app/vmselect/promql: fix corner-case calculation for ideriv

This commit is contained in:
Aliaksandr Valialkin 2019-08-16 11:55:10 +03:00
parent 1b5b9ced27
commit 0cb66a8f95
2 changed files with 3 additions and 3 deletions

View file

@ -698,7 +698,7 @@ func rollupIderiv(rfa *rollupFuncArg) float64 {
// It is impossible to calculate derivative on 0 or 1 values.
return nan
}
return (values[0] - rfa.prevValue) / float64(timestamps[0]-rfa.prevTimestamp)
return (values[0] - rfa.prevValue) / (float64(timestamps[0]-rfa.prevTimestamp) * 1e-3)
}
vEnd := values[len(values)-1]
tEnd := timestamps[len(timestamps)-1]
@ -722,7 +722,7 @@ func rollupIderiv(rfa *rollupFuncArg) float64 {
}
dv := vEnd - vStart
dt := tEnd - tStart
return dv / (float64(dt) / 1000)
return dv / (float64(dt) * 1e-3)
}
func rollupChanges(rfa *rollupFuncArg) float64 {

View file

@ -56,7 +56,7 @@ func TestRollupIderivDuplicateTimestamps(t *testing.T) {
timestamps: []int64{100},
}
n = rollupIderiv(rfa)
if n != 0.5 {
if n != 500 {
t.Fatalf("unexpected value; got %v; want %v", n, 0.5)
}