mirror of
https://github.com/prometheus/prometheus
synced 2026-04-20 22:41:05 +08:00
convertnhcb: reject NaN bucket boundary in SetBucketCount (#18383)
Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
var (
|
||||
errNegativeBucketCount = errors.New("bucket count must be non-negative")
|
||||
errNaNBucket = errors.New("bucket boundary must not be NaN")
|
||||
errNegativeCount = errors.New("count must be non-negative")
|
||||
errCountMismatch = errors.New("count mismatch")
|
||||
errCountNotCumulative = errors.New("count is not cumulative")
|
||||
@@ -71,6 +72,10 @@ func (h *TempHistogram) SetBucketCount(boundary, count float64) error {
|
||||
if h.err != nil {
|
||||
return h.err
|
||||
}
|
||||
if math.IsNaN(boundary) {
|
||||
h.err = errNaNBucket
|
||||
return h.err
|
||||
}
|
||||
if count < 0 {
|
||||
h.err = fmt.Errorf("%w: le=%g, count=%g", errNegativeBucketCount, boundary, count)
|
||||
return h.err
|
||||
|
||||
@@ -147,6 +147,19 @@ func TestNHCBConvert(t *testing.T) {
|
||||
},
|
||||
expectedErr: errNegativeCount,
|
||||
},
|
||||
"NaN bucket upper bound": {
|
||||
setup: func() *TempHistogram {
|
||||
h := NewTempHistogram()
|
||||
// Add a real bucket first so that the NaN call reaches the
|
||||
// default branch of the switch in SetBucketCount; without an
|
||||
// existing bucket, len(h.buckets)==0 and the NaN is silently
|
||||
// appended without triggering the panic.
|
||||
h.SetBucketCount(1.0, 5)
|
||||
h.SetBucketCount(math.NaN(), 10)
|
||||
return &h
|
||||
},
|
||||
expectedErr: errNaNBucket,
|
||||
},
|
||||
"mixed order": {
|
||||
setup: func() *TempHistogram {
|
||||
h := NewTempHistogram()
|
||||
|
||||
Reference in New Issue
Block a user