mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-06 10:01:02 +01:00
[BUGFIX] PromQL: avoid panic parsing malformed info call (#17379)
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
This commit is contained in:
parent
3d2d847e77
commit
b2e7938e25
@ -803,11 +803,14 @@ func (p *parser) checkAST(node Node) (typ ValueType) {
|
||||
p.addParseErrf(node.PositionRange(), "expected type %s in %s, got %s", DocumentedType(ValueTypeVector), fmt.Sprintf("call to function %q", n.Func.Name), DocumentedType(n.Args[1].Type()))
|
||||
}
|
||||
// Check the vector selector in the input doesn't contain a metric name
|
||||
if n.Args[1].(*VectorSelector).Name != "" {
|
||||
if vs, ok := n.Args[1].(*VectorSelector); ok && vs.Name != "" {
|
||||
p.addParseErrf(n.Args[1].PositionRange(), "expected label selectors only, got vector selector instead")
|
||||
} else if ok {
|
||||
// Set Vector Selector flag to bypass empty matcher check
|
||||
vs.BypassEmptyMatcherCheck = true
|
||||
} else {
|
||||
p.addParseErrf(n.Args[1].PositionRange(), "expected label selectors only")
|
||||
}
|
||||
// Set Vector Selector flag to bypass empty matcher check
|
||||
n.Args[1].(*VectorSelector).BypassEmptyMatcherCheck = true
|
||||
}
|
||||
|
||||
for i, arg := range n.Args {
|
||||
|
||||
@ -4375,6 +4375,17 @@ var testExpr = []struct {
|
||||
PosRange: posrange.PositionRange{Start: 0, End: 73},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `info(http_request_counter_total{namespace="zzz"}, {foo="bar"} == 1)`,
|
||||
fail: true,
|
||||
errors: ParseErrors{
|
||||
ParseErr{
|
||||
PositionRange: posrange.PositionRange{Start: 50, End: 66},
|
||||
Err: errors.New("expected label selectors only"),
|
||||
Query: `info(http_request_counter_total{namespace="zzz"}, {foo="bar"} == 1)`,
|
||||
},
|
||||
},
|
||||
},
|
||||
// Test that nested parentheses result in the correct position range.
|
||||
{
|
||||
input: `foo[11s+10s-5*2^2]`,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user