Need Help Understanding Rate Limit Inconsistency When Exceeding Limits

20 views
Skip to first unread message

hrai

unread,
May 29, 2024, 3:48:08 AMMay 29
to KrakenD Community
I'm facing an issue with rate limiting in my KrakenD configuration. Here's a snippet of how I've set it up:
```
{
  "$schema": "https://www.krakend.io/schema/krakend.json",
  "version": 3,
  "name": "KrakenD - API Gateway",
  "timeout": "3000ms",
  "port": 8080,
  "output_encoding": "no-op",
  "extra_config": {
    "router": {
      "return_error_msg": true
    }
  },
  "endpoints": [
    {
      "endpoint": "/api/posts",
      "method": "GET",
      "extra_config": {
        "security/cors": {
          "allow_origins": ["*"],
          "allow_methods": ["GET", "HEAD", "POST"],
          "expose_headers": ["Content-Length", "Content-Type"],
          "allow_headers": ["Accept-Language"],
          "max_age": "12h",
          "allow_credentials": false,
          "debug": false
        },
        "github.com/devopsfaith/krakend-ratelimit/juju/router": {
          "max_rate": 2,
          "client_max_rate": 1,
          "strategy": "ip"
        }
      },
      "backend": [
        {
          "url_pattern": "/posts",
          "method": "GET",
          "host": [
            "https://jsonplaceholder.typicode.com"
          ]
        }
      ]
    }
  ]
}
```
However, upon checking the logs, I'm noticing "rate limit exceeded" errors, even when the incoming requests appear to be within the configured limits. Can anyone help me understand why this inconsistency is happening, especially when the rate limits are being exceeded?

```
Parsing configuration file: /etc/krakend/krakend.json
2024/05/29 07:34:44 KRAKEND ERROR: [SERVICE: Logging] Unable to create the logger: getting the extra config for the krakend-gologging module
2024/05/29 07:34:44 KRAKEND INFO: Starting the KrakenD instance
2024/05/29 07:34:44 KRAKEND DEBUG: [ENDPOINT: /api/posts] Building the proxy pipe
2024/05/29 07:34:44 KRAKEND DEBUG: [BACKEND: /posts] Building the backend pipe
2024/05/29 07:34:44 KRAKEND DEBUG: [ENDPOINT: /api/posts] Building the http handler
2024/05/29 07:34:44 KRAKEND DEBUG: [ENDPOINT: /api/posts][JWTSigner] Signer disabled
2024/05/29 07:34:44 KRAKEND DEBUG: [ENDPOINT: /api/posts][Ratelimit] Rate limit enabled
2024/05/29 07:34:44 KRAKEND DEBUG: [ENDPOINT: /api/posts][Ratelimit] IP-based rate limit enabled
2024/05/29 07:34:44 KRAKEND INFO: [ENDPOINT: /api/posts][JWTValidator] Validator disabled for this endpoint
2024/05/29 07:34:44 KRAKEND INFO: [SERVICE: Gin] Listening on port: 8080
2024/05/29 07:34:49 KRAKEND DEBUG: [SERVICE: Telemetry] Registering usage stats for Cluster ID MGIbF1Je7g+xT9yvmNdzCj61q3OpwWAx5t/Uklxp4Vs=
[GIN] 2024/05/29 - 07:34:51 | 200 |   50.371776ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:34:52 | 200 |   11.731188ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:34:53 | 200 |   11.797469ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:34:54 | 200 |   12.416988ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:34:55 | 200 |   11.882631ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:34:56 | 200 |   12.026061ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:34:57 | 200 |   10.776836ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:34:58 | 429 |        7.25µs |     192.168.2.6 | GET      "/api/posts"
Error #01: rate limit exceded
[GIN] 2024/05/29 - 07:34:58 | 200 |   10.904887ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:34:59 | 200 |   12.250655ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:00 | 200 |   13.130887ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:01 | 200 |   11.797482ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:02 | 429 |       6.807µs |     192.168.2.6 | GET      "/api/posts"
Error #01: rate limit exceded
[GIN] 2024/05/29 - 07:35:03 | 200 |   12.195662ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:03 | 200 |   12.680235ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:04 | 200 |    10.35999ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:05 | 429 |      11.302µs |     192.168.2.6 | GET      "/api/posts"
Error #01: rate limit exceded
[GIN] 2024/05/29 - 07:35:06 | 200 |   12.885605ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:06 | 200 |   13.608264ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:07 | 200 |   10.376501ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:08 | 200 |   12.344512ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:09 | 200 |   11.644459ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:10 | 429 |       7.357µs |     192.168.2.6 | GET      "/api/posts"
Error #01: rate limit exceded
[GIN] 2024/05/29 - 07:35:10 | 200 |   11.332519ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:11 | 200 |     10.9152ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:13 | 200 |   13.738431ms |     192.168.2.6 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:38 | 200 |  588.561106ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:40 | 200 |   11.986087ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:40 | 429 |       7.337µs |      172.17.0.1 | GET      "/api/posts"
Error #01: rate limit exceded
[GIN] 2024/05/29 - 07:35:41 | 200 |   11.449192ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:42 | 200 |   16.851826ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:43 | 200 |   11.374515ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:44 | 200 |   11.539758ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:45 | 200 |   11.784806ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:46 | 200 |   11.953895ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:46 | 429 |       7.525µs |      172.17.0.1 | GET      "/api/posts"
Error #01: rate limit exceded
[GIN] 2024/05/29 - 07:35:58 | 200 |   14.045308ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:35:59 | 200 |   10.498823ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:36:00 | 200 |    11.38414ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:36:01 | 200 |   12.402406ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:36:02 | 200 |   11.436349ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:36:03 | 200 |   12.319664ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:36:04 | 200 |   17.816982ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:36:05 | 200 |   12.669939ms |      172.17.0.1 | GET      "/api/posts"
[GIN] 2024/05/29 - 07:36:05 | 429 |       7.585µs |      172.17.0.1 | GET      "/api/posts"
Error #01: rate limit exceded
```
Reply all
Reply to author
Forward
0 new messages