Skip to content

Commit

Permalink
app/vmselect/promql: adjust integrate() calculations to be more sim…
Browse files Browse the repository at this point in the history
…ilar to calculations from InfluxDB

Updates #701
  • Loading branch information
valyala committed Sep 8, 2020
1 parent c0343a6 commit 8e85b56
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/vmselect/promql/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion app/vmselect/promql/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions app/vmselect/promql/rollup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 8e85b56

Please sign in to comment.