question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RateLimiter is not working

See original GitHub issue

Apart from redis connection, do we have to do anything else for a basic rate limiter to work? As I’ve been trying to create a rate limiter but it is not working as it is supposed to.

Rate limiter : RedisRateLimiter redisRateLimiter() { return new RedisRateLimiter(1, 2); }

Portion of my route: .route("redis_rate_check", r->r.path("/redisrate") .and().method(HttpMethod.GET) .filters(f -> f.requestRateLimiter(rate -> rate .setRateLimiter(redisRateLimiter())) ) .uri("http://localhost:9081/rate"))

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mathieufortin01commented, Jun 8, 2018

@jayendra155 never tested using code configuration, but I guess you need a KeyResolver somewhere. I think the default one limits based on the Principal authentified. Maybe that is your problem.

@stevenNzonzi Rate limiter configuration doesnt work using shortcut form (see #167 ). Here is 2 working configuration:

Using a rate limiter bean:

filters:
- name: RequestRateLimiter
  args:
    key-resolver: "#{@myKeyResolver}"
    rate-limiter: "#{@myRateLimiter}"

Hardcoding the configuration:

filters:
- name: RequestRateLimiter
  args:
    key-resolver: "#{@myKeyResolver}"
    redis-rate-limiter.replenishRate: 1
    redis-rate-limiter.burstCapacity: 5
2reactions
stevenNzonzicommented, Jun 5, 2018

I would like to know that too, whenever I use the rate limiter, my test endpoint returns a blank body with a 200 ok. This is the bean that I created, nothing special,

@Bean
KeyResolver testKeyResolver() {
    return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("test"));
}

And this is my config file,

spring:
  cloud:
    gateway:
      routes:
      - id: redirectRoute
        uri: http://localhost:9081/getname
        predicates:
        - Path=/path
        filters:
        - RequestRateLimiter=100, 100, #{@testKeyResolver}
      - id: HeaderMatching
        uri: http://localhost:9080/world
        predicates:
        - Path=/header
        - Header=X-Request-Id, \d+
      - id: HystrixExample
        uri: http://localhost:9081/getname
        predicates:
        - Path=/checkfallback
        filters:
        - name: Hystrix
          args:
            name: fallbackcmd
            fallbackUri: forward:/world
      - id: MethodMatching
        uri: http://localhost:9080/world
        predicates:
        - Path=/post
        - Method=POST

This is the log I get in DEBUG mode

2018-06-05 17:10:03:364PM DEBUG [reactor-http-server-epoll-7] [o.s.c.g.h.RoutePredicateHandlerMapping] Mapping [Exchange: GET http://localhost:9080/path] to Route{id='redirectRoute', uri=http://localhost:9081/getname, order=0, predicate=org.springframework.cloud.gateway.handler.predicate.PathRoutePredicateFactory$$Lambda$669/388424292@65a2dc58, gatewayFilters=[OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RequestRateLimiterGatewayFilterFactory$$Lambda$671/1128014181@3d34d98d, order=1}]}
2018-06-05 17:10:03:365PM DEBUG [reactor-http-server-epoll-7] [o.s.c.g.handler.FilteringWebHandler] Sorted gatewayFilterFactories: [OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@698d6d30}, order=-1}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardPathFilter@538b3c88}, order=0}, OrderedGatewayFilter{delegate=org.springframework.cloud.gateway.filter.factory.RequestRateLimiterGatewayFilterFactory$$Lambda$671/1128014181@3d34d98d, order=1}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@3407aa4f}, order=10000}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@78065fcd}, order=2147483637}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@19b9f903}, order=2147483646}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyRoutingFilter@13aed42b}, order=2147483647}, OrderedGatewayFilter{delegate=GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardRoutingFilter@51ed2f68}, order=2147483647}]
2018-06-05 17:10:03:367PM DEBUG [reactor-http-server-epoll-7] [o.s.h.s.r.ReactorHttpHandlerAdapter] Handling completed with success
Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel 8 rate limiter not working for routes - Stack Overflow
Since Laravel 8 you can configure rate limits in the method configureRateLimiting() of the App\Providers\RouteServiceProvider . For example:
Read more >
Rate limiter is not working (at least in test) - Laracasts
I've defined a rate limiter to throttle the number of requests a user can send each time and now I'm trying to test...
Read more >
RateLimiter not working with Spring · Issue #1315 - GitHub
I have a project where the goal is to read records from a database, manipulate those records, and then insert them into another...
Read more >
RateLimiter with 1 permitsPerSecond does not appear to work ...
My use case is that I create the single RateLimiter instance in a static context and that instance is passed to all callers...
Read more >
RateLimiter (Guava: Google Core Libraries for Java 19.0 API)
The returned RateLimiter ensures that on average no more than permitsPerSecond are issued during any given second, with sustained requests being smoothly spread ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found