Comments (9)
Hello @denapucaco, thanks for getting in touch, we will get back to you asap! If you have issues in the 1.x.x.RELEASE
line we recommend you to update to the latest version, unfortunately this line is not supported anymore.
from spring-cloud-zuul-ratelimit.
The configuration you added to the description looks odd to me. Are you using it exactly the way you described? I'm talking about the full configuration not just the url_pattern
from spring-cloud-zuul-ratelimit.
@marcosbarbero Thanks for your reply.
Below is the zuul config for service we are trying to add rate limiting. Please let me know if I am missing anything for url-pattern.
zuul:
routes:
audit-api:
path: /gw/audit/**
serviceId: audit-api-ms
stripPrefix: true
retryable: true
ratelimit:
enabled: true
repository: JPA
policy-list: # Zuul rate limit policy list
audit-api: # custom policy name
- limit: 2 # request number limit per refresh interval window
refresh-interval: 60 # in seconds
type:
- user
- url_pattern=/api/v1.0.0/audit/*
audit-api-ms:
ribbon:
listOfServers: ${SERVER_LIST_AUDIT}
ServerListRefreshInterval: 3600000
When I just use the url without value then rate table has below rows after I try few endpoints, so it rate limiting is working for all the urls if no url or url_pattern is mentioned in type. But we want it for just few urls
mi-gateway:audit-api:lossmgr:/api/v1.0.0/audit/statuscode/IPG -1 57011 2021-08-16 16:03:57
mi-gateway:audit-api:lossmgr:/api/v1.0.0/audit/statuscode/COM -1 57419 2021-08-16 16:04:06
mi-gateway:audit-api:lossmgr:/api/v1.0.0/audit/statuscode/WAT -1 30756 2021-08-16 16:03:22
Thanks you
from spring-cloud-zuul-ratelimit.
I see, I'm not on my computer now but I suspect the serviceId being different than the uri is causing the problem.
Can you try to use audit-api-ms on the policy-list?
If it works then we have a bug
from spring-cloud-zuul-ratelimit.
Sure, I'll try and get back to you.
Thanks
Prashant
from spring-cloud-zuul-ratelimit.
@marcosbarbero As per your suggestion tried with audit-api-ms in the policy-list. This didn't solve the issue.
I tried to debug the code to understand what could be causing the issue with url_pattern
and found that -
com.marcosbarbero.cloud.autoconfigure.zuul.ratelimit.filters.AbstractRateLimitFilter
Class ; policy
method
policies = properties.getPolicies(routeId).stream()
.filter(policy -> applyPolicy(request, route, policy))
.collect(Collectors.toList());
When used the url_pattern
the above code returns the empty list. I think because of this rate limiting is not working with url_pattern
I tried with url
again and this time I could make it work with below config
ratelimit:
enabled: true
repository: JPA
policy-list: # Zuul rate limit policy list
audit-api: # custom policy name
- limit: 2 # request number limit per refresh interval window
refresh-interval: 60 # in seconds
type:
- user
- url=/api/v1.0.0/audit/statuscode/INP
- limit: 1 # request number limit per refresh interval window
refresh-interval: 60 # in seconds
type:
- user
- url=/api/v1.0.0/audit/statuscode/COM
- limit: 3 # request number limit per refresh interval window
refresh-interval: 60 # in seconds
type:
- user
- url=/api/v1.0.0/audit/statuscode/WAT
This created below rows in rate table. The URL is added twice in the rate_key. Is this a normal behavior?
mi-gateway:audit-api:lossmmgr:/api/v1.0.0/audit/statuscode/INP:/api/v1.0.0/audit/statuscode/INP -1 48423 2021-08-17 16:51:25
mi-gateway:audit-api:lossmmgr:/api/v1.0.0/audit/statuscode/COM:/api/v1.0.0/audit/statuscode/COM -1 43007 2021-08-17 16:51:42
mi-gateway:audit-api:lossmmgr:/api/v1.0.0/audit/statuscode/WAT:/api/v1.0.0/audit/statuscode/WAT -1 55993 2021-08-17 16:54:41
For now we want to use rate limiting with few URLs but we would like to make the url_pattern
work. If you have any suggestions please let me know
Thanks,
Prashant
from spring-cloud-zuul-ratelimit.
Thanks for the detailed response.
Can you try using **
instead of *
?
from spring-cloud-zuul-ratelimit.
I think I have tried it already but will try it one more time tomorrow and will update you.
from spring-cloud-zuul-ratelimit.
@marcosbarbero Thank you for your help, I am able to make it work with url_pattern
I had to debug the code to understand the issue.
The request.getRequestURI()
in the apply
method of URL_PATTERN
in RateLimitType
class contains the URI with the path /gw/audit/
. Since we are using the stripPrefix: true
I was not adding this path in the url_pattern
. ( url
worked fine without this path )
Along with the path addition had to use **
as the AntPathMatcher
uses them. I have added the config that worked for me below.
/**
* Rate limit policy considering an URL Pattern
*/
URL_PATTERN {
@Override
public boolean apply(HttpServletRequest request, Route route, RateLimitUtils rateLimitUtils, String matcher) {
return new AntPathMatcher().match(matcher.toLowerCase(), request.getRequestURI().toLowerCase());
}
Working Config
zuul:
routes:
audit-api:
path: /gw/audit/**
serviceId: audit-api-ms
stripPrefix: true
retryable: true
ratelimit:
enabled: true
repository: JPA
policy-list: # Zuul rate limit policy list
audit-api: # custom policy name
- limit: 2 # request number limit per refresh interval window
refresh-interval: 60 # in seconds
type:
- user
- url_pattern=/gw/audit/api/v1.0.0/audit/**
- http_method=get
from spring-cloud-zuul-ratelimit.
Related Issues (20)
- Rate Limit for List of Users HOT 4
- JDK 8 compatibility HOT 6
- Rate Limit by multiple types : Origin and HTTP_HEADER HOT 1
- url_pattern in v.2.42.0 HOT 2
- Consul repository not working with URL_PATTERN HOT 2
- Fix Travis-CI Integration
- High Performance degradation happen because of method synchronization HOT 3
- How do you pass REDIS configs for REDIS based ratelimit HOT 8
- URL Pattern key HOT 2
- Working example using bucket4j HOT 8
- Migrate from Travis CI to Circle CI HOT 1
- Visibility on the usage of Log4j HOT 1
- Recent Spring Boot Support? HOT 2
- General Question for better understanding HOT 10
- Configuration "zuul.ratelimit.enable=false" failed to start the service HOT 3
- Rate Limited consistently though refresh interval is crossed HOT 13
- Query regarding MatchType And breakOnMatch HOT 11
- How can set the zuul ratelimit filter for group of users other than the user with name xxxx HOT 2
- Not able to make policy with url_pattern HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-cloud-zuul-ratelimit.