mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 00:23:18 +00:00
use kahan for avg_over_time
Signed-off-by: darshanime <deathbullet@gmail.com>
This commit is contained in:
parent
0a9deb9597
commit
a905354da3
@ -367,7 +367,7 @@ func aggrOverTime(vals []parser.Value, enh *EvalNodeHelper, aggrFn func([]Point)
|
|||||||
// === avg_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
// === avg_over_time(Matrix parser.ValueTypeMatrix) Vector ===
|
||||||
func funcAvgOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
func funcAvgOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) Vector {
|
||||||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||||
var mean, count float64
|
var mean, count, c float64
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
count++
|
count++
|
||||||
if math.IsInf(mean, 0) {
|
if math.IsInf(mean, 0) {
|
||||||
@ -387,9 +387,13 @@ func funcAvgOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNode
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mean += v.V/count - mean/count
|
mean, c = kahanSummationIter(v.V/count-mean/count, mean, c)
|
||||||
}
|
}
|
||||||
return mean
|
|
||||||
|
if math.IsInf(mean, 0) {
|
||||||
|
return mean
|
||||||
|
}
|
||||||
|
return mean + c
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user