mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 16:30:55 +01:00
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:
parent
57aaf914ac
commit
31486f2244
@ -891,11 +891,10 @@ func newRollupDurationOverTime(args []interface{}) (rollupFunc, error) {
|
|||||||
rf := func(rfa *rollupFuncArg) float64 {
|
rf := func(rfa *rollupFuncArg) float64 {
|
||||||
// There is no need in handling NaNs here, since they must be cleaned up
|
// There is no need in handling NaNs here, since they must be cleaned up
|
||||||
// before calling rollup funcs.
|
// before calling rollup funcs.
|
||||||
values := rfa.values
|
timestamps := rfa.timestamps
|
||||||
if len(values) == 0 {
|
if len(timestamps) == 0 {
|
||||||
return nan
|
return nan
|
||||||
}
|
}
|
||||||
timestamps := rfa.timestamps
|
|
||||||
tPrev := timestamps[0]
|
tPrev := timestamps[0]
|
||||||
dSum := int64(0)
|
dSum := int64(0)
|
||||||
dMax := int64(dMaxs[rfa.idx] * 1000)
|
dMax := int64(dMaxs[rfa.idx] * 1000)
|
||||||
@ -906,7 +905,7 @@ func newRollupDurationOverTime(args []interface{}) (rollupFunc, error) {
|
|||||||
}
|
}
|
||||||
tPrev = t
|
tPrev = t
|
||||||
}
|
}
|
||||||
return float64(dSum / 1000)
|
return float64(dSum) / 1000
|
||||||
}
|
}
|
||||||
return rf, nil
|
return rf, nil
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
func TestRollupShareLEOverTime(t *testing.T) {
|
||||||
f := func(le, vExpected float64) {
|
f := func(le, vExpected float64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
Loading…
Reference in New Issue
Block a user