mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/promql: prevent from incorrect calculations for deriv()
over multiple samples with identical timestamps
This commit is contained in:
parent
82917398b9
commit
82cf9f26db
1 changed files with 6 additions and 1 deletions
|
@ -875,7 +875,12 @@ func linearRegression(rfa *rollupFuncArg) (float64, float64) {
|
|||
tvSum += dt * v
|
||||
ttSum += dt * dt
|
||||
}
|
||||
k := (tvSum - tSum*vSum/n) / (ttSum - tSum*tSum/n)
|
||||
k := float64(0)
|
||||
tDiff := ttSum - tSum*tSum/n
|
||||
if math.Abs(tDiff) >= 1e-6 {
|
||||
// Prevent from incorrect division for too small tDiff values.
|
||||
k = (tvSum - tSum*vSum/n) / tDiff
|
||||
}
|
||||
v := vSum/n - k*tSum/n
|
||||
return v, k
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue