diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index 0ae73cb350..d04b3d9674 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -891,11 +891,10 @@ func newRollupDurationOverTime(args []interface{}) (rollupFunc, error) { rf := func(rfa *rollupFuncArg) float64 { // There is no need in handling NaNs here, since they must be cleaned up // before calling rollup funcs. - values := rfa.values - if len(values) == 0 { + timestamps := rfa.timestamps + if len(timestamps) == 0 { return nan } - timestamps := rfa.timestamps tPrev := timestamps[0] dSum := int64(0) dMax := int64(dMaxs[rfa.idx] * 1000) @@ -906,7 +905,7 @@ func newRollupDurationOverTime(args []interface{}) (rollupFunc, error) { } tPrev = t } - return float64(dSum / 1000) + return float64(dSum) / 1000 } return rf, nil } diff --git a/app/vmselect/promql/rollup_test.go b/app/vmselect/promql/rollup_test.go index 0b025fd04e..e90ebd0eb8 100644 --- a/app/vmselect/promql/rollup_test.go +++ b/app/vmselect/promql/rollup_test.go @@ -193,6 +193,27 @@ func testRollupFunc(t *testing.T, funcName string, args []interface{}, meExpecte } } +func TestRollupDurationOverTime(t *testing.T) { + f := func(maxInterval, dExpected float64) { + t.Helper() + maxIntervals := []*timeseries{{ + Values: []float64{maxInterval}, + Timestamps: []int64{123}, + }} + var me metricsql.MetricExpr + args := []interface{}{&metricsql.RollupExpr{Expr: &me}, maxIntervals} + testRollupFunc(t, "duration_over_time", args, &me, dExpected) + } + f(-123, 0) + f(0, 0) + f(0.001, 0) + f(0.005, 0.007) + f(0.01, 0.036) + f(0.02, 0.125) + f(1, 0.125) + f(100, 0.125) +} + func TestRollupShareLEOverTime(t *testing.T) { f := func(le, vExpected float64) { t.Helper()