app/vmselect/promql: properly return durations smaller than one second from duration_over_time() function

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1780
This commit is contained in:
Aliaksandr Valialkin 2021-11-09 11:41:42 +02:00
parent 57aaf914ac
commit 31486f2244
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 24 additions and 4 deletions

View File

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

View File

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