You need to enable JavaScript to run this app. Envoy本地限流中rate limit descriptors使用及配置不生效排查
优惠活动
大模型
产品
解决方案
定价
更多

Envoy本地限流中rate limit descriptors使用及配置不生效排查

问题根因&修复方案

你配置的local descriptor不生效是两个配置错误共同导致的:

  1. request_headers字段缩进错误
    原配置中header_name、descriptor_key和request_headers平级,不属于request_headers的子字段,Envoy无法正确解析生成对应descriptor,导致没有符合匹配规则的条目,只能走默认限流规则。
  2. 未显式开启descriptor匹配开关
    Local Rate Limit过滤器默认关闭descriptor匹配逻辑,需要添加enable_descriptors: true配置项才会触发自定义descriptor的匹配校验。

修正后配置片段

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:
          # 修正缩进,header_name作为request_headers的子字段
          - 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
          # 新增:开启descriptor匹配
          enable_descriptors: true
          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

验证方法

修改配置重启Envoy后,连续请求curl -v localhost:8080/service/1/foo/bar,第二次请求就会返回429状态码,符合预期。

内容的提问来源于stack exchange,提问作者alexfv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.18 19:54:04