app/vmselect/promql: prevent from incorrect calculations for deriv() over multiple samples with identical timestamps

This commit is contained in:
Aliaksandr Valialkin 2021-11-12 13:50:43 +02:00
parent 82917398b9
commit 82cf9f26db
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -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
}