PromQL: Speed up parsing of variadic functions (#17316)

* PromQL: Add benchmark case with variadic function

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* PromQL: Speed up parsing of variadic functions

Defer formatting of an error message until we hit an error.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

---------

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2025-10-10 09:16:33 +01:00 committed by GitHub
parent 8558b722f2
commit 1c58399160
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -664,6 +664,7 @@ func BenchmarkParser(b *testing.B) {
`foo{a="b", foo!="bar", test=~"test", bar!~"baz"}`,
`min_over_time(rate(foo{bar="baz"}[2s])[5m:])[4m:3s]`,
"sum without(and, by, avg, count, alert, annotations)(some_metric) [30m:10s]",
`sort_by_label(metric, "foo", "bar")`,
}
errCases := []string{
"(",

View File

@ -819,7 +819,9 @@ func (p *parser) checkAST(node Node) (typ ValueType) {
}
i = len(n.Func.ArgTypes) - 1
}
p.expectType(arg, n.Func.ArgTypes[i], fmt.Sprintf("call to function %q", n.Func.Name))
if t := p.checkAST(arg); t != n.Func.ArgTypes[i] {
p.addParseErrf(arg.PositionRange(), "expected type %s in call to function %q, got %s", DocumentedType(n.Func.ArgTypes[i]), n.Func.Name, DocumentedType(t))
}
}
case *ParenExpr: