Route matching priority is confusing / not intuitive #7887
-
I'm using Kong 2.5.0, but I do not believe this issue is version-specific. Consider two routes configured as follows:
This works exactly as expected; requests to
Based on the config above, I would expect the following:
Instead, what actually happens is:
The documentation is not clear on this topic: https://docs.konghq.com/gateway-oss/2.5.x/proxy/ First, there is this:
That's true sometimes, but apparently can be trumped by this:
There are a couple issues here. First, the sentence as written is not clear. It doesn't match the route with the most number of rules defined; it (apparently) matches the route with the most number of rules that match the request. Second, this is not intuitive at all. I would not expect a modification to route-1 that makes the request method more strict for route-1 to break routing for route-2, but that's exactly what can happen if you aren't aware of the "rule count" priority. The same issue can occur with host header rules. If route-1 ( I would encourage you to revisit/rethink the "rule count" prioritization and instead always match longest path (as described in the first quote from the documentation above), then use additional rules for request method / host header / etc to eliminate route candidates from selection. If that's not possible, then I would encourage you to update the documentation to make "rule count" section more visible and mention that "rule count" may override other rules in each of the sections that describes the individual rules. For example: "When proxying with path prefixes, the longest paths get evaluated first. This allow you to define two Routes with two paths: /service and /service/resource, and ensure that the former does not “shadow” the latter. NOTE: See the Matching priorities section below for situations where longest path may not get evaluated first." |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It resolves to
whereas with It would be hugely breaking change if we change this. We would probably instead rather add exact match, OR add this as an option. Nginx supports things like |
Beta Was this translation helpful? Give feedback.
It resolves to
route-1
as withroute-1
more criterias match:whereas with
route-2
it only matches path prefix.It would be hugely breaking change if we change this. We would probably instead rather add exact match, OR add this as an option. Nginx supports things like
=
,^~
.