-
Notifications
You must be signed in to change notification settings - Fork 680
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
internal/dag: Add exact path match condition in HttpProxy #5000
internal/dag: Add exact path match condition in HttpProxy #5000
Conversation
Hi @arjunsalyan! Welcome to our community and thank you for opening your first Pull Request. Someone will review it soon. Thank you for committing to making Contour better. You can also join us on our mailing list and in our channel in the Kubernetes Slack Workspace |
This is by no means near completion. Still need to cover some edge cases as I feel I must have missed them, and work on the documentation. Any reviews and feedback would be very helpful. Also, please bear with me as this is my first PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re the rules around merging path conditions in the tree of HTTPProxy includes:
// If the root condition is prefix, and included condition is prefix then after merging we get one prefix condition.
// If the root condition is prefix, and included condition is exact then after merging we get one exact condition.
// If the root condition is exact, and included condition is exact then after merging we get one exact condition.
// If the root condition is exact, and included condition is prefix then after merging we get one prefix condition.
an alternate interpretation of the "exact" match in this context could be that such a match is terminal, i.e. it must come as a leaf of the tree of match conditions, since as it stands above if an exact match is at the root or middle of an include tree it effectively becomes a prefix match. if we want to keep these things distinct/clear that might be a way to go
Thanks for the PR @arjunsalyan I think this is a good start, but we will definitely need some more unit test coverage, we can give pointers where to look to add these if you like we should already have logic further in our processing logic to sort the generated routes properly so that exact matches are considered by Envoy first, so this should mostly be covered by httpproxy processor/dag tests and some end to end tests |
Agreed @sunjayBhatia, If you see the next line ahead of these comments I have mentioned the interpretation. These comments are just to explain why we reached the conclusion that the leaf decides the path type.
Will improve the wording of this statement. Let me know if you meant something else. |
Above I meant that an option we can take is to not allow and mark an HTTPProxy as Invalid if you try to use an exact match in an include match condition |
823e20d
to
3d26269
Compare
Got it. I have some subjective thoughts here, especially for the case of delegation of a path to teams. Included routes should have the flexibility to use exact matches. But open to any other views on this. I have added unit tests and e2e trying to cover most of the things. Will start with documentation once these things come to good shape. |
For now I have added the docs considering my initial theory about routes delegation, just to make this PR ready for a review. Although we can revisit it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my interpretation of "Exact" path matching in conjunction with the Inclusion feature is that if you are using Inclusion, you really want a "Prefix" match (because the Included child proxy can then do different matching) so "Exact" matches should be disallowed on the path match conditions on an Include
Yeah, that is how I had been thinking about it too, should be disallowed as an Include condition. |
Alright, I am starting to see the point here. But before we reach a conclusion, please allow me to put one last statement in the favour of the proposed merging algorithm.
There are definitely other ways to handle this, but just putting a use case. Anyways, I am now aligned on not allowing the |
1dad0b2
to
29ccfcf
Compare
The changes for disallowing the |
}, | ||
}, | ||
} | ||
invalidRootProxy := &contourv1.HTTPProxy{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's ok to omit testing this in e2e tests, should instead get coverage in the dag
package tests
Paths defined are matched using exact conditions. | ||
Up to one exact condition may be present in any condition block. Any condition block can | ||
either have an exact condition or prefix condition, but not both together. Exact conditions are | ||
not allowed in root httpproxies or in includes blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not allowed in root httpproxies or in includes blocks. | |
only allowed in route match conditions and not in include match conditions. |
To resolve this Contour applies the following logic. | ||
|
||
- `prefix:` conditions are concatenated together in the order they were applied from the root object. For example the conditions, `prefix: /api`, `prefix: /v1` becomes a single `prefix: /api/v1` conditions. Note: Multiple prefixes cannot be supplied on a single set of Route conditions. | ||
- `exact:` conditions are also concatenated just like `prefix:` conditions, but `exact:` conditions are not allowed in the root httpproxy or in the inlcusion block. If the child httpproxy has `exact:` condition then after concatenation, it becomes a single `exact:` condition. For example, `prefix: /static` and `exact: /main.js` become a single `exact: /static/main.js` condition. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `exact:` conditions are also concatenated just like `prefix:` conditions, but `exact:` conditions are not allowed in the root httpproxy or in the inlcusion block. If the child httpproxy has `exact:` condition then after concatenation, it becomes a single `exact:` condition. For example, `prefix: /static` and `exact: /main.js` become a single `exact: /static/main.js` condition. | |
- `exact:` conditions are also concatenated just like `prefix:` conditions, but `exact:` conditions are not allowed in include match conditions. If the child httpproxy has `exact:` condition then after concatenation, it becomes a single `exact:` condition. For example, `prefix: /static` and `exact: /main.js` become a single `exact: /static/main.js` condition. |
0636f94
to
d7e30b3
Compare
@sunjayBhatia Added the generated sources, which were leading to the failed test. |
This is strange
These tests pass all fine when I run them locally. Looking into it |
you'll want to merge/rebase on main, and update the port in that test (github is merging the PR with the base branch when checking out the code) |
This adds support for exact path matching in the HttpProxy along side prefix matching Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
…ical Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
d7e30b3
to
56fd244
Compare
Ah! The tests were updated. Fixed, thanks. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #5000 +/- ##
==========================================
+ Coverage 77.74% 77.79% +0.04%
==========================================
Files 139 139
Lines 18073 18121 +48
==========================================
+ Hits 14051 14097 +46
- Misses 3750 3753 +3
+ Partials 272 271 -1
|
|
||
f.CreateHTTPProxyAndWaitFor(serviceProxy, e2e.HTTPProxyValid) | ||
|
||
cases := map[string]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this looks correct, but it's not super intuitive to read
not a huge deal but would be nice to either add some comments above some of the cases or use naming of the routes/services that make it clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can agree to that, it is just the nature of a few cases that I could not find better naming. Have tried something with comments, not sure how much value that adds though.
f.CreateHTTPProxyAndWaitFor(baseProxy, e2e.HTTPProxyValid) | ||
f.CreateHTTPProxyAndWaitFor(invalidRootProxy, e2e.HTTPProxyInvalid) | ||
|
||
cases := map[string]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar nit to the above on comments/naming to make these test cases super clear (looks correct though)
internal/dag/builder_test.go
Outdated
@@ -14958,6 +15090,9 @@ func listeners(ls ...*Listener) []*Listener { | |||
func prefixString(prefix string) MatchCondition { | |||
return &PrefixMatchCondition{Prefix: prefix, PrefixMatchType: PrefixMatchString} | |||
} | |||
func exactString(exact string) MatchCondition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the prefixString
was named since it represented a prefix match that would basically match a path using "string prefix" vs. matching path segments, we could change this to just exact
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, rather exact()
is already there making it completely redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good overall, just some tiny nits
approving but will leave for another maintainer to have a pass over as well before merge
Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
exactString(exact string) is redundant and does the same as exact(path string) Signed-off-by: Arjun Salyan <iarjunsalyan@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @arjunsalyan!
This adds support for exact path matching in the HttpProxy along side prefix matching
fixes #4069
Signed-off-by: Arjun Salyan iarjunsalyan@gmail.com