Skip to content
7 changes: 7 additions & 0 deletions docker-compose-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ services:

statsd:
image: prom/statsd-exporter:v0.18.0
entrypoint: /bin/statsd_exporter
command:
- "--statsd.mapping-config=/etc/statsd-exporter/conf.yaml"
expose:
- 9125
- 9102
ports:
- 9125:9125
- 9102:9102 # Visit http://localhost:9102/metrics to see metrics in Prometheus format
networks:
- ratelimit-network
volumes:
- ./examples/prom-statsd-exporter/conf.yaml:/etc/statsd-exporter/conf.yaml

ratelimit:
image: envoyproxy/ratelimit:master
Expand Down
53 changes: 27 additions & 26 deletions examples/envoy/mock.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 9999
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
codec_type: auto
stat_prefix: ingress
route_config:
name: ingress
virtual_hosts:
- name: backend
domains:
- "*"
routes:
- match:
prefix: "/"
direct_response:
status: "200"
body:
inline_string: "Hello World"
http_filters:
- name: envoy.router
config: {}
- address:
socket_address:
address: 0.0.0.0
port_value: 9999
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: AUTO
stat_prefix: ingress
route_config:
name: ingress
virtual_hosts:
- name: backend
domains:
- "*"
routes:
- match:
prefix: "/"
direct_response:
status: "200"
body:
inline_string: "Hello World"
http_filters:
- name: envoy.filters.http.router
typed_config: {}
admin:
access_log_path: "/dev/null"
address:
Expand Down
20 changes: 11 additions & 9 deletions examples/envoy/proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ static_resources:
port_value: 8888
filter_chains:
- filters:
- name: envoy.http_connection_manager
config:
codec_type: auto
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: AUTO
stat_prefix: ingress
http_filters:
- name: envoy.rate_limit
config:
- name: envoy.filters.http.ratelimit
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimit
domain: rl
request_type: external
stage: 0
Expand All @@ -57,8 +59,8 @@ static_resources:
grpc_service:
envoy_grpc:
cluster_name: ratelimit
- name: envoy.router
config: {}
- name: envoy.filters.http.router
typed_config: {}
route_config:
name: route
virtual_hosts:
Expand All @@ -72,8 +74,8 @@ static_resources:
cluster: mock
rate_limits:
- actions:
- source_cluster: {}
- destination_cluster: {}
- source_cluster: {} # This action's value is populated by the "service-cluster" arg passed in when starting Envoy. In this example, it's "proxy" (see docker-compose-example.yml)
- destination_cluster: {} # This action's value is populated by the value set in the above egress "cluster" field -- "mock"
- match:
prefix: /header
route:
Expand Down
67 changes: 67 additions & 0 deletions examples/prom-statsd-exporter/conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
mappings: # Requires statsd exporter >= v0.6.0 since it uses the "drop" action.
- match:
"ratelimit.service.rate_limit.*.*.near_limit"
name: "ratelimit_service_rate_limit_near_limit"
timer_type: "histogram"
labels:
domain: "$1"
key1: "$2"
- match:
"ratelimit.service.rate_limit.*.*.over_limit"
name: "ratelimit_service_rate_limit_over_limit"
timer_type: "histogram"
labels:
domain: "$1"
key1: "$2"
- match:
"ratelimit.service.rate_limit.*.*.total_hits"
name: "ratelimit_service_rate_limit_total_hits"
timer_type: "histogram"
labels:
domain: "$1"
key1: "$2"

- match:
"ratelimit.service.rate_limit.*.*.*.near_limit"
name: "ratelimit_service_rate_limit_near_limit"
timer_type: "histogram"
labels:
domain: "$1"
key1: "$2"
key2: "$3"
- match:
"ratelimit.service.rate_limit.*.*.*.over_limit"
name: "ratelimit_service_rate_limit_over_limit"
timer_type: "histogram"
labels:
domain: "$1"
key1: "$2"
key2: "$3"
- match:
"ratelimit.service.rate_limit.*.*.*.total_hits"
name: "ratelimit_service_rate_limit_total_hits"
timer_type: "histogram"
labels:
domain: "$1"
key1: "$2"
key2: "$3"

- match: "ratelimit.service.call.should_rate_limit.*"
name: "ratelimit_service_should_rate_limit_error"
match_metric_type: counter
labels:
err_type: "$1"

- match: "ratelimit.service.config_load_success"
name: "ratelimit_service_config_load_success"
match_metric_type: counter
- match: "ratelimit.service.config_load_error"
name: "ratelimit_service_config_load_error"
match_metric_type: counter
- match: "ratelimit.service.config_load_error"
name: "ratelimit_service_config_load_error"
match_metric_type: counter
- match: "."
match_type: "regex"
action: "drop"
name: "dropped"