app/vmselect/promql: adjust integrate() calculations to be more similar to calculations from InfluxDB

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/701
This commit is contained in:
Aliaksandr Valialkin 2020-09-08 14:23:36 +03:00
parent db91045348
commit 0d0b606455
3 changed files with 4 additions and 4 deletions

View File

@ -4836,7 +4836,7 @@ func TestExecSuccess(t *testing.T) {
q := `integrate(time()/1e3)` q := `integrate(time()/1e3)`
r := netstorage.Result{ r := netstorage.Result{
MetricName: metricNameExpected, MetricName: metricNameExpected,
Values: []float64{180, 220.00000000000003, 259.99999999999994, 300, 340.00000000000006, 380}, Values: []float64{160, 200, 240, 280, 320, 360},
Timestamps: timestampsExpected, Timestamps: timestampsExpected,
} }
resultExpected := []netstorage.Result{r} resultExpected := []netstorage.Result{r}

View File

@ -1710,7 +1710,7 @@ func rollupIntegrate(rfa *rollupFuncArg) float64 {
for i, v := range values { for i, v := range values {
timestamp := timestamps[i] timestamp := timestamps[i]
dt := float64(timestamp-prevTimestamp) / 1e3 dt := float64(timestamp-prevTimestamp) / 1e3
sum += 0.5 * (v + prevValue) * dt sum += prevValue * dt
prevTimestamp = timestamp prevTimestamp = timestamp
prevValue = v prevValue = v
} }

View File

@ -431,7 +431,7 @@ func TestRollupNewRollupFuncSuccess(t *testing.T) {
f("stdvar_over_time", 945.7430555555555) f("stdvar_over_time", 945.7430555555555)
f("first_over_time", 123) f("first_over_time", 123)
f("last_over_time", 34) f("last_over_time", 34)
f("integrate", 5.4705) f("integrate", 5.237)
f("distinct_over_time", 8) f("distinct_over_time", 8)
f("ideriv", 0) f("ideriv", 0)
f("decreases_over_time", 5) f("decreases_over_time", 5)
@ -970,7 +970,7 @@ func TestRollupFuncsNoWindow(t *testing.T) {
} }
rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step) rc.Timestamps = getTimestamps(rc.Start, rc.End, rc.Step)
values := rc.Do(nil, testValues, testTimestamps) 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} timestampsExpected := []int64{0, 40, 80, 120, 160}
testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected) testRowsEqual(t, values, rc.Timestamps, valuesExpected, timestampsExpected)
}) })