-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edge Limiting is sharing the hits across windows #1406
Comments
I did reproduce the issue with the attached configuration import json
import requests
from sys import exit
url = 'http://localhost:8080/{}-endpoint?user_key=foo'
results = {}
# Hit both endpoints 21 times, print the aggregated number
# of hits allowed (200) and rejected (429)
for i in range(21):
for endpoint in ['first', 'second']:
r = requests.get(url.format(endpoint))
if endpoint not in results:
results[endpoint] = {}
if r.status_code not in results[endpoint]:
results[endpoint][r.status_code] = 0
results[endpoint][r.status_code] += 1
print(json.dumps(results, indent=2))
if results['first'][200] != 10 and results['second'][200] != 20:
print("Test FAILED")
exit(1)
else:
print("Test PASSED")
exit(0) Launching with:
Looking at the code at https://github.com/3scale/lua-resty-limit-traffic/blob/count-increments/lib/resty/limit/count.lua#L47 it looks like for a certain key there is a common count incremented, even when the limits for each path are different. The key is jwc.sub (the subscriber id) which is effectively the same for the same session. If we use a different key for each path, as in
This comment mentions the flexibility of using different limits on the same key (for example on different paths or for different groups of users). IMHO, this may be a feature, as using the same key for both paths makes it a single window limiter, even if each path has a different limit. |
@odkq The behavior is expected. It's especially useful when you have multiple gateways. When using openresty shdict, the limit is applied per gateway so depending on where the request is routed to, the user may exceed the limit. So when used with redis and sharing the same key, the limit is shared across gateways. |
So this are limits per user, not to avoid call congestion (which may be configured using other nginx/openresty mechanism?) so sharing the hit count between gateways makes all sense. Thank you @tkan145 ! |
I have configured the edge limiting policy (Fixed window limiters) for a service that has 2 Rest APIs and each has a different rate limit configured. But while hitting the first API the limit is getting affected for both the APIs.
Version: 3.8.0
Steps To Reproduce
Current Result
The 6th hit of the
first-endpoint
fails and gives429 too many requests
and the 16th hit of thesecond-endpoint
fails and gives429 too many requests
.Expected Result
The 11th hit of the
first-endpoint
should fail and give429 too many requests
and the 21st hit of thesecond-endpoint
should fail and give429 too many requests
Limit reducing pattern
The text was updated successfully, but these errors were encountered: