From bef9d4e18226775ef334a0dc79f5a9b4007d0424 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Thu, 12 Nov 2020 14:25:52 +0000 Subject: [PATCH] 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 --- promql/parser/parse.go | 2 +- promql/parser/parse_test.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/promql/parser/parse.go b/promql/parser/parse.go index 50d69b21d..99879445d 100644 --- a/promql/parser/parse.go +++ b/promql/parser/parse.go @@ -577,7 +577,7 @@ func (p *parser) checkAST(node Node) (typ ValueType) { case *SubqueryExpr: ty := p.checkAST(n.Expr) 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: p.checkAST(n.VectorSelector) diff --git a/promql/parser/parse_test.go b/promql/parser/parse_test.go index 8b5150540..fc965e43a 100644 --- a/promql/parser/parse_test.go +++ b/promql/parser/parse_test.go @@ -15,6 +15,7 @@ package parser import ( "math" + "strings" "testing" "time" @@ -2234,6 +2235,11 @@ var testExpr = []struct { input: "rate(avg)", fail: true, 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)", expected: &AggregateExpr{ @@ -2644,11 +2650,11 @@ var testExpr = []struct { }, { input: "test[5d] OFFSET 10s [10m:5s]", 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]`, 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`, }, }