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

List of matchers for route #34866

Open
Ferdudas97 opened this issue Jun 24, 2024 · 2 comments
Open

List of matchers for route #34866

Ferdudas97 opened this issue Jun 24, 2024 · 2 comments

Comments

@Ferdudas97
Copy link

Ferdudas97 commented Jun 24, 2024

List of matchers for route: Route should have list of matchers instead of one match

Description:
Current api forces Istio (and other control planes) to create many duplicated routes with different matchers but the same route actions. Having possibility to specify list of match rules (OR operation between all rules) would simplify a envoy config and reduce used memory.

Istio Example

Route config from Istio virtual service

  - match:
    - headers:
        x-service-tag-preference:
          regex: (^|.*\|)vte7($|\|.*)
      withoutHeaders:
        x-service-tag: {}
    - headers:
        x-service-tag:
          exact: fast
        x-service-tag-preference:
          regex: (^|.*\|)vte7($|\|.*)
    - headers:
        x-service-tag:
          exact: vte7
        x-service-tag-preference:
          regex: (^|.*\|)vte7($|\|.*)
    route:
    - destination:
        host: foo.bar.svc.cluster.local
        port:
          number: 31011
      weight: 50

produces 3 routes, with only different matchers

  {
          "match": {
           "prefix": "/",
           "case_sensitive": true,
           "headers": [
            {
             "name": "x-service-tag",
             "present_match": true,
             "invert_match": true
            },
            {
             "name": "x-service-tag-preference",
             "string_match": {
              "safe_regex": {
               "regex": "(^|.*\\|)vte7($|\\|.*)"
              }
             }
            }
           ]
          },
          "route": {
           "cluster": "outbound|31011||foo.bar.svc.cluster.local",
           "timeout": "0s",
           "retry_policy": {
            "retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
            "num_retries": 2,
            "retry_host_predicate": [
             {
              "name": "envoy.retry_host_predicates.previous_hosts",
              "typed_config": {
               "@type": "type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate"
              }
             }
            ],
            "host_selection_retry_max_attempts": "5",
            "retriable_status_codes": [
             503
            ]
           },
           "max_grpc_timeout": "0s",
           "host_rewrite_header": "x-envoy-original-host"
          },
          "metadata": {
           "filter_metadata": {
            "istio": {
             "config": "/apis/networking.istio.io/v1alpha3/namespaces/default/virtual-service/foo"
            }
           }
          },
          "decorator": {
           "operation": "foo.bar.svc.cluster.local:31011/*"
          }
         },
         {
          "match": {
           "prefix": "/",
           "case_sensitive": true,
           "headers": [
            {
             "name": "x-service-tag",
             "string_match": {
              "exact": "fast"
             }
            },
            {
             "name": "x-service-tag-preference",
             "string_match": {
              "safe_regex": {
               "regex": "(^|.*\\|)vte7($|\\|.*)"
              }
             }
            }
           ]
          },
          "route": {
           "cluster": "outbound|31011||foo.bar.svc.cluster.local",
           "timeout": "0s",
           "retry_policy": {
            "retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
            "num_retries": 2,
            "retry_host_predicate": [
             {
              "name": "envoy.retry_host_predicates.previous_hosts",
              "typed_config": {
               "@type": "type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate"
              }
             }
            ],
            "host_selection_retry_max_attempts": "5",
            "retriable_status_codes": [
             503
            ]
           },
           "max_grpc_timeout": "0s",
           "host_rewrite_header": "x-envoy-original-host"
          },
          "metadata": {
           "filter_metadata": {
            "istio": {
             "config": "/apis/networking.istio.io/v1alpha3/namespaces/default/virtual-service/foo"
            }
           }
          },
          "decorator": {
           "operation": "foo.bar.svc.cluster.local:31011/*"
          }
         },
         {
          "match": {
           "prefix": "/",
           "case_sensitive": true,
           "headers": [
            {
             "name": "x-service-tag",
             "string_match": {
              "exact": "vte7"
             }
            },
            {
             "name": "x-service-tag-preference",
             "string_match": {
              "safe_regex": {
               "regex": "(^|.*\\|)vte7($|\\|.*)"
              }
             }
            }
           ]
          },
          "route": {
           "cluster": "outbound|31011||foo.bar.svc.cluster.local",
           "timeout": "0s",
           "retry_policy": {
            "retry_on": "connect-failure,refused-stream,unavailable,cancelled,retriable-status-codes",
            "num_retries": 2,
            "retry_host_predicate": [
             {
              "name": "envoy.retry_host_predicates.previous_hosts",
              "typed_config": {
               "@type": "type.googleapis.com/envoy.extensions.retry.host.previous_hosts.v3.PreviousHostsPredicate"
              }
             }
            ],
            "host_selection_retry_max_attempts": "5",
            "retriable_status_codes": [
             503
            ]
           },
           "max_grpc_timeout": "0s",
           "host_rewrite_header": "x-envoy-original-host"
          },
          "metadata": {
           "filter_metadata": {
            "istio": {
             "config": "/apis/networking.istio.io/v1alpha3/namespaces/default/virtual-service/foo"
            }
           }
          },
          "decorator": {
           "operation": "foo.bar.svc.cluster.local:31011/*"
          }
         },
@Ferdudas97 Ferdudas97 added enhancement Feature requests. Not bugs or questions. triage Issue requires triage labels Jun 24, 2024
@mattklein123 mattklein123 added area/http and removed enhancement Feature requests. Not bugs or questions. triage Issue requires triage labels Jun 25, 2024
@mattklein123
Copy link
Member

cc @ravenblackx @kyessenov I'm not sure the current state of the art of enhanced matching but would that help here in any way?

@ravenblackx
Copy link
Contributor

I think a MatcherTree can help with this, but it's a bit tricky to generate because at the base level you ~must have prefix/exact path matches for the tree, and some routes may want to e.g. use a regular expression for the path, which means you have to roll all those ones into a sub-matcher on the "no match" branch of the base tree.

There is definitely or_matcher in the Predicate message, so it should be feasible to do the sort of matching that's needed (and I guess you don't have to use a MatcherTree at the base, a MatcherList should more closely mimic the pre-tree behavior while still allowing custom predicates.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants