router: add new path-splitting prefix matcher#20145
Conversation
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
|
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. |
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
|
Not sure about the naming, |
lambdai
left a comment
There was a problem hiding this comment.
Thank you! The test cases are awesome!
|
I'm on the fence here on whether to do this vs the other alternatives in #18148. @kyessenov @snowp |
|
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. |
|
@snowp can you help out here with matcher + RouteConfiguration? |
|
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. |
|
@tpetkov-VMW this is failing on version history formatting - but i guess you are waiting for feedback before proceeding/fixing /wait-any |
|
I'm not sure what to do, and whether this patch is desired at all. |
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
|
@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). |
|
/wai |
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
adisuissa
left a comment
There was a problem hiding this comment.
Thanks, looks good!
Left a few nits.
/wait
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
adisuissa
left a comment
There was a problem hiding this comment.
Thanks, LGTM!
/lgtm api
LGTM code changes.
Can you please add release-notes?
|
/assign-from @envoyproxy/senior-maintainers |
|
@envoyproxy/senior-maintainers assignee is @htuch |
I've added them in /docs/root/version_history/current.rst but not sure what to write in the comment at the top |
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) && |
There was a problem hiding this comment.
The path_patcher_ will did the invoke Http::PathUtil::removeQueryAndFragment on the path again.
envoy/source/common/common/matchers.cc
Line 126 in b77651d
Not sure whether worth to use envoy::type::matcher::v3::StringMatcher here directly. Leave this to other reviewers.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
It seemed like the most concise way to do it, without expanding the StringMatcher definition.
|
LGTM |
adisuissa
left a comment
There was a problem hiding this comment.
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) && |
There was a problem hiding this comment.
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) && |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
It would be good to use consistent test cases that are easy to correlate across the JWT and core router.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
Signed-off-by: Toma Petkov <tpetkov@vmware.com>
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>
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