Header Based Routing Priority

Hey guys, wondering if somebody could help solve a problem. Our current setup has two potential routing methods.

  1. Direct exposure of a path e.x. /my-path defined in a VirtualService, matching on a uri.
  2. Routing to a service based on headers e.x. curl -H "service: my-service" example.com/my-path, defined in a VirtualService routing to a destination based on a header match.

A problem with this setup arises if we want to access /my-path on serviceA via header routing if that path has a URI match defined by another service. Instead of going to my-service as requested in the header match, it’ll go to /my-path owned by another service.

Is there a way we can force Istio to consider the header match as a priority, to make sure curl -H "service: my-service" example.com/my-path hits serviceA with the header match, and not serviceB with the /my-path path match?

That is to say, in all scenarios, if the service header is defined we always want the request to go to that service’s VS, we don’t care about other rules.

We happy to solve this with any sort of Istio mechanic, Envoy Filters are in the picture too. Though for clarity, the header value defined in the http match (e.x. my-service) may not match the actual k8s service, which could be called anything, making an Envoy Filter here a little difficult unless it could also do the lookup on the VS’s.

ServiceA VS Snippet

http:
  match:
    - headers:
        service:
          exact: my-service
    - uri:
        prefix: /
    route:
        - destination:
        host: my-service.default.svc.cluster.local

ServiceB VS Snippet

http:
  match:
    - uri:
        prefix: /my-path
    route:
    - destination:
        host: other-service.default.svc.cluster.local