0

我有一个端点的 krakend 配置,如下所示

        {
            "endpoint": "/api/login",
            "method": "POST",
            "output_encoding": "no-op",
            "headers_to_pass": [
              "*"
            ],
            "backend": [
                {
                    "encoding": "no-op",
                    "host": [ "http://login-service:80" ],
                    "url_pattern": "/api/login",
                    "method": "POST",
            "extra_config": {
      "github.com/devopsfaith/krakend-ratelimit/juju/router": {
          "maxRate": 2,
          "capacity": 2,
          "clientMaxRate": 1,
          "strategy": "header",
          "key": "x-real-ip"
      }
      }
                }
            ]
        }



我按照这些链接形成了配置 https://www.krakend.io/docs/backends/rate-limit/ https://www.krakend.io/docs/endpoints/rate-limit/

但问题是我没有看到配置工作。对于上述配置,每秒允许的最大请求数为 2,但是,端点每秒接受超过 2 个请求而不会显示任何错误消息。根据文档,如果触发限制的人达到了 maxRate 限制,它应该显示 503 Service Unavailable。

4

1 回答 1

0

看起来您的额外配置放错了位置。路由器速率限制进入端点内部,而不是后端。用这个:

{
    "endpoint": "/api/login",
    "method": "POST",
    "output_encoding": "no-op",
    "headers_to_pass": [
        "*"
    ],
    "extra_config": {
        "github.com/devopsfaith/krakend-ratelimit/juju/router": {
            "maxRate": 2,
            "capacity": 2,
            "clientMaxRate": 1,
            "strategy": "header",
            "key": "x-real-ip"
        }
    },
    "backend": [
        {
            "encoding": "no-op",
            "host": [
                "http://login-service:80"
            ],
            "url_pattern": "/api/login",
            "method": "POST"
        }
    ]
}
于 2021-12-21T08:25:39.060 回答