envoyproxy / envoyproxy/gateway
Add detailed_metrics support to global ratelimit config
- Dominant language
- Go
- Stars
- 3k
- Forks
- 864
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 140
Description
https://github.com/envoyproxy/ratelimit/issues/461 added support for dynamic [`detailed_metrics`](https://github.com/envoyproxy/ratelimit#including-detailed-metrics-for-unspecified-values) to the ratelimit service.
All the API dependencies are already present, [I did a quick test](https://github.com/crinjes/gateway/commit/35a3be9fba6733e3969fe719ed185818bb85054c) and believe the only thing required to enable the use in gateway is to add a boolean flag very similar to `shadowMode` to the `BackendTrafficPolicy` configuration.
This would allow something like:
```yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: BackendTrafficPolicy
spec:
rateLimit:
global:
rules:
- clientSelectors:
- headers:
- name: x-client-id
type: Distinct
detailedMetric: true # <<<
limit:
requests: 10
unit: Minute
shared: true
```
For example, if there were one request with header `x-client-id: 1234` and four requests with `x-client-id: 4567`, the ratelimit service currentls would show the metrics like this:
```
ratelimit_service_rate_limit_total_hits{domain="...",key1="...",key2="rule-0-match-0"} 5
```
By enabling `detailed_metrics`, the resulting metrics would look like this:
```
ratelimit_service_rate_limit_total_hits{domain="...",key1="...",key2="rule-0-match-0_1234"} 1
ratelimit_service_rate_limit_total_hits{domain="...",key1="...",key2="rule-0-match-0_4567"} 4
```
This makes the `ratelimit_service_rate_limit_near_limit` and `ratelimit_service_rate_limit_over_limit` more useful, at the potential cost of very high metrics cardinality if not used carefully.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.