mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Don't include rendered expression in parse errors. (#8177)
For a sufficiently complex expression, having to render thousands of nodes for every subquery type error can take a while - so don't do that. Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
parent
f97fba7cc9
commit
bef9d4e182
|
@ -577,7 +577,7 @@ func (p *parser) checkAST(node Node) (typ ValueType) {
|
||||||
case *SubqueryExpr:
|
case *SubqueryExpr:
|
||||||
ty := p.checkAST(n.Expr)
|
ty := p.checkAST(n.Expr)
|
||||||
if ty != ValueTypeVector {
|
if ty != ValueTypeVector {
|
||||||
p.addParseErrf(n.PositionRange(), "subquery is only allowed on instant vector, got %s in %q instead", ty, n.String())
|
p.addParseErrf(n.PositionRange(), "subquery is only allowed on instant vector, got %s instead", ty)
|
||||||
}
|
}
|
||||||
case *MatrixSelector:
|
case *MatrixSelector:
|
||||||
p.checkAST(n.VectorSelector)
|
p.checkAST(n.VectorSelector)
|
||||||
|
|
|
@ -15,6 +15,7 @@ package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -2234,6 +2235,11 @@ var testExpr = []struct {
|
||||||
input: "rate(avg)",
|
input: "rate(avg)",
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: `expected type range vector`,
|
errMsg: `expected type range vector`,
|
||||||
|
}, {
|
||||||
|
// This is testing that we are not re-rendering the expression string for each error, which would timeout.
|
||||||
|
input: "(" + strings.Repeat("-{}-1", 10000) + ")" + strings.Repeat("[1m:]", 1000),
|
||||||
|
fail: true,
|
||||||
|
errMsg: `1:3: parse error: vector selector must contain at least one non-empty matcher`,
|
||||||
}, {
|
}, {
|
||||||
input: "sum(sum)",
|
input: "sum(sum)",
|
||||||
expected: &AggregateExpr{
|
expected: &AggregateExpr{
|
||||||
|
@ -2644,11 +2650,11 @@ var testExpr = []struct {
|
||||||
}, {
|
}, {
|
||||||
input: "test[5d] OFFSET 10s [10m:5s]",
|
input: "test[5d] OFFSET 10s [10m:5s]",
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "1:1: parse error: subquery is only allowed on instant vector, got matrix in \"test[5d] offset 10s[10m:5s]\"",
|
errMsg: "1:1: parse error: subquery is only allowed on instant vector, got matrix",
|
||||||
}, {
|
}, {
|
||||||
input: `(foo + bar{nm="val"})[5m:][10m:5s]`,
|
input: `(foo + bar{nm="val"})[5m:][10m:5s]`,
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: `1:1: parse error: subquery is only allowed on instant vector, got matrix in "(foo + bar{nm=\"val\"})[5m:][10m:5s]" instead`,
|
errMsg: `1:1: parse error: subquery is only allowed on instant vector, got matrix`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue