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
23 changes: 23 additions & 0 deletions examples/envoy/proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,26 @@ static_resources:
- generic_key:
descriptor_value: "service_2"
descriptor_key: "service"
- match:
prefix: /tokenquota
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_2"
descriptor_key: "service"
hits_addend:
number: 0
- actions:
- generic_key:
descriptor_value: "service_2"
descriptor_key: "service"
hits_addend:
number: 1
apply_on_stream_done: true
33 changes: 33 additions & 0 deletions integration-test/scripts/token-quota.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

#
# request to /tokenquota will produce the (service: service_1), (service: service_2) descriptor
# with 0 addend on request path and (service: service_2) descriptor with addend 1 on response path.
# service_2 has 2 req/min so 2 requests should be allowed
#

response=$(curl -f -s -H "request-no: 1" http://envoy-proxy:8888/tokenquota)
response=$(curl -f -s -H "request-no: 2" http://envoy-proxy:8888/tokenquota)
response=$(curl -f -s -H "request-no: 3" http://envoy-proxy:8888/tokenquota)

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

# Quota is debited from service_2 bucket on the response path so only the 4th request should be rejected
response=$(curl -f -s -H "request-no: 4" http://envoy-proxy:8888/tokenquota)

if [ $? -ne 0 ]; then
echo "Quota mode does not deny requests yet"
exit 1
fi

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

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