diff --git a/examples/envoy/proxy.yaml b/examples/envoy/proxy.yaml index a4a6a87f5..f6e6518ba 100644 --- a/examples/envoy/proxy.yaml +++ b/examples/envoy/proxy.yaml @@ -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" diff --git a/examples/ratelimit/config/example.yaml b/examples/ratelimit/config/example.yaml index 1c3d0c198..3c2709151 100644 --- a/examples/ratelimit/config/example.yaml +++ b/examples/ratelimit/config/example.yaml @@ -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 diff --git a/integration-test/scripts/quota.sh b/integration-test/scripts/quota.sh new file mode 100755 index 000000000..b21e7dd16 --- /dev/null +++ b/integration-test/scripts/quota.sh @@ -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