marcosbarbero / spring-cloud-zuul-ratelimit

Rate limit auto-configure for Spring Cloud Netflix Zuul

Home Page:https://blog.marcosbarbero.com/spring-cloud-netflix-zuul-rate-limit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rate Limited consistently though refresh interval is crossed

akshaydk-buku opened this issue · comments

Hello Team,

It looks like for some reason am getting 429 for every request post exceeding a certain threshold that i've set.
Below is my configuration defined in app.properties

zuul.ratelimit.behind-proxy=false
zuul.ratelimit.enabled=true
zuul.ratelimit.key-prefix=buku12
zuul.ratelimit.repository=REDIS
zuul.ratelimit.response-headers=verbose

zuul.ratelimit.policy-list.notification-demo-service[0].limit=2000
zuul.ratelimit.policy-list.notification-demo-service[0].quota=15000s
zuul.ratelimit.policy-list.notification-demo-service[0].refresh-interval=2s
zuul.ratelimit.policy-list.notification-demo-service[0].type[0]=origin

What am assuming is if within 2secs I exceed 2000 requests, then i get rate limited till we cross 2second window.
But what am seeing it am getting rate limited ever after once I cross the 2000req/2sec cap.
There is no default policy set. Am using Redis as my storage.

Am using JMeter to issue to requests to my gateway.
Why am i seeing this inconsistency? Am I missing something?

Please suggest!

Thanks,
Akshay

Upon further debugging, looks like these keys[attached screenshot take from a REDIS memory UI viewer] in REDIS memory are never expired after a while or in other terms they are never reset. Because of which I get rate limited every time after performing some load test on rate limit defined endpoints. Though have set TTL of REDIS cluster to 1minute, this behaviour seems to persist every time. In which case I had to manually delete the keys from REDIS memory in order to bring back the regular flow.

Below is my redis confg of local
redis.cluster.enabled=false
redis.node.addresses=redis://127.0.0.1:6379
redis.password=
redis.ttl.duration=1m
Screenshot 2022-04-19 at 10 11 40 AM

Please help me understand why this is happening!

Can you tell me which version you are using for these?

  • Spring Boot
  • Spring Cloud
  • Spring Cloud Zuul Rate Limit

Spring Boot => 2.3.5.RELEASE
Spring Boot Cloud Starter Netflix Zuul => 2.2.6.RELEASE
Spring Cloud Zuul Rate Limit => 2.4.0.RELEASE

I'm sorry @akshaydk-buku. Can you tell me what Spring Cloud's release train version is?

We are not using Spring Cloud if you're referring to this
https://spring.io/projects/spring-cloud
We're relying on AWS Infra for Service Discovery/Registration, Load Balancing etc

Ok, we need to clarify this so we are on the same page.

This project works with Spring Cloud Netflix Zuul. To use it, you need to specify a Spring Cloud - Spring Boot compatible version.

If you're importing Spring Cloud Netflix Zuul using a random version without using the release train managed dependencies, I don't think I can help you that much. I don't know the compatibility of that one version with everything else.

Do you understand what I'm saying?

I see.

This is how my dependencies look like currently, taken from build.gradle

implementation 'org.springframework.boot:spring-boot-starter-web:2.3.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.3.5.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-zuul:2.2.6.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-data-redis:2.3.4.RELEASE'
implementation 'org.redisson:redisson:3.16.8'
implementation ('org.redisson:redisson-spring-data-24:3.16.8') {
    exclude group: 'org.springframework.data', module: 'spring-data-redis'
}
implementation ('net.javacrumbs.shedlock:shedlock-spring:4.23.0') {
    exclude group: 'org.springframework', module: 'spring-context'
}
implementation ('net.javacrumbs.shedlock:shedlock-provider-redis-spring:4.23.0') {
    exclude group: 'org.springframework.data', module: 'spring-data-redis'
}
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.1'
implementation 'com.marcosbarbero.cloud:spring-cloud-zuul-ratelimit:2.4.0.RELEASE'

We don't possess any dependency management (Spring Cloud) tool as of now.
I believe you're expecting something like below

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

ext {
	set('springCloudVersion', "2021.0.1")
}

This is actually a legacy project. Any workaround suggestions with the current design? Thanks!

Ok, let's assume the versions are compatible.

Can you tell me why you have a 1 minute TTL set on your Redis?

That was just a trail. I've tried with 5secs, 3secs & 10secs TTL. The behaviour was still the same!

Let me rephrase the question. Why do you have a TTL set?

Just to be on the safer side. Since this is the gateway we're dealing with, we don't want too many keys to get accumulated at Redis cluster(I believe every policy we define will have two keys associated with it as seen in the above screenshot) thereby flooding the memory. Thus the TTL

Hi, @akshaydk-buku. I'm having a hard time reproducing the behavior that you're reporting. Can you share in a public repo an application recreating the issue?

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 1 day