Comments (3)
I did reproduce the issue with the attached configuration
edge-limiting-1406.json
and the test program:
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:
$ docker run -d --publish 8080:8080 --rm --volume $(pwd)/edge-limiting-1406.json:/edge-limiting-1406.json --env THREESCALE_CONFIG_FILE=/edge-limiting-1406.json quay.io/3scale/apicast:latest
f15b7bb4f1bf6a50877b5cc38f2480a3b2f7bef63497f1fdd09ce0ef1d646f95
$ ./test.py
{
"first": {
"200": 5,
"429": 16
},
"second": {
"200": 15,
"429": 6
}
}
Test FAILED
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
edge-limiting-1406-differentkeys.json the test passes:
$ docker run -d --publish 8080:8080 --rm --volume $(pwd)/edge-limiting-1406-differentkeys.json:/edge-limiting-1406.json --env THREESCALE_CONFIG_FILE=/edge-limiting-1406.json quay.io/3scale/apicast:latest
3006a2208e5098368009faf66a83e9d8a93b3210d2b1d1b633f0efa01eddc653
$ ./test.py
{
"first": {
"200": 10,
"429": 11
},
"second": {
"200": 20,
"429": 1
}
}
Test PASSED
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.
from apicast.
@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.
from apicast.
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 !
from apicast.
Related Issues (20)
- configuration-loading-boot-without-config.t
- configuration-loading-boot-remote.t
- custom-config.t
- backend.t HOT 1
- resolver.t HOT 2
- balancer.t HOT 1
- apicast-upstream-balancer.t
- management.t
- apicast-mapping-rules.t
- backend-cache-handler.t
- Review and update DNS-resolver doc HOT 5
- Setup local env fails HOT 13
- Retiring the probot-changelog app HOT 1
- Trigger Alert `CoreDNSErrorsHigh` with OpenShift 4.11.9 HOT 2
- Swagger compatibility Issue HOT 5
- GRPC integration tests HOT 1
- OpenTelemetry instrumentation does not use environment variable OTEL_RESOURCE_ATTRIBUTES HOT 1
- Need help with build failure on power HOT 2
- lua-rover issue faced while enabling support for power(ppc64le) architecture HOT 4
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 apicast.