diff --git a/promql/engine.go b/promql/engine.go index bb1536829e..c464d9baf0 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -3156,11 +3156,14 @@ func handleInfinityBuckets(isUpperTrim bool, b histogram.Bucket[float64], rhs fl // As the rhs is greater than the upper bound, we keep the entire current bucket. return b.Count, 0 } - if rhs >= 0 && b.Upper > rhs && !math.IsInf(b.Upper, 1) { + if rhs > 0 && b.Upper > 0 && !math.IsInf(b.Upper, 1) { // If upper is finite and positive, we treat lower as 0 (despite it de facto being -Inf). // This is only possible with NHCB, so we can always use linear interpolation. return b.Count * rhs / b.Upper, rhs / 2 } + if b.Upper <= 0 { + return b.Count, rhs + } // Otherwise, we are targeting a valid trim, but as we don't know the exact distribution of values that belongs to an infinite bucket, we need to remove the entire bucket. return 0, zeroIfInf(b.Upper) } diff --git a/promql/promqltest/testdata/native_histograms.test b/promql/promqltest/testdata/native_histograms.test index 614521b3af..07aabcfa94 100644 --- a/promql/promqltest/testdata/native_histograms.test +++ b/promql/promqltest/testdata/native_histograms.test @@ -2070,7 +2070,7 @@ eval instant at 1m cbh_has_neg / -10.0 @@ -2193,7 +2193,7 @@ eval instant at 1m cbh_two_buckets_split_at_negative / -10.0