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

EnvoyFilter RateLimit pattern regex not working , need help! #34197

Open
wmashal opened this issue May 16, 2024 · 7 comments
Open

EnvoyFilter RateLimit pattern regex not working , need help! #34197

wmashal opened this issue May 16, 2024 · 7 comments
Labels
area/ratelimit question Questions that are neither investigations, bugs, nor enhancements

Comments

@wmashal
Copy link

wmashal commented May 16, 2024

Hi

I am trying to configure my Global Rate limit in istio using the EnvoyFilter resource to handle a a dynamic URL requests rate limit, my url contains a dynamic UUID in the path so I tried to use regex_value_rewrite pattern but its not working as expected, I expect to have a request count for each unique UUID, and not apply the rate limit on any other paths just if I have the UUID Regex

Example:

lets say we have limit 50 req/minute

/cloudautomation/v1/solutions//spfi/notify called 2 times --- > count1 is 2 out of 50
/cloudautomation/v1/solutions//spfi/notify called 10 times ---> count2 is 10 out of 50

My Configurations

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: ratelimit-envoy-filter
  namespace: istio-system
spec:
  workloadSelector:
    labels:
      istio: ingressgateway
  configPatches:
    - applyTo: HTTP_FILTER
      match:
        context: GATEWAY
        listener:
          filterChain:
            filter:
              name: 'envoy.filters.network.http_connection_manager'
              subFilter:
                name: 'envoy.filters.http.router'
      patch:
        operation: INSERT_BEFORE
        value:
          name: envoy.filters.http.header_to_metadata
          typed_config:
            "@type": type.googleapis.com/envoy.extensions.filters.http.header_to_metadata.v3.Config
            request_rules:
            - header: ':path'
              on_header_present:
                # use an arbitary name for the namespace
                # will be used later to extract descriptor value
                metadata_namespace: spfi
                # use an arbitary key for the metadata
                # will be used later to extract descriptor value
                key: uri
                regex_value_rewrite:
                  pattern:
                    # regex matcher
                    google_re2: {}
                    # truncates parameters from path
                    regex: '^\/cloudautomation\/v1\/solutions\/(.+)\/spfi\/notify$'
                  substitution: '\1'
    - applyTo: HTTP_FILTER
      match:
        context: GATEWAY
        listener:
          filterChain:
            filter:
              name: "envoy.filters.network.http_connection_manager"
              subFilter:
                name: "envoy.filters.http.router"
      patch:
        operation: INSERT_BEFORE
        value:
          name: envoy.filters.http.ratelimit
          typed_config:
            "@type": type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimit
            domain: atom-istio-ratelimit
            failure_mode_deny: false
            timeout: 10s
            rate_limit_service:
              grpc_service:
                envoy_grpc:
                  cluster_name: outbound|8081||ratelimit.istio-system.svc.cluster.local
                  authority: ratelimit.istio-system.svc.cluster.local
              transport_api_version: V3
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: uca-spfi-ratelimit-actions
  namespace: istio-system
spec:
  workloadSelector:
    labels:
      istio: ingressgateway
  configPatches:
  - applyTo: VIRTUAL_HOST
    match:
      context: GATEWAY
      routeConfiguration:
        vhost:
          name: {{ .Values.uca.ingress.appPrefix }}.ingress.{{ .Values.domain }}:443
          route:
            action: ANY
    patch:
      operation: MERGE
      value:
        rate_limits:
        - actions:
          - metadata:
              descriptor_key: SPFI
              metadata_key:
                key: spfi
                path:
                - key: uri

In the rate limit service config I configured

   - key: SPFI
     rate_limit:
       unit: MINUTE
       requests_per_unit: 50

Please Advice ?
Thanks

@wmashal wmashal added the triage Issue requires triage label May 16, 2024
@wmashal wmashal changed the title Envoy RateLimit pattern regex not working , need help! EnvoyFilter RateLimit pattern regex not working , need help! May 16, 2024
@ravenblackx
Copy link
Contributor

ravenblackx commented May 16, 2024

I think substitution: '\1' is telling it to replace the pattern with itself, so making no change. For what you describe it looks like substitution: "" would do what you intended?
Or maybe substitution: "/cloudautomation/v1/solutions//spfi/notify"

@ravenblackx
Copy link
Contributor

Oh, no, I misunderstood, you're aiming to do just the UUID, not to ignore the UUID, so your configuration looks right.

@ravenblackx
Copy link
Contributor

@mattklein123 as ratelimit primary owner.

@ravenblackx ravenblackx added question Questions that are neither investigations, bugs, nor enhancements area/ratelimit and removed triage Issue requires triage labels May 16, 2024
@wmashal
Copy link
Author

wmashal commented May 19, 2024

@mattklein123 can help plz ?

@wmashal
Copy link
Author

wmashal commented May 21, 2024

@ravenblackx u think its a bug ? or no support for such a scenario ?

@ravenblackx
Copy link
Contributor

Not really my area, that's why I tried to ping Matt to look. Maybe @wbpcode might know more, as someone touching rate limit related stuff recently?

@wbpcode
Copy link
Member

wbpcode commented May 22, 2024

so, what is the current behavior? Seems the configuration is fine. It would be better to log the dynamic metadata or check the stats of rate limit server to find what actually happened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ratelimit question Questions that are neither investigations, bugs, nor enhancements
Projects
None yet
Development

No branches or pull requests

3 participants