Fix for nhcb [-Inf; -x) bucket

Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
This commit is contained in:
Linas Medziunas 2026-02-13 16:21:12 +02:00
parent 9a6c170d15
commit c657e859e3
2 changed files with 7 additions and 4 deletions

View File

@ -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)
}

View File

@ -2070,7 +2070,7 @@ eval instant at 1m cbh_has_neg </ -4
cbh_has_neg{} {{schema:-53 count:2.4 sum:-22.8 custom_values:[-10 5 10 15 20] buckets:[2 0.4]}}
eval instant at 1m cbh_has_neg </ -15
cbh_has_neg{} {{schema:-53 custom_values:[-10 5 10 15 20]}}
cbh_has_neg{} {{schema:-53 count:2 sum:-30 custom_values:[-10 5 10 15 20] buckets:[2]}}
load 1m
@ -2125,7 +2125,7 @@ eval instant at 1m cbh_two_buckets_split_at_zero </ 0.0
# Skip both buckets (1, 100).
eval instant at 1m cbh_two_buckets_split_at_zero </ -10.0
cbh_two_buckets_split_at_zero {{schema:-53 sum:0.0 count:0 custom_values:[0] buckets:[0 0]}}
cbh_two_buckets_split_at_zero {{schema:-53 sum:-10.0 count:1 custom_values:[0] buckets:[1 0]}}
# Skip [-Inf, 0] bucket (1).
eval instant at 1m cbh_two_buckets_split_at_zero >/ -10.0
@ -2193,7 +2193,7 @@ eval instant at 1m cbh_two_buckets_split_at_negative </ -2.0
# Skip both buckets (1 and 100).
eval instant at 1m cbh_two_buckets_split_at_negative </ -10.0
cbh_two_buckets_split_at_negative {{schema:-53 sum:0.0 count:0 custom_values:[-5] buckets:[0 0]}}
cbh_two_buckets_split_at_negative {{schema:-53 sum:-10.0 count:1 custom_values:[-5] buckets:[1 0]}}
# Skip [-Inf, -5] bucket (1).
eval instant at 1m cbh_two_buckets_split_at_negative >/ -10.0