Merge pull request #17320 from prometheus/beorn7/histogram3
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run

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 {
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,