mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01: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
@ -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 New Issue
Block a user