From 0cb66a8f9505f11858f90da5a0dda3aabc552d6a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 16 Aug 2019 11:55:10 +0300 Subject: [PATCH] app/vmselect/promql: fix corner-case calculation for `ideriv` --- app/vmselect/promql/rollup.go | 4 ++-- app/vmselect/promql/rollup_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 16df4755c5..f2272097f6 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -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 { diff --git a/app/vmselect/promql/rollup_test.go b/app/vmselect/promql/rollup_test.go index 337d634587..00fbbff374 100644 --- a/app/vmselect/promql/rollup_test.go +++ b/app/vmselect/promql/rollup_test.go @@ -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) }