From 6a8cacdf6f0488a3dafd916a2a562595128845c5 Mon Sep 17 00:00:00 2001 From: beorn7 Date: Fri, 10 Oct 2025 23:10:32 +0200 Subject: [PATCH] model/histogram: Fix checkHistogramCustomBounds to accept -Inf Signed-off-by: beorn7 --- model/histogram/generic.go | 4 ++-- model/histogram/histogram_test.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/model/histogram/generic.go b/model/histogram/generic.go index f95d3b464e..386eb21815 100644 --- a/model/histogram/generic.go +++ b/model/histogram/generic.go @@ -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 diff --git a/model/histogram/histogram_test.go b/model/histogram/histogram_test.go index 9b93b3581c..2000bf7659 100644 --- a/model/histogram/histogram_test.go +++ b/model/histogram/histogram_test.go @@ -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,