-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
kong proxy match order #4121
Comments
The matching can definitely be complex and counter intuitive and will depend on the exact examples you are using. Please review the following discussions and documentation and reply with the exact routes and requests you are using. https://discuss.konghq.com/t/a-few-words-on-regex-uris-usage-and-common-pitfalls/506 and https://docs.konghq.com/1.0.x/proxy/#matching-priorities Regards, |
I think it is a bug. I will send a PR soon. |
This is not a bug, but a known missing feature. The feature would be the equivalent of the nginx The order of evaluation is:
But in the case of multiple matches, the priority order is:
Of course, the actual order of evaluation is determined by the number of matching properties. So a Route with a host and a path will always be matched, even if it has a prefix path while another route has a plain matching path (but no matching host, that is). |
According to this:
So I guess we need to update the docs? In a meanwhile I corrected this and some other issues in path matching in #4153 (though, now I am not sure should we change it a bit?) |
@thibaultcha, I don't fully understand the:
You mean if single route has multiple |
Just a note, this very same issue has previously been discussed in #3111. |
@thibaultcha you described it as:
How is it different from:
|
This piece is correct. But regex paths are also evaluated after prefix paths and take precedence if there is a match (over the previous prefix match). That is what the
Given a Route with a prefix path, and another Route with a regex path (and both match the incoming request path), the latter will override the former, even though the former was evaluated first, and was a match. This is what the documentation describes, the order of evaluation is correctly mentioned, but we fail to mention that a regex match will override the prefix match. This is identical to nginx's behavior except that they have the
If the order was what you wrote (regexes then prefixes), then it would never be possible to override a regex with a prefix match (i.e. shadow the regex). But with the current evaluation order (as implemented and correctly documented), it is possible to do so, given we implement the Now on to the next steps, and implement the |
@thibaultcha Thank you for the full explanation on the history of how the present status came about. But I'll play Devil's (or User's?) Advocate a bit. Given that the difference between evaluation order and matching precedence is fully opaque to a Kong user (as it should be; only the second one matters), the users are fully justified in thinking that the "evaluation order" the documentation mentions are in fact the precedence rules (especially since the precedence rules themselves are not distinguished from that), and that either the docs or code are wrong. I'm sure that if I show our proxy docs to 10 people and ask them "given route A with If the code is not changing to match their expectations, then the docs should change. As for the prefix-not-regex functionality, I think the Nginx evaluation order has IMO a weird design that I think we shouldn't expose or replicate (I didn't dig the full history of past Nginx releases, but the In light of all this, moving forward, I believe we should just generalize the
I think the explicit This sounds flexible enough. The Nginx docs contain this example to illustrate their semantics:
in our case, that would be (modulo regex case-insensitivity) [ { "paths": ["/$"], "priority": 100, "service": A },
{ "paths": ["/images/"], "priority": 100, "service": D },
{ "paths": ["\\.(gif|jpg|jpeg)$"], "priority": 200, "service": E },
{ "paths": ["/documents/"], "priority": 200, "service": C },
{ "paths": ["/"], "priority": 200, "service": B } ] Presentation is central for understandability, so ideally we should list routes sorted by matching priority (including the tie-breaking logic). The example above could use 5 different priority numbers, I just used 2 to illustrate the tie-breaking. (Side note: we could even optimize any |
Yes, I said so in my above comment: the docs could be clarified around this use-case, definitely. The code should also change, is what I was hoping was transpiring from my above comments as well: the router is still incomplete in that regard (whichever tie-breaker attribute we end up implementing).
Indeed. In December, I advocated for this field to be updated to I like the idea of relying solely on the |
We always need some criteria for tie-breaking (even if it's My risk-mitigation suggestion is to have the current behavior (regexes first, prefixes long-to-short next) to be the tie-breaker for |
By “solely”, I meant without |
closing for lack of activity (and probably outdated) |
Don't think this is outdated, but certainly still a missing feature. Shall we reopen but rename it maybe? There's valuable explanations in here. |
Do we have any plans of implementing this feature, or do we continue with kong overriding a prefix match with a regex if both of them match? |
NOTE: GitHub issues are reserved for bug reports only. For anything else,
please join the conversation in Kong Nation https://discuss.konghq.com/.
Please read the CONTRIBUTING.md guidelines to learn on which channels you can
seek for help and ask general questions:
https://github.com/Kong/kong/blob/master/CONTRIBUTING.md#where-to-seek-for-help
Summary
SUMMARY_GOES_HERE
i configured some routes,but the true matching rule is different from the docs tells. i think docs says the matching rule is:
for example, two rules:
a: {path:'/api/account'}
b: {path:'/api/.*'}
when requesting '/api/account/getAll',it matched b.
that is to say the truth is:
i use the default kong config and db type is postgres. hope for your answer.
Additional Details & Logs
$ kong 0.14.0
)$ kong start --vv
)<KONG_PREFIX>/logs/error.log
)https://docs.konghq.com/latest/admin-api/#retrieve-node-information)
The text was updated successfully, but these errors were encountered: