promql: Fix avg_over_time for single histogram

avg_over_time would produce +Inf count/sum and NaN zero bucket when
averaging a single histogram, because the count variable was initialized
to 0 instead of 1. This caused a division by zero at the end of the
function.

The float version of avg_over_time already correctly initializes count
to 1, this change makes the histogram version consistent with that.

Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
This commit is contained in:
Jeanette Tan 2026-02-11 05:06:53 +08:00
parent 9fddb70b8c
commit d2bb5605dc

View file

@ -848,7 +848,7 @@ func funcAvgOverTime(_ []Vector, matrixVal Matrix, args parser.Expressions, enh
var (
sum = s.Histograms[0].H.Copy()
mean, kahanC *histogram.FloatHistogram
count float64
count = 1.
incrementalMean bool
nhcbBoundsReconciled bool
err error