promql: Improve Kahan usage in avg_over_time

The calculation of the mean value in avg_over_time is performed in an
incremental fashion. This introduces additional numerical errors that
even Kahan summation cannot compensate, but at least we can use the
Kahan-corrected mean value when we use the intermediate mean value in
the calculation.

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2024-07-04 18:36:32 +02:00
parent c46074f4dd
commit 3a908d8e08

View file

@ -593,7 +593,8 @@ func funcAvgOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNode
continue
}
}
mean, c = kahanSumInc(f.F/count-mean/count, mean, c)
correctedMean := mean + c
mean, c = kahanSumInc(f.F/count-correctedMean/count, mean, c)
}
if math.IsInf(mean, 0) {