Skip to content

Commit 337dc9b

Browse files
authored
Add integration test for token based quota (#1092)
Signed-off-by: yavlasov <[email protected]>
1 parent b1603d1 commit 337dc9b

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

examples/envoy/proxy.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,26 @@ static_resources:
176176
- generic_key:
177177
descriptor_value: "service_2"
178178
descriptor_key: "service"
179+
- match:
180+
prefix: /tokenquota
181+
route:
182+
cluster: mock
183+
typed_per_filter_config:
184+
envoy.filters.http.ratelimit:
185+
"@type": type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimitPerRoute
186+
vh_rate_limits: INCLUDE
187+
override_option: INCLUDE_POLICY
188+
rate_limits:
189+
- actions:
190+
- generic_key:
191+
descriptor_value: "service_2"
192+
descriptor_key: "service"
193+
hits_addend:
194+
number: 0
195+
- actions:
196+
- generic_key:
197+
descriptor_value: "service_2"
198+
descriptor_key: "service"
199+
hits_addend:
200+
number: 1
201+
apply_on_stream_done: true
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
#
4+
# request to /tokenquota will produce the (service: service_1), (service: service_2) descriptor
5+
# with 0 addend on request path and (service: service_2) descriptor with addend 1 on response path.
6+
# service_2 has 2 req/min so 2 requests should be allowed
7+
#
8+
9+
response=$(curl -f -s -H "request-no: 1" http://envoy-proxy:8888/tokenquota)
10+
response=$(curl -f -s -H "request-no: 2" http://envoy-proxy:8888/tokenquota)
11+
response=$(curl -f -s -H "request-no: 3" http://envoy-proxy:8888/tokenquota)
12+
13+
if [ $? -ne 0 ]; then
14+
echo "Quota limit should not trigger yet"
15+
exit 1
16+
fi
17+
18+
# Quota is debited from service_2 bucket on the response path so only the 4th request should be rejected
19+
response=$(curl -f -s -H "request-no: 4" http://envoy-proxy:8888/tokenquota)
20+
21+
if [ $? -ne 0 ]; then
22+
echo "Quota mode does not deny requests yet"
23+
exit 1
24+
fi
25+
26+
echo "Waiting 1 minute for quota buckets to be refreshed"
27+
sleep 60
28+
29+
response=$(curl -i -s -H "request-no: 5" http://envoy-proxy:8888/tokenquota)
30+
if [ $? -ne 0 ]; then
31+
echo "Quota bucket should be refreshed"
32+
exit 1
33+
fi

0 commit comments

Comments
 (0)