From 0d0b6064559630ec2a9a2ad4104381e5d8dfd904 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 8 Sep 2020 14:23:36 +0300 Subject: [PATCH] app/vmselect/promql: adjust `integrate()` calculations to be more similar to calculations from InfluxDB Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/701 --- app/vmselect/promql/exec_test.go | 2 +- app/vmselect/promql/rollup.go | 2 +- app/vmselect/promql/rollup_test.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index f05b043ac..af5d976d8 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -4836,7 +4836,7 @@ func TestExecSuccess(t *testing.T) { q := `integrate(time()/1e3)` r := netstorage.Result{ MetricName: metricNameExpected, - Values: []float64{180, 220.00000000000003, 259.99999999999994, 300, 340.00000000000006, 380}, + Values: []float64{160, 200, 240, 280, 320, 360}, Timestamps: timestampsExpected, } resultExpected := []netstorage.Result{r} diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index a271757b1..16087c052 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -1710,7 +1710,7 @@ func rollupIntegrate(rfa *rollupFuncArg) float64 { for i, v := range values { timestamp := timestamps[i] dt := float64(timestamp-prevTimestamp) / 1e3 - sum += 0.5 * (v + prevValue) * dt + sum += prevValue * dt prevTimestamp = timestamp prevValue = v } diff --git a/app/vmselect/promql/rollup_test.go b/app/vmselect/promql/rollup_test.go index d8080685a..aef7c335f 100644 --- a/app/vmselect/promql/rollup_test.go +++ b/app/vmselect/promql/rollup_test.go @@ -431,7 +431,7 @@ func TestRollupNewRollupFuncSuccess(t *testing.T) { f("stdvar_over_time", 945.7430555555555) f("first_over_time", 123) f("last_over_time", 34) - f("integrate", 5.4705) + f("integrate", 5.237) f("distinct_over_time", 8) f("ideriv", 0) f("decreases_over_time", 5) @@ -970,7 +970,7 @@ func TestRollupFuncsNoWindow(t *testing.T) { } rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step) values := rc.Do(nil, testValues, testTimestamps) - valuesExpected := []float64{nan, 1.526, 2.2795, 1.325, 0.34} + valuesExpected := []float64{nan, 2.064, 1.677, 1.156, 0.34} timestampsExpected := []int64{0, 40, 80, 120, 160} testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) })