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 c0343a661b
commit 8e85b56737
3 changed files with 4 additions and 4 deletions

View file

@ -4826,7 +4826,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}

View file

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

View file

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