Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/envoy/proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,21 @@ static_resources:
- request_headers:
header_name: "unspec"
descriptor_key: "unspec"
- match:
prefix: /quota
route:
cluster: mock
typed_per_filter_config:
envoy.filters.http.ratelimit:
"@type": type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimitPerRoute
vh_rate_limits: INCLUDE
override_option: INCLUDE_POLICY
rate_limits:
- actions:
- generic_key:
descriptor_value: "service_1"
descriptor_key: "service"
- actions:
- generic_key:
descriptor_value: "service_2"
descriptor_key: "service"
12 changes: 12 additions & 0 deletions examples/ratelimit/config/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,15 @@ descriptors:
- key: qux
rate_limit:
unlimited: true
- key: service
value: service_1
quota_mode: true
rate_limit:
unit: minute
requests_per_unit: 1
- key: service
value: service_2
quota_mode: true
rate_limit:
unit: minute
requests_per_unit: 2
31 changes: 31 additions & 0 deletions integration-test/scripts/quota.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

#
# request to /quota will produce the (service: service_1), (service: service_2) descriptor
# service_1 has 1 req/min and service_2 has 2 req/min
#

response=$(curl -f -s http://envoy-proxy:8888/quota)
response=$(curl -f -s http://envoy-proxy:8888/quota)

if [ $? -ne 0 ]; then
echo "Quota limit should not trigger yet"
exit 1
fi

# Quota is debited from all matching buckets and 3rd request should be rejected
response=$(curl -f -s http://envoy-proxy:8888/quota | grep "Too Many Requests")

if [ $? -eq 0 ]; then
echo "Quota limiting should fail the request"
exit 1
fi

echo "Waiting 1 minute for quota buckets to be refreshed"
sleep 60

response=$(curl -i -s http://envoy-proxy:8888/quota)
if [ $? -ne 0 ]; then
echo "Quota bucket should be refreshed"
exit 1
fi
Loading