Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eskip: do not add empty last route id to parse error #2875

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cmd/webhook/admission/admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestRouteGroupAdmitter(t *testing.T) {
{
name: "invalid eskip filters",
inputFile: "rg-with-invalid-eskip-filters.json",
message: "parse failed after token status, last route id: , position 11: syntax error",
message: "parse failed after token status, position 11: syntax error",
},
{
name: "valid eskip predicates",
Expand All @@ -116,12 +116,12 @@ func TestRouteGroupAdmitter(t *testing.T) {
{
name: "invalid eskip predicates",
inputFile: "rg-with-invalid-eskip-predicates.json",
message: "parse failed after token Method, last route id: Method, position 6: syntax error",
message: "parse failed after token Method, position 6: syntax error",
},
{
name: "invalid eskip filters and predicates",
inputFile: "rg-with-invalid-eskip-filters-and-predicates.json",
message: "parse failed after token status, last route id: , position 11: syntax error\\nparse failed after token Method, last route id: Method, position 6: syntax error",
message: "parse failed after token status, position 11: syntax error\\nparse failed after token Method, position 6: syntax error",
},
{
name: "invalid routgroup multiple filters per json/yaml array item",
Expand Down Expand Up @@ -180,12 +180,12 @@ func TestIngressAdmitter(t *testing.T) {
{
name: "invalid eskip filters",
inputFile: "invalid-filters.json",
message: `invalid \"zalando.org/skipper-filter\" annotation: parse failed after token this, last route id: , position 9: syntax error`,
message: `invalid \"zalando.org/skipper-filter\" annotation: parse failed after token this, position 9: syntax error`,
},
{
name: "invalid eskip predicates",
inputFile: "invalid-predicates.json",
message: `invalid \"zalando.org/skipper-predicate\" annotation: parse failed after token ), last route id: , position 15: syntax error`,
message: `invalid \"zalando.org/skipper-predicate\" annotation: parse failed after token ), position 15: syntax error`,
},
{
name: "invalid eskip routes",
Expand All @@ -195,7 +195,7 @@ func TestIngressAdmitter(t *testing.T) {
{
name: "invalid eskip filters and predicates",
inputFile: "invalid-filters-and-predicates.json",
message: `invalid \"zalando.org/skipper-filter\" annotation: parse failed after token this, last route id: , position 9: syntax error\ninvalid \"zalando.org/skipper-predicate\" annotation: parse failed after token ), last route id: , position 15: syntax error`,
message: `invalid \"zalando.org/skipper-filter\" annotation: parse failed after token this, position 9: syntax error\ninvalid \"zalando.org/skipper-predicate\" annotation: parse failed after token ), position 15: syntax error`,
},
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func Test_Validate(t *testing.T) {
c.KubernetesEastWestRangePredicatesString = "WrongEastWestMode"
},
wantErr: true,
want: errors.New("invalid east-west-range-predicates: parse failed after token ->, last route id: WrongEastWestMode, position 20: syntax error"),
want: errors.New("invalid east-west-range-predicates: parse failed after token ->, position 20: syntax error"),
},
{
name: "test wrong HistoGramBuckets",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
\[routegroup\] parse failed after token foo, last route id: , position 8: syntax error
\[routegroup\] parse failed after token foo, position 8: syntax error
Original file line number Diff line number Diff line change
@@ -1 +1 @@
\[routegroup\] parse failed after token Header, last route id: Header, position 6: syntax error
\[routegroup\] parse failed after token Header, position 6: syntax error
Original file line number Diff line number Diff line change
@@ -1 +1 @@
\[routegroup\] parse failed after token foo, last route id: , position 8: syntax error
\[routegroup\] parse failed after token foo, position 8: syntax error
Original file line number Diff line number Diff line change
@@ -1 +1 @@
\[routegroup\] parse failed after token foo, last route id: foo, position 3: syntax error
\[routegroup\] parse failed after token foo, position 3: syntax error
17 changes: 7 additions & 10 deletions eskip/eskip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ func TestParse(t *testing.T) {
"syntax without id",
`* -> #`,
nil,
// TODO: remove empty last route id
"parse failed after token ->, last route id: , position 5: syntax error",
"parse failed after token ->, position 5: syntax error",
}} {
t.Run(ti.msg, func(t *testing.T) {
routes, err := Parse(ti.expression)
Expand Down Expand Up @@ -220,14 +219,14 @@ func TestParseFilters(t *testing.T) {
"error",
"trallala",
nil,
// TODO: remove empty last route id and fix position
"parse failed after token ->, last route id: , position 16: syntax error",
// TODO: fix position
"parse failed after token ->, position 16: syntax error",
}, {
"error 2",
"foo-bar",
nil,
// TODO: remove empty last route id and fix position
"parse failed after token foo, last route id: , position 8: syntax error",
// TODO: fix position
"parse failed after token foo, position 8: syntax error",
}, {
"success",
`filter1(3.14) -> filter2("key", 42)`,
Expand Down Expand Up @@ -259,13 +258,11 @@ func TestParsePredicates(t *testing.T) {
}, {
title: "invalid",
input: `not predicates`,
// TODO: fix wrong last route id
err: "parse failed after token predicates, last route id: not, position 14: syntax error",
err: "parse failed after token predicates, position 14: syntax error",
}, {
title: "invalid",
input: `Header#`,
// TODO: fix wrong last route id
err: "parse failed after token Header, last route id: Header, position 6: syntax error",
err: "parse failed after token Header, position 6: syntax error",
}, {
title: "single predicate",
input: `Foo("bar")`,
Expand Down
8 changes: 6 additions & 2 deletions eskip/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ func (l *eskipLex) Lex(lval *eskipSymType) int {
}

func (l *eskipLex) Error(err string) {
lastRouteID := ""
if l.lastRouteID != "" {
lastRouteID = ", last route id: " + l.lastRouteID
}
l.err = fmt.Errorf(
"parse failed after token %s, last route id: %v, position %d: %s",
l.lastToken, l.lastRouteID, l.initialLength-len(l.code), err)
"parse failed after token %s%s, position %d: %s",
l.lastToken, lastRouteID, l.initialLength-len(l.code), err)
}
55 changes: 28 additions & 27 deletions eskip/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions eskip/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ routes:
}

routedef:
routeid colon route {
$$.route = $3.route
routeid route {
$$.route = $2.route
$$.route.id = $1.token
}

routeid:
symbol {
symbol colon {
// match symbol and colon to get route id early even if route parsing fails later
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any performance improvement here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, performance change is within measurement deviation

goos: linux
goarch: amd64
pkg: github.com/zalando/skipper/eskip
cpu: Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
                  │   HEAD~1    │                HEAD                │
                  │   sec/op    │   sec/op     vs base               │
ParsePredicates-8   8.189µ ± 4%   8.515µ ± 4%  +3.98% (p=0.007 n=10)
Parse-8             253.3m ± 2%   256.8m ± 3%  +1.38% (p=0.011 n=10)
geomean             1.440m        1.479m       +2.67%

                  │    HEAD~1    │                HEAD                 │
                  │     B/op     │     B/op      vs base               │
ParsePredicates-8   1.961Ki ± 0%   1.961Ki ± 0%       ~ (p=1.000 n=10)
Parse-8             49.02Mi ± 0%   49.02Mi ± 0%       ~ (p=0.566 n=10)
geomean             313.7Ki        313.7Ki       -0.00%

                  │   HEAD~1    │                 HEAD                 │
                  │  allocs/op  │  allocs/op   vs base                 │
ParsePredicates-8    32.00 ± 0%    32.00 ± 0%       ~ (p=1.000 n=10) ¹
Parse-8             1.080M ± 0%   1.080M ± 0%       ~ (p=0.700 n=10)
geomean             5.879k        5.879k       +0.00%
¹ all samples are equal

$$.token = $1.token
eskiplex.(*eskipLex).lastRouteID = $1.token
}
Expand Down