Fix midpoint of NHCB 1st bucket

Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
This commit is contained in:
Linas Medziunas 2026-02-13 15:39:42 +02:00
parent 538ad96136
commit 9a6c170d15
2 changed files with 16 additions and 13 deletions

View File

@ -3444,21 +3444,24 @@ func trimHistogram(trimmedHist *histogram.FloatHistogram, rhs float64, isUpperTr
}
}
func computeMidpoint(survivingIntervalBoundA, survivingIntervalBoundB float64, isPositive, isLinear bool) float64 {
if math.IsInf(survivingIntervalBoundA, 0) {
if math.IsInf(survivingIntervalBoundB, 0) {
func computeMidpoint(survivingIntervalLowerBound, survivingIntervalUpperBound float64, isPositive, isLinear bool) float64 {
if math.IsInf(survivingIntervalLowerBound, 0) {
if math.IsInf(survivingIntervalUpperBound, 0) {
return 0
}
return survivingIntervalBoundB
} else if math.IsInf(survivingIntervalBoundB, 0) {
return survivingIntervalBoundA
if survivingIntervalUpperBound > 0 {
return survivingIntervalUpperBound / 2
}
return survivingIntervalUpperBound
} else if math.IsInf(survivingIntervalUpperBound, 0) {
return survivingIntervalLowerBound
}
if isLinear {
return (survivingIntervalBoundA + survivingIntervalBoundB) / 2
return (survivingIntervalLowerBound + survivingIntervalUpperBound) / 2
}
geoMean := math.Sqrt(math.Abs(survivingIntervalBoundA * survivingIntervalBoundB))
geoMean := math.Sqrt(math.Abs(survivingIntervalLowerBound * survivingIntervalUpperBound))
if isPositive {
return geoMean

View File

@ -2020,24 +2020,24 @@ load 1m
# Custom buckets: trim on bucket boundary without interpolation
eval instant at 1m cbh </ 15
cbh{} {{schema:-53 count:11 sum:100 custom_values:[5 10 15 20] buckets:[1 6 4]}}
cbh{} {{schema:-53 count:11 sum:97.5 custom_values:[5 10 15 20] buckets:[1 6 4]}}
eval instant at 1m cbh >/ 15
cbh{} {{schema:-53 count:4 sum:72.5 custom_values:[5 10 15 20] offset:3 buckets:[3 1]}}
# Custom buckets: trim uses linear interpolation if cutoff is inside a bucket
eval instant at 1m cbh </ 13
cbh{} {{schema:-53 count:9.4 sum:77.6 custom_values:[5 10 15 20] buckets:[1 6 2.4]}}
cbh{} {{schema:-53 count:9.4 sum:75.1 custom_values:[5 10 15 20] buckets:[1 6 2.4]}}
eval instant at 1m cbh >/ 13
cbh{} {{schema:-53 count:5.6 sum:94.9 custom_values:[5 10 15 20] offset:2 buckets:[1.6 3 1]}}
eval instant at 1m cbh </ 7.5
cbh{} {{schema:-53 count:4 sum:23.75 custom_values:[5 10 15 20] buckets:[1 3]}}
cbh{} {{schema:-53 count:4 sum:21.25 custom_values:[5 10 15 20] buckets:[1 3]}}
# Custom buckets: trim drops +Inf bucket entirely even if cutoff is above its lower bound
eval instant at 1m cbh </ 50
cbh{} {{schema:-53 count:14 sum:152.5 custom_values:[5 10 15 20] buckets:[1 6 4 3]}}
cbh{} {{schema:-53 count:14 sum:150.0 custom_values:[5 10 15 20] buckets:[1 6 4 3]}}
eval instant at 1m cbh </ -Inf
cbh{} {{schema:-53 custom_values:[5 10 15 20]}}
@ -2145,7 +2145,7 @@ load 1m
# Skip (5; +Inf] bucket (100).
eval instant at 1m cbh_two_buckets_split_at_positive </ 10.0
cbh_two_buckets_split_at_positive {{schema:-53 sum:5.0 count:1 custom_values:[5] buckets:[1 0]}}
cbh_two_buckets_split_at_positive {{schema:-53 sum:2.5 count:1 custom_values:[5] buckets:[1 0]}}
# Skip (5; +Inf] bucket (100) and 3/5 of [-Inf, 5] bucket (0.6 * 3.5).
eval instant at 1m cbh_two_buckets_split_at_positive </ 2.0