Merge pull request #17320 from prometheus/beorn7/histogram3

model/histogram: Fix checkHistogramCustomBounds to accept -Inf
This commit is contained in:
Björn Rabenstein 2025-10-12 16:10:17 +02:00 committed by GitHub
commit 2c2a4314b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 { func checkHistogramCustomBounds(bounds []float64, spans []Span, numBuckets int) error {
prev := math.Inf(-1) prev := math.Inf(-1)
for _, curr := range bounds { for i, curr := range bounds {
if math.IsNaN(curr) { if math.IsNaN(curr) {
return ErrHistogramCustomBucketsNaN 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) return fmt.Errorf("previous bound is %f and current is %f: %w", prev, curr, ErrHistogramCustomBucketsInvalid)
} }
prev = curr 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", 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": { "reject custom buckets histogram with NaN bound": {
h: &Histogram{ h: &Histogram{
Schema: CustomBucketsSchema, Schema: CustomBucketsSchema,