【问题标题】:How to use rate limit descriptors for local rate limiting in Envoy?如何在 Envoy 中使用速率限制描述符进行本地速率限制?
【发布时间】:2021-05-25 20:20:39
【问题描述】:

我正在尝试将 local rate limit filter 添加到 front-proxy 示例。默认令牌桶按预期工作,但本地描述符的令牌桶没有。

这是我对front-envoy.yamlroute_config 更改:

route_config:
  name: local_route
  virtual_hosts:
  - name: backend
    domains:
    - "*"
    routes:
    - match:
        prefix: "/service/2"
      route:
        cluster: service2
    - match:
        prefix: "/service/1"
      route:
        cluster: service1
        rate_limits:
        - actions:
          # https://www.envoyproxy.io/docs/envoy/v1.18.2/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-ratelimit-action-requestheaders
          - request_headers:
            header_name: ":path"
            descriptor_key: path

      typed_per_filter_config:
        envoy.filters.http.local_ratelimit:
          "@type": type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit
          stat_prefix: http_local_rate_limiter

          # if there is no matching descriptor entries, the default token bucket is used
          token_bucket:
            max_tokens: 3
            tokens_per_fill: 3
            fill_interval: 60s

          filter_enabled:
            default_value:
              numerator: 100
              denominator: HUNDRED
          filter_enforced:
            default_value:
              numerator: 100
              denominator: HUNDRED
          descriptors:
          - entries:
            - key: path
              value: /service/1/foo/bar
            token_bucket:
              max_tokens: 1
              tokens_per_fill: 1
              fill_interval: 60s


我发送了 4 次 curl -v localhost:8080/service/1/foo/bar 并期望在第二个请求上得到 429 响应,以匹配本地描述符。

但我在第 4 次尝试时才收到 429 响应:没有匹配的描述符条目,使用默认令牌桶。

【问题讨论】:

  • 可能是错字。但似乎描述符内的缩进不正确。理想情况下应该是:描述符:-条目:-键:路径值:/service/1/foo/bar token_bucket:max_tokens:1 tokens_per_fill:1 fill_interval:60s

标签: envoyproxy


【解决方案1】:

看起来是缩进问题:

          descriptors:
            - entries:
              - key: path
                value: /service/1/foo/bar
              token_bucket:
                max_tokens: 1
                tokens_per_fill: 1
                fill_interval: 60s

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多