When configuring the Rate Limiting or Rate Limiting Advanced plugin with a path identifier, what is the expected behavior?
When configuring the Rate Limiting plugin (or Rate Limiting Advanced) with config.identifier=path it means the plugin will have a counter for the path configured and another counter for the paths that don’t match the configured path. For example:
-
Configure a service to
httpbin.org/anything -
Configure 3 routes for that service:
/http1/http2/http3 -
Configure the Rate Limiting plugin at the service level and set:
identifier=path, strategy=local, path=/http1, window_size=[ 60 ], limit=[ 3 ], window_type=fixed
We are configuring 3 requests per minute. This means the plugin will have a counter for the path /http1 and a counter for the other paths (also using fixed window for an easier understanding). Let’s see an example:
-
We are going to send 6 requests within the same window. We can confirm we are in the same window with the header
RateLimit-Reset(RateLimit-Reset:53throughout) -
We are going to send 4 requests to
/http1. The first 3 will respond with a 200 OK and the forth 429 Too Many Requests (noteRateLimit-Remaining:0) -
We are going to send 2 requests more, to
/http2and/http3. We still are in the same window (RateLimit-Reset:53). We see now both requests respond with a 200 OK as they use another counter. Also, you can see they use the same counter, for/http2RateLimit-Remaining:2and for/http3RateLimit-Remaining:1
curl -I http://proxy.kong/http1
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 2
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 2
curl -I http://proxy.kong/http1
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 1
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 1
curl -I http://proxy.kong/http1
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 0
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 0
curl -I http://proxy.kong/http1
HTTP/1.1 429 Too Many Requests
Retry-After: 53
RateLimit-Reset: 53
RateLimit-Remaining: 0
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 0
curl -I http://proxy.kong/http2
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 2
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 2
curl -I http://proxy.kong/http3
HTTP/1.1 200 OK
RateLimit-Reset: 53
RateLimit-Remaining: 1
RateLimit-Limit: 3
X-RateLimit-Limit-minute: 3
X-RateLimit-Remaining-minute: 1Note if we don’t configure any path, the plugin will only accept 3 requests per minute. In this case, it accepts 6 requests per minute:
-
3 for
/http1 -
3 for either
/http2or/http3(or any other path configured)