Skip to content

Commit b1603d1

Browse files
authored
Add quota integration test (#1090)
1 parent ae44ab6 commit b1603d1

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

examples/envoy/proxy.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,21 @@ static_resources:
158158
- request_headers:
159159
header_name: "unspec"
160160
descriptor_key: "unspec"
161+
- match:
162+
prefix: /quota
163+
route:
164+
cluster: mock
165+
typed_per_filter_config:
166+
envoy.filters.http.ratelimit:
167+
"@type": type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimitPerRoute
168+
vh_rate_limits: INCLUDE
169+
override_option: INCLUDE_POLICY
170+
rate_limits:
171+
- actions:
172+
- generic_key:
173+
descriptor_value: "service_1"
174+
descriptor_key: "service"
175+
- actions:
176+
- generic_key:
177+
descriptor_value: "service_2"
178+
descriptor_key: "service"

examples/ratelimit/config/example.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,15 @@ descriptors:
8484
- key: qux
8585
rate_limit:
8686
unlimited: true
87+
- key: service
88+
value: service_1
89+
quota_mode: true
90+
rate_limit:
91+
unit: minute
92+
requests_per_unit: 1
93+
- key: service
94+
value: service_2
95+
quota_mode: true
96+
rate_limit:
97+
unit: minute
98+
requests_per_unit: 2

integration-test/scripts/quota.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
#
4+
# request to /quota will produce the (service: service_1), (service: service_2) descriptor
5+
# service_1 has 1 req/min and service_2 has 2 req/min
6+
#
7+
8+
response=$(curl -f -s http://envoy-proxy:8888/quota)
9+
response=$(curl -f -s http://envoy-proxy:8888/quota)
10+
11+
if [ $? -ne 0 ]; then
12+
echo "Quota limit should not trigger yet"
13+
exit 1
14+
fi
15+
16+
# Quota is debited from all matching buckets and 3rd request should be rejected
17+
response=$(curl -f -s http://envoy-proxy:8888/quota | grep "Too Many Requests")
18+
19+
if [ $? -eq 0 ]; then
20+
echo "Quota limiting should fail the request"
21+
exit 1
22+
fi
23+
24+
echo "Waiting 1 minute for quota buckets to be refreshed"
25+
sleep 60
26+
27+
response=$(curl -i -s http://envoy-proxy:8888/quota)
28+
if [ $? -ne 0 ]; then
29+
echo "Quota bucket should be refreshed"
30+
exit 1
31+
fi

0 commit comments

Comments
 (0)