Skip to content

router: add new path-splitting prefix matcher#20145

Merged
htuch merged 15 commits intoenvoyproxy:mainfrom
tpetkov-VMW:path_splitting_prefix_match
Apr 1, 2022
Merged

router: add new path-splitting prefix matcher#20145
htuch merged 15 commits intoenvoyproxy:mainfrom
tpetkov-VMW:path_splitting_prefix_match

Conversation

@tpetkov-VMW
Copy link
Copy Markdown
Contributor

@tpetkov-VMW tpetkov-VMW commented Feb 28, 2022

Commit Message: Extend RouteMatch with a new field for subpath matching
Additional Description: The new field would allow more efficient generation of routes, replacing pairs of path+prefix routes into one path_separated_prefix route
Risk Level: Low
Testing: Unit test
Docs Changes: inline
Release Notes: Added
Fixes #18148

Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
@tpetkov-VMW tpetkov-VMW requested a review from lizan as a code owner February 28, 2022 21:45
@repokitteh-read-only
Copy link
Copy Markdown

Hi @tpetkov-VMW, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #20145 was opened by tpetkov-VMW.

see: more, trace.

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy[\w/]*/(v1alpha\d?|v1|v2alpha\d?|v2))|(api/envoy/type/(matcher/)?\w+.proto).
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @htuch
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #20145 was opened by tpetkov-VMW.

see: more, trace.

Copy link
Copy Markdown
Contributor

@lambdai lambdai left a comment

Choose a reason for hiding this comment

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

Thank you! Almost there

@tpetkov-VMW
Copy link
Copy Markdown
Contributor Author

Not sure about the naming, path_separated_prefix seems long.
Thinking about subpath as an alternative

lambdai
lambdai previously approved these changes Mar 2, 2022
Copy link
Copy Markdown
Contributor

@lambdai lambdai left a comment

Choose a reason for hiding this comment

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

Thank you! The test cases are awesome!

@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 3, 2022

I'm on the fence here on whether to do this vs the other alternatives in #18148. @kyessenov @snowp

@kyessenov
Copy link
Copy Markdown
Contributor

Until we can use the matcher API to select routes, I don't see another way to support this without adding API fields. So I think the stumbling block is moving towards matchers in RDS, and I'm not up to date on that area.

@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 10, 2022

@snowp can you help out here with matcher + RouteConfiguration?

@snowp
Copy link
Copy Markdown
Contributor

snowp commented Mar 10, 2022

It is possible today to use the new matching structure via RDS (#17633), so if that was the main perceived blocker perhaps this should go into the new matcher framework? Or are there other reasons to want to continue to add to the legacy route matcher?

@tpetkov-VMW
Copy link
Copy Markdown
Contributor Author

It is possible today to use the new matching structure via RDS (#17633), so if that was the main perceived blocker perhaps this should go into the new matcher framework? Or are there other reasons to want to continue to add to the legacy route matcher?

Adding it to the legacy route matcher would give users a more easily consumable feature.
Frankly, the new matching structure is still confusing to me, and that's the main reason I chose the legacy routes.
I could try to open another PR for the RDS version and close this one, or perhaps they could coexist?

@phlax
Copy link
Copy Markdown
Member

phlax commented Mar 21, 2022

@tpetkov-VMW this is failing on version history formatting - but i guess you are waiting for feedback before proceeding/fixing

/wait-any

@tpetkov-VMW
Copy link
Copy Markdown
Contributor Author

I'm not sure what to do, and whether this patch is desired at all.
I'll fix what's needed to pass the checks, so the PR is ready to go.

Signed-off-by: Toma Petkov <tpetkov@vmware.com>
@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 23, 2022

@tpetkov-VMW I've discussed this with @envoyproxy/api-shepherds and we're in-principle good with moving ahead with this PR. The consensus is that we will continue to support and evolve the existing matchers (and ideally integrate them as leaf functions into the generalized match trees).

@htuch
Copy link
Copy Markdown
Member

htuch commented Mar 23, 2022

/wai

Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks, looks good!
Left a few nits.
/wait

Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!
/lgtm api
LGTM code changes.
Can you please add release-notes?

@adisuissa
Copy link
Copy Markdown
Contributor

/assign-from @envoyproxy/senior-maintainers

@repokitteh-read-only
Copy link
Copy Markdown

@envoyproxy/senior-maintainers assignee is @htuch

🐱

Caused by: a #20145 (comment) was created by @adisuissa.

see: more, trace.

@tpetkov-VMW
Copy link
Copy Markdown
Contributor Author

tpetkov-VMW commented Mar 28, 2022

Can you please add release-notes?

I've added them in /docs/root/version_history/current.rst but not sure what to write in the comment at the top
Is just "inline" okay?

@adisuissa
Copy link
Copy Markdown
Contributor

Can you please add release-notes?

I've added them in /docs/root/version_history/current.rst but not sure what to write in the comment at the top Is just "inline" okay?

Yep. I typically write "Added", unless there's some special doc that was added.

BTW: please merge main.

return nullptr;
}
absl::string_view path = Http::PathUtil::removeQueryAndFragment(headers.getPathValue());
if (path.size() >= prefix_.size() && path_matcher_->match(path) &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The path_patcher_ will did the invoke Http::PathUtil::removeQueryAndFragment on the path again.

return matcher_.match(Http::PathUtil::removeQueryAndFragment(path));

Not sure whether worth to use envoy::type::matcher::v3::StringMatcher here directly. Leave this to other reviewers.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, you are correct.
I think the alternative is to not invoke path_matcher_->match method, which could result in inconsistencies in the future if this method is updated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seemed like the most concise way to do it, without expanding the StringMatcher definition.

@soulxu
Copy link
Copy Markdown
Member

soulxu commented Mar 29, 2022

LGTM

adisuissa
adisuissa previously approved these changes Mar 29, 2022
Copy link
Copy Markdown
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

LGTM thanks!
Needs approval from senior-maintainer.

return nullptr;
}
absl::string_view path = Http::PathUtil::removeQueryAndFragment(headers.getPathValue());
if (path.size() >= prefix_.size() && path_matcher_->match(path) &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, you are correct.
I think the alternative is to not invoke path_matcher_->match method, which could result in inconsistencies in the future if this method is updated.

return false;
}
absl::string_view path = Http::PathUtil::removeQueryAndFragment(headers.getPathValue());
if (path.size() >= prefix_.size() && path_matcher_->match(path) &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bit unhappy we have duplicative logic here @qiwzhang. I've probably complained before and this is unrelated to this PR, so just an observation, but by having to copy+paste all our matching logic in two places, we are leaving open a significant opportunity for drift and check vs. use semantic differences between this and routing.

htuch
htuch previously approved these changes Mar 30, 2022
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Looks good, my main concern is not specific to this PR but that we are having to constantly copy+paste our match logic across this and the JWT filter. This is related to the generic matcher discussion @envoyproxy/api-shepherds @snowp, since if we were using that, we would be able to just implement this once.

TestUtility::loadFromYaml(config, rule);
MatcherConstPtr matcher = Matcher::create(rule);
auto headers = TestRequestHeaderMapImpl{{":path", "/api"}};
EXPECT_TRUE(matcher->matches(headers));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be good to use consistent test cases that are easy to correlate across the JWT and core router.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean "equalize the test inputs per test case"?
I'll start with that, and if more work needs to be done - just elaborate on it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure about the definition of equalize :) Anything you can do to make tests more consistent between JWT and core router. Since you're taking on #20578 I'm fine with punting to that if you prefer to do it there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made it so the jwt test cases are a subset of the router ones, and the test strings are pretty much the same.
They don't look exactly the same, but the correlation should be obvious.

Signed-off-by: Toma Petkov <tpetkov@vmware.com>
@tpetkov-VMW tpetkov-VMW dismissed stale reviews from htuch and adisuissa via dd8972a March 31, 2022 16:08
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@htuch htuch merged commit 8f9e112 into envoyproxy:main Apr 1, 2022
@tpetkov-VMW tpetkov-VMW deleted the path_splitting_prefix_match branch April 5, 2022 13:21
ravenblackx pushed a commit to ravenblackx/envoy that referenced this pull request Jun 8, 2022
The new field would allow more efficient generation of routes, replacing pairs of path+prefix routes into one path_separated_prefix route

Risk Level: Low
Testing: Unit test
Docs Changes: inline
Release Notes: Added

Fixes envoyproxy#18148

Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add efficient path-based prefix matching

8 participants