You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add field to add unspecified value to metric (#996)
* Add field to add unspecified value to metric
Signed-off-by: xuannam230201 <[email protected]>
Signed-off-by: Nam Dang <[email protected]>
* Update README.md to pass docs_check_format check
Signed-off-by: Nam Dang <[email protected]>
* Update format to pass pre-commit check
Signed-off-by: Nam Dang <[email protected]>
* Update based on comments and add more unit tests
Signed-off-by: Nam Dang <[email protected]>
---------
Signed-off-by: xuannam230201 <[email protected]>
Signed-off-by: Nam Dang <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@
21
21
-[Replaces](#replaces)
22
22
-[ShadowMode](#shadowmode)
23
23
-[Including detailed metrics for unspecified values](#including-detailed-metrics-for-unspecified-values)
24
+
-[Including descriptor values in metrics](#including-descriptor-values-in-metrics)
24
25
-[Examples](#examples)
25
26
-[Example 1](#example-1)
26
27
-[Example 2](#example-2)
@@ -31,6 +32,7 @@
31
32
-[Example 7](#example-7)
32
33
-[Example 8](#example-8)
33
34
-[Example 9](#example-9)
35
+
-[Example 10](#example-10)
34
36
-[Loading Configuration](#loading-configuration)
35
37
-[File Based Configuration Loading](#file-based-configuration-loading)
36
38
-[xDS Management Server Based Configuration Loading](#xds-management-server-based-configuration-loading)
@@ -282,6 +284,7 @@ descriptors:
282
284
requests_per_unit: <see below: required>
283
285
shadow_mode: (optional)
284
286
detailed_metric: (optional)
287
+
value_to_metric: (optional)
285
288
descriptors: (optional block)
286
289
- ... (nested repetition of above)
287
290
```
@@ -336,6 +339,14 @@ Setting the `detailed_metric: true` for a descriptor will extend the metrics tha
336
339
337
340
NB! This should only be enabled in situations where the potentially large cardinality of metrics that this can lead to is acceptable.
338
341
342
+
### Including descriptor values in metrics
343
+
344
+
Setting `value_to_metric: true` (default: `false`) for a descriptor will include the descriptor's runtime value in the metric key, even when the descriptor value is not explicitly defined in the configuration. This allows you to track metrics per descriptor value when the value comes from the runtime request, providing visibility into different rate limit scenarios without needing to pre-define every possible value.
345
+
346
+
**Note:** If a value is explicitly specified in a descriptor (e.g., `value: "GET"`), that value is always included in the metric key regardless of the `value_to_metric` setting. The `value_to_metric` flag only affects descriptors where the value is not explicitly defined in the configuration.
347
+
348
+
When combined with wildcard matching, the full runtime value is included in the metric key, not just the wildcard prefix. This feature works independently of `detailed_metric` - when `detailed_metric` is set, it takes precedence and `value_to_metric` is ignored.
349
+
339
350
### Examples
340
351
341
352
#### Example 1
@@ -629,6 +640,58 @@ descriptors:
629
640
requests_per_unit: 20
630
641
```
631
642
643
+
#### Example 10
644
+
645
+
Using `value_to_metric: true` to include descriptor values in metrics when values are not explicitly defined in the configuration:
646
+
647
+
```yaml
648
+
domain: example10
649
+
descriptors:
650
+
- key: route
651
+
value_to_metric: true
652
+
descriptors:
653
+
- key: http_method
654
+
value_to_metric: true
655
+
descriptors:
656
+
- key: subject_id
657
+
rate_limit:
658
+
unit: minute
659
+
requests_per_unit: 60
660
+
```
661
+
662
+
With this configuration, requests with different runtime values for `route` and `http_method` will generate separate metrics:
Note: When `detailed_metric: true` is set on a descriptor, it takes precedence and `value_to_metric` is ignored for that descriptor.
694
+
632
695
## Loading Configuration
633
696
634
697
Rate limit service supports following configuration loading methods. You can define which methods to use by configuring environment variable `CONFIG_TYPE`.
0 commit comments