File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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"
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments