-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Version: 3.0.2
I'm now trying to configure RequestRateLimiterGatewayFilterFactory with RedisRateLimiter for my services.
But for different endpoints, we want to set different replenishRate and burstCapacity.
Then I looked into the implementation, I found it might not work for multiple routes.
For example, with the following route configuration, route-1 and route-2 use RedisRateLimiter but with different replenishRate and burstCapacity :
spring:
cloud:
gateway:
routes:
- id: route-1
uri: https://example1.org
filters:
- name: RequestRateLimiter
args:
redis-rate-limiter.replenishRate: 1
redis-rate-limiter.burstCapacity: 2
redis-rate-limiter.requestedTokens: 1
- id: route-2
uri: https://example2.org
filters:
- name: RequestRateLimiter
args:
redis-rate-limiter.replenishRate: 10
redis-rate-limiter.burstCapacity: 20
redis-rate-limiter.requestedTokens: 1
Assuming we are using the default KeyResolver, which using the principal to identify the request.
I found this part of code that get keys of Redis.
It only uses id (principal in this case) to form the Redis key.
Then, for both route-1 and route-2, RedisRateLimiter will get request_rate_limiter.{id}.tokens from Redis to calculate (here)
Seems the tokens will be messed up when the same principal hitting both route-1 and route-2 endpoints.
My questions are:
- Is this behavior by design?
- If no, maybe it should be fixed to use both id (provided by
KeyResolver) and Route ID? like"request_rate_limiter.{user1_route1}.tokens - If yes, do you have advice on how we handle the situation when we want to configure multiple routes with RedisRateLimiter?
(maybe a customKeyResolverto resolve both principal and routeid?)