On Mon, Nov 22, 2021 at 3:16 PM Zexuan Luo <[email protected]> wrote:
> So far, we can match routes with hosts/remote_addrs/vars. How can we > compare two routes, one has vars and the other has hosts? > there is no way for this case. > > YuanSheng Wang <[email protected]> 于2021年11月22日周一 下午3:07写道: > > > > hi: > > > > This is indeed an easier way to understand. > > > > I like this proposal very much. > > > > In this case, Route1 should have a higher priority than Route2. > > > > ================= > > { > > "name": "route1", > > "uri": "/_graphql", > > "vars": [ > > ["graphql_operation", "==", "query"], > > ["graphql_name", "==", "getRepo"], > > ["graphql_root_fields", "has", "owner"] > > ], > > "upstream": { > > "type": "roundrobin", > > "nodes": { > > "39.97.63.215:80 <http://39.97.63.215/>": 1 > > } > > } > > } > > > > and > > > > { > > "name": "route2", > > "uri": "/_graphql", > > "upstream": { > > "type": "roundrobin", > > "nodes": { > > "39.97.63.215:81": 1 > > } > > } > > } > > > > > > On Fri, Nov 19, 2021 at 3:50 PM Li Yang <[email protected]> wrote: > > > > > Hello, Community, > > > > > > Currently in APISIX, there is a built-in prioritization of > routes by > > > the matching uri. > > > For example, if the requested uri is /foo/bar, and the server side > routes > > > contain /foo/bar and /foo/* and /*. > > > Although all 3 uri patterns match /foo/bar, only the exact match > /foo/bar > > > will be chosen. That design makes > > > much sense since a stricter route takes priority than a looser one. > > > But when we have route matching on fields other than uri, the > > > priority will only depend on the priority field. > > > For example, consider 2 routes: > > > > > > { > > > "name": "route1", > > > "uri": "/_graphql", > > > "vars": [ > > > ["graphql_operation", "==", "query"], > > > ["graphql_name", "==", "getRepo"], > > > ["graphql_root_fields", "has", "owner"] > > > ], > > > "upstream": { > > > "type": "roundrobin", > > > "nodes": { > > > "39.97.63.215:80": 1 > > > } > > > } > > > } > > > > > > and > > > > > > { > > > "name": "route2", > > > "uri": "/_graphql", > > > "upstream": { > > > "type": "roundrobin", > > > "nodes": { > > > "39.97.63.215:81": 1 > > > } > > > } > > > } > > > > > > A request which matches both route1 and route2 will possibly hit > > > route2 since we don't have prioritization on vars. > > > > > > Although priority setting can help here, if a big organization > > > shares the same APISIX, it will be difficult for all > > > the developers to agree on how to use the priorities since every > priority > > > itself can impact others in an unexpected way. > > > > > > Here I want to propose that we provide a smart prioritization: > > > > > > * If route X and route Y share the same URI, their priority will > be > > > determined like this: * > > > * Route X should be matched first if and only if route X's > matching > > > rule set is a proper superset of route Y's matching rule set.* > > > > > > Relevant discussion: > https://github.com/apache/apisix/issues/3865 > > > > > > > > > -- > > > > *MembPhis* > > My GitHub: https://github.com/membphis > > Apache APISIX: https://github.com/apache/apisix > -- *MembPhis* My GitHub: https://github.com/membphis Apache APISIX: https://github.com/apache/apisix
