fix(route-http-match): adjust route matching to more closely align to… - #4604
Conversation
|
Looking at how route precedence ordering happens, it seems like this logic is actually spread across a few different places and the result may not be what we want. In the policy controller, routes are sorted by timestamp then by name: https://github.com/linkerd/linkerd2/blob/main/policy-controller/grpc/src/outbound.rs#L677 with older timestamps getting sorted to the front of the list. This is intended to give HTTPRoutes with older timestamps higher priority. Then in the proxy, we define a cmp which compares based on match length (and match type, with your change). Finally, the proxy uses that cmp to pick the maximum match (https://github.com/linkerd/linkerd2-proxy/blob/main/linkerd/http/route/src/lib.rs#L93). But if there are multiple maximal matches then So our priority matching may be wrong in multiple ways. I'd recommend the following actions:
|
|
I agree that it's a little confusing for the matching to be split this way. I'm interested in the longer term fix here. I'll take some time to refactor and see where I land. I did add some unit tests for the precedence ordering but I can add an inter test for more complete verification. I think in my ideal world, the config and spec are completely handled in the data plane. edit: I'll create a separate task for doing the long term work. For now, I will go with the short-term approach and the integration test for verification. |
|
Something to keep in mind is that I don't think we send the resource timestamps to the proxy so the data plane may not have all the necessary information to determine the full priority order. In my opinion, the control plane is likely a better place to do this sorting. I'm not sure why we originally decided to do match length sorting in the data plane but it might have been because we were calculating the match length based on the length of the matched segment in the URI, which is only known at request time by the proxy. But it looks like the spec https://gateway-api.sigs.k8s.io/reference/api-spec/main/spec/#httprouterule doesn't say we have to do this and leaves the priority order of Regex matches up to the implementation. |
653fd89 to
e9f2d12
Compare
|
the latest commit adds verification of the gateway htttproute spec via integration tests. also I did introduce a |
|
i see that i have been requested as a reviewer for this.
i'd like to defer to @adleong, who has context for this already. if her advice is that the control plane would be a better place to do this sorting, particularly if the proxy does not have a complete picture of the information to determine priority order, perhaps we should investigate a fix there instead?
my understanding is that this branch currently performs option 2 suggested above. if so, i would not block on this, but would want to see a ticket filed tracking the long-term solution described in step 3. |
e9f2d12 to
1871fad
Compare
|
@cratelyn, added you as a reviewer in case you had some cycles the PR does implement option 2. i created this ticket for the long-term work in 3 and will start working on it as a fast follow to this |
1871fad to
c116901
Compare
|
fwiw, here is the follow up: linkerd/linkerd2#15614 |
442d1ba to
6e64155
Compare
… gateway api httproute spec also address edge case around ties between exact and prefix match; refactor some integ tests Signed-off-by: Anthony Turcios (anthoturc) <anthony@buoyant.io>
6e64155 to
e6c4d4d
Compare
… gateway api httproute spec
also address edge case around ties between exact and prefix match