Skip to content

Commit 01cbe3d

Browse files
committed
some more fixes
Signed-off-by: amanycodes <amanycodes@gmail.com>
1 parent 6b5f967 commit 01cbe3d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

promql/functions.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,11 +1351,12 @@ func histogramVariance(vals []parser.Value, enh *EvalNodeHelper, varianceToResul
13511351
}
13521352
var val float64
13531353
switch {
1354-
case bucket.Lower <= 0 && bucket.Upper >= 0:
1355-
val = 0
13561354
case sample.H.UsesCustomBuckets():
13571355
// Use arithmetic mean in case of custom buckets.
1358-
val = (bucket.Upper * bucket.Lower) / 2.0
1356+
val = (bucket.Upper + bucket.Lower) / 2.0
1357+
case bucket.Lower <= 0 && bucket.Upper >= 0:
1358+
// Use zero (effectively the arithmetic mean) in the zero bucket of a standard exponential histogram.
1359+
val = 0
13591360
default:
13601361
// Use geometric mean in case of standard exponential buckets.
13611362
val = math.Sqrt(bucket.Upper * bucket.Lower)

promql/promqltest/testdata/histograms.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ eval instant at 50m histogram_avg(testhistogram3)
9595

9696
# Test histogram_stddev. This has no classic equivalent.
9797
eval instant at 50m histogram_stddev(testhistogram3)
98-
{start="positive"} 2.962188994031886
99-
{start="negative"} 3.9825070621406313
98+
{start="positive"} 2.7435461458749795
99+
{start="negative"} 4.187667907081458
100100

101101
# Test histogram_stdvar. This has no classic equivalent.
102102
eval instant at 50m histogram_stdvar(testhistogram3)
103-
{start="positive"} 8.774563636363636
104-
{start="negative"} 15.860362500000003
103+
{start="positive"} 7.527045454545455
104+
{start="negative"} 17.5365625
105105

106106
# Test histogram_fraction.
107107
#

0 commit comments

Comments
 (0)