model/histogram: Fix checkHistogramCustomBounds to accept -Inf

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7
2025-10-10 23:10:32 +02:00
parent 1c58399160
commit 6a8cacdf6f
2 changed files with 8 additions and 2 deletions

View File

@@ -468,11 +468,11 @@ func checkHistogramBuckets[BC BucketCount, IBC InternalBucketCount](buckets []IB
func checkHistogramCustomBounds(bounds []float64, spans []Span, numBuckets int) error {
prev := math.Inf(-1)
for _, curr := range bounds {
for i, curr := range bounds {
if math.IsNaN(curr) {
return ErrHistogramCustomBucketsNaN
}
if curr <= prev {
if i > 0 && curr <= prev {
return fmt.Errorf("previous bound is %f and current is %f: %w", prev, curr, ErrHistogramCustomBucketsInvalid)
}
prev = curr

View File

@@ -1579,6 +1579,12 @@ func TestHistogramValidation(t *testing.T) {
},
errMsg: "custom buckets: last +Inf bound must not be explicitly defined: histogram custom bounds must be finite",
},
"valid custom buckets histogram with explicit -Inf bound": {
h: &Histogram{
Schema: CustomBucketsSchema,
CustomValues: []float64{math.Inf(-1), 1},
},
},
"reject custom buckets histogram with NaN bound": {
h: &Histogram{
Schema: CustomBucketsSchema,