mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01:00
app/vmselect/promql: fix panic on sum(aggr_over_time(...))
with incorrect number of args
This commit is contained in:
parent
7d429e2806
commit
ce0b602405
@ -329,6 +329,10 @@ func tryGetArgRollupFuncWithMetricExpr(ae *metricsql.AggrFuncExpr) (*metricsql.F
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
rollupArgIdx := getRollupArgIdx(fe.Name)
|
rollupArgIdx := getRollupArgIdx(fe.Name)
|
||||||
|
if rollupArgIdx >= len(fe.Args) {
|
||||||
|
// Incorrect number of args for rollup func.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
arg := fe.Args[rollupArgIdx]
|
arg := fe.Args[rollupArgIdx]
|
||||||
if me, ok := arg.(*metricsql.MetricExpr); ok {
|
if me, ok := arg.(*metricsql.MetricExpr); ok {
|
||||||
if me.IsEmpty() {
|
if me.IsEmpty() {
|
||||||
@ -366,7 +370,7 @@ func evalRollupFuncArgs(ec *EvalConfig, fe *metricsql.FuncExpr) ([]interface{},
|
|||||||
var re *metricsql.RollupExpr
|
var re *metricsql.RollupExpr
|
||||||
rollupArgIdx := getRollupArgIdx(fe.Name)
|
rollupArgIdx := getRollupArgIdx(fe.Name)
|
||||||
if len(fe.Args) <= rollupArgIdx {
|
if len(fe.Args) <= rollupArgIdx {
|
||||||
return nil, nil, fmt.Errorf("expecting at least %d args to %q; got %d args; expr: %q", rollupArgIdx, fe.Name, len(fe.Args), fe.AppendString(nil))
|
return nil, nil, fmt.Errorf("expecting at least %d args to %q; got %d args; expr: %q", rollupArgIdx+1, fe.Name, len(fe.Args), fe.AppendString(nil))
|
||||||
}
|
}
|
||||||
args := make([]interface{}, len(fe.Args))
|
args := make([]interface{}, len(fe.Args))
|
||||||
for i, arg := range fe.Args {
|
for i, arg := range fe.Args {
|
||||||
|
@ -5304,6 +5304,9 @@ func TestExecError(t *testing.T) {
|
|||||||
f(`aggr_over_time()`)
|
f(`aggr_over_time()`)
|
||||||
f(`aggr_over_time(foo)`)
|
f(`aggr_over_time(foo)`)
|
||||||
f(`aggr_over_time("foo", bar, 1)`)
|
f(`aggr_over_time("foo", bar, 1)`)
|
||||||
|
f(`sum(aggr_over_time())`)
|
||||||
|
f(`sum(aggr_over_time(foo))`)
|
||||||
|
f(`count(aggr_over_time("foo", bar, 1))`)
|
||||||
f(`hoeffding_bound_lower()`)
|
f(`hoeffding_bound_lower()`)
|
||||||
f(`hoeffding_bound_lower(1)`)
|
f(`hoeffding_bound_lower(1)`)
|
||||||
f(`hoeffding_bound_lower(0.99, foo, 1)`)
|
f(`hoeffding_bound_lower(0.99, foo, 1)`)
|
||||||
|
Loading…
Reference in New Issue
Block a user