MCPcopy
hub / github.com/grafana/tempo / addIncrementMean

Method addIncrementMean

pkg/traceql/engine_metrics_average.go:246–255  ·  view source on GitHub ↗

It increments the mean based on a new value

(interval int, inc float64)

Source from the content-addressed store, hash-verified

244
245// It increments the mean based on a new value
246func (k *averageSeries) addIncrementMean(interval int, inc float64) {
247 currentMean := k.values[interval]
248 if math.IsNaN(currentMean.mean) && !math.IsNaN(inc) {
249 k.values[interval] = averageValue{mean: inc, weight: 1}
250 return
251 }
252 currentMean.weight++
253 currentMean.add(inc/currentMean.weight - currentMean.mean/currentMean.weight)
254 k.values[interval] = currentMean
255}
256
257// It calculates the incremental weighted mean using kahan-neumaier summation and a delta approach.
258// By adding incremental values we prevent overflow

Callers 1

ObserveMethod · 0.80

Calls 1

addMethod · 0.45

Tested by

no test coverage detected