Handle zero_bucket_only case (plus more tests)

Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
This commit is contained in:
Linas Medziunas
2026-02-10 16:02:01 +02:00
parent 5c49187719
commit 0615b6af4f
2 changed files with 37 additions and 2 deletions

View File

@@ -3233,10 +3233,10 @@ func computeZeroBucketTrim(zeroBucket histogram.Bucket[float64], rhs float64, ha
lower = zeroBucket.Lower
upper = zeroBucket.Upper
)
if !hasPositive {
if hasNegative && !hasPositive {
upper = 0
}
if !hasNegative {
if hasPositive && !hasNegative {
lower = 0
}

View File

@@ -1980,6 +1980,41 @@ eval instant at 1m h_negative_buckets >/ 0
h_negative_buckets {{schema:0 z_bucket_w:0.5}}
# Exponential buckets: trim zero bucket when there are no other buckets.
load 1m
zero_bucket_only {{schema:0 count:5 sum:0 z_bucket:5 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only >/ 0.1
zero_bucket_only {{schema:0 count:0 sum:0 z_bucket:0 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only </ 0.1
zero_bucket_only {{schema:0 count:5 sum:0 z_bucket:5 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only >/ 0.05
zero_bucket_only {{schema:0 count:1.25 sum:0.09375000000000001 z_bucket:1.25 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only </ 0.05
zero_bucket_only {{schema:0 count:3.75 sum:-0.09375000000000001 z_bucket:3.75 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only >/ 0
zero_bucket_only {{schema:0 count:2.5 sum:0.125 z_bucket:2.5 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only </ 0
zero_bucket_only {{schema:0 count:2.5 sum:-0.125 z_bucket:2.5 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only >/ -0.05
zero_bucket_only {{schema:0 count:3.75 sum:0.09375000000000001 z_bucket:3.75 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only </ -0.05
zero_bucket_only {{schema:0 count:1.25 sum:-0.09375000000000001 z_bucket:1.25 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only </ -0.1
zero_bucket_only {{schema:0 count:0 sum:0 z_bucket:0 z_bucket_w:0.1 }}
eval instant at 1m zero_bucket_only >/ -0.1
zero_bucket_only {{schema:0 count:5 sum:0 z_bucket:5 z_bucket_w:0.1 }}
load 1m
cbh {{schema:-53 sum:172.5 count:15 custom_values:[5 10 15 20] buckets:[1 6 4 3 1]}}