Skip to content
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

question about path match order? #2974

Closed
zirain opened this issue Apr 14, 2024 · 6 comments
Closed

question about path match order? #2974

zirain opened this issue Apr 14, 2024 · 6 comments

Comments

@zirain
Copy link
Contributor

zirain commented Apr 14, 2024

there's an sample httproute as follows:

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: match-order
spec:
  parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: eg/kuma/contour # change to different
  rules:
    - backendRefs:
        - group: ""
          kind: Service
          name: httpbin
          port: 8000
          weight: 1
      matches:
        - path:
            type: PathPrefix
            value: /api/store
        - path:
            type: RegularExpression
            value: ^/api/[1-9][0-9]*/.*$
    - backendRefs:
        - group: ""
          kind: Service
          name: httpbin
          port: 8000
          weight: 1
      matches:
        - path:
            type: PathPrefix
            value: /

I test with EnvoyGateway, Contour and Kuma (all of them base on envoy)but got different result:

  • Contour
- ignorePortInHostMatching: true
  name: http-80
  requestHeadersToAdd:
  - header:
      key: x-request-start
      value: t=%START_TIME(%s.%3f)%
  virtualHosts:
  - domains:
    - '*'
    name: '*'
    routes:
    - match:
        safeRegex:
          regex: ^^/api/[1-9][0-9]*/.*$
      metadata:
        filterMetadata:
          envoy.access_loggers.file:
            io.projectcontour.kind: HTTPRoute
            io.projectcontour.name: match-order
            io.projectcontour.namespace: default
      route:
        cluster: default/httpbin/8000/da39a3ee5e
    - match:
        pathSeparatedPrefix: /api/store
      metadata:
        filterMetadata:
          envoy.access_loggers.file:
            io.projectcontour.kind: HTTPRoute
            io.projectcontour.name: match-order
            io.projectcontour.namespace: default
      route:
        cluster: default/httpbin/8000/da39a3ee5e
    - match:
        prefix: /
      metadata:
        filterMetadata:
          envoy.access_loggers.file:
            io.projectcontour.kind: HTTPRoute
            io.projectcontour.name: match-order
            io.projectcontour.namespace: default
      route:
        cluster: default/httpbin/8000/da39a3ee5e
  • EnvoyGateway
- ignorePortInHostMatching: true
  name: default/eg/http
  virtualHosts:
  - domains:
    - '*'
    name: default/eg/http/*
    routes:
    - match:
        safeRegex:
          regex: ^/api/[1-9][0-9]*/.*$
      name: httproute/default/match-order/rule/0/match/1/*
      route:
        cluster: httproute/default/match-order/rule/0
        upgradeConfigs:
        - upgradeType: websocket
    - match:
        pathSeparatedPrefix: /api/store
      name: httproute/default/match-order/rule/0/match/0/*
      route:
        cluster: httproute/default/match-order/rule/0
        upgradeConfigs:
        - upgradeType: websocket
    - match:
        prefix: /
      name: httproute/default/match-order/rule/1/match/0/*
      route:
        cluster: httproute/default/match-order/rule/1
        upgradeConfigs:
        - upgradeType: websocket
  • Kuma
- ignorePortInHostMatching: true
  name: kuma.default:HTTP:8080:*
  requestHeadersToRemove:
  - x-kuma-tags
  validateClusters: false
  virtualHosts:
  - domains:
    - '*'
    name: '*'
    routes:
    - match:
        path: /api/store
      route:
        clusterNotFoundResponseCode: INTERNAL_SERVER_ERROR
        idleTimeout: 5s
        retryPolicy:
          numRetries: 5
          perTryTimeout: 16s
          retryBackOff:
            baseInterval: 0.025s
            maxInterval: 0.250s
          retryOn: gateway-error,connect-failure,refused-stream
        timeout: 15s
        weightedClusters:
          clusters:
          - name: httpbin_default_svc_8000-732a2f143c735941
            requestHeadersToAdd:
            - header:
                key: x-kuma-tags
                value: '&kuma.io/service=kuma_default_gateway&&kuma.io/zone=default&'
            weight: 1
    - match:
        prefix: /api/store/
      route:
        clusterNotFoundResponseCode: INTERNAL_SERVER_ERROR
        idleTimeout: 5s
        retryPolicy:
          numRetries: 5
          perTryTimeout: 16s
          retryBackOff:
            baseInterval: 0.025s
            maxInterval: 0.250s
          retryOn: gateway-error,connect-failure,refused-stream
        timeout: 15s
        weightedClusters:
          clusters:
          - name: httpbin_default_svc_8000-732a2f143c735941
            requestHeadersToAdd:
            - header:
                key: x-kuma-tags
                value: '&kuma.io/service=kuma_default_gateway&&kuma.io/zone=default&'
            weight: 1
    - match:
        prefix: /
      route:
        clusterNotFoundResponseCode: INTERNAL_SERVER_ERROR
        idleTimeout: 5s
        retryPolicy:
          numRetries: 5
          perTryTimeout: 16s
          retryBackOff:
            baseInterval: 0.025s
            maxInterval: 0.250s
          retryOn: gateway-error,connect-failure,refused-stream
        timeout: 15s
        weightedClusters:
          clusters:
          - name: httpbin_default_svc_8000-732a2f143c735941
            requestHeadersToAdd:
            - header:
                key: x-kuma-tags
                value: '&kuma.io/service=kuma_default_gateway&&kuma.io/zone=default&'
            weight: 1
    - match:
        safeRegex:
          regex: ^/api/[1-9][0-9]*/.*$
      route:
        clusterNotFoundResponseCode: INTERNAL_SERVER_ERROR
        idleTimeout: 5s
        retryPolicy:
          numRetries: 5
          perTryTimeout: 16s
          retryBackOff:
            baseInterval: 0.025s
            maxInterval: 0.250s
          retryOn: gateway-error,connect-failure,refused-stream
        timeout: 15s
        weightedClusters:
          clusters:
          - name: httpbin_default_svc_8000-732a2f143c735941
            requestHeadersToAdd:
            - header:
                key: x-kuma-tags
                value: '&kuma.io/service=kuma_default_gateway&&kuma.io/zone=default&'
            weight: 1

Is there a guidance tell vendor how to implement the route match?

@zirain
Copy link
Contributor Author

zirain commented Apr 14, 2024

xref: for istio, please see istio/istio#50108

@arkodg
Copy link
Contributor

arkodg commented Apr 15, 2024

previous discussion on path precedence in #1770

@zirain
Copy link
Contributor Author

zirain commented Apr 16, 2024

@arkodg so what the conclusion?

@dprotaso
Copy link
Contributor

Digging through - https://github.com/kubernetes-sigs/gateway-api/pull/1855/files#r1146317544

Using RegularExpressions means you let the implementation decide on the precedence

@arkodg
Copy link
Contributor

arkodg commented Apr 18, 2024

the current spec (and conformance tests test this) specifies Exact > Prefix precedence
RegularExpression precedence is implementation specific, but some implementations such as Contour, Nginx and Envoy Gateway have implemented the following precedence order - Exact > RegularExpression > Prefix, since Prefix matches are used as catch alls so are moved to the end of the match order

@zirain
Copy link
Contributor Author

zirain commented Apr 24, 2024

thanks!

@zirain zirain closed this as completed Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants