spring-cloud / spring-cloud-circuitbreaker

Spring Cloud Circuit Breaker API and Implementations
Apache License 2.0
336 stars 110 forks source link

spring cloud gateway resilience4j rate limiter not working #153

Closed BaekSeungYeol closed 1 year ago

BaekSeungYeol commented 2 years ago

Describe the bug spring cloud gateway resilience4j rate limiter is not working. if i'm wrong please tell me.

Sample this is my code.

resilience4j:
  ratelimiter:
    instances:
      testCircuitBreaker:
        limitForPeriod: 1
        limitRefreshPeriod: 60s
        timeoutDuration: 1s
        registerHealthIndicator: true

i defined rate limiter in .yml file. and added to gateway routes like this

    gateway:
      routes:
        - id: sample-limit
          uri: http://localhost:8080
          predicates:
            - Path=/test
          filters:
            - name: CircuitBreaker
              args:
                name: testCircuitBreaker
                fallbackUri: forward:/rateLimitFallback

I tried sending a request through postman, but there was no limit on the request. I changed the rateLimiter to timeLimiter and gave timeoutDuration like this.

resilience4j:
  timelimiter:
    instances:
      testCircuitBreaker:
        timeoutDuration: 1s

and it worked fine, but I don't know why ratelimiter doesn't work.

ryanjbaxter commented 2 years ago

Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

BaekSeungYeol commented 2 years ago

@ryanjbaxter hi, i added a demo project link. it briefly reproduce the situation of sending a request to a demo-backend server through a demo-gateway.

demo : https://github.com/BaekSeungYeol/demo-ratelimiter-sample

As stated in the README, If i run demo-gateway, demo-backend-server and send a localhost:8080/test2 request, the response is not what I expected. isn't it correct that an error occurs due to the rate limiter that is allowed once in 60 seconds? If i'm wrong, please tell me, thank you.

ryanjbaxter commented 2 years ago

This doesn't work because we are not configuring the RateLimiter and applying it in Spring Cloud CircuitBreaker. Frankly RateLimiting is a bit separate from Circuit Breakers. In this particular case I would suggest you look into the Rate Limiter provided by Spring Cloud Gateway

spring-cloud-issues commented 2 years ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues commented 2 years ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.