From d2bb5605dc2d9c67b8ee8efec20f2f193a26db87 Mon Sep 17 00:00:00 2001 From: Jeanette Tan Date: Wed, 11 Feb 2026 05:06:53 +0800 Subject: [PATCH] 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 --- promql/functions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/promql/functions.go b/promql/functions.go index f02262ac40..2cb90a9b6c 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -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