Skip to content

Commit 57b85bf

Browse files
doc: http metrics path normalization (#4155)
* doc: http metrics path normalization Signed-off-by: nelson.parente <[email protected]> * doc: code review & path matching rename Signed-off-by: nelson.parente <[email protected]> * doc: add configuration examples Signed-off-by: nelson.parente <[email protected]> * update: update docs based on last proposal changes Signed-off-by: nelson.parente <[email protected]> * feat: more updates based on the ingress/egress merge Signed-off-by: nelson.parente <[email protected]> * doc: code review comments Signed-off-by: nelson.parente <[email protected]> * doc: code review comments Signed-off-by: nelson.parente <[email protected]> * feat: add excludeVerbs Signed-off-by: nelson.parente <[email protected]> * feat: new line Signed-off-by: nelson.parente <[email protected]> * feat: add review meeting changes Signed-off-by: nelson.parente <[email protected]> * feat: apply hunter suggestions Signed-off-by: nelson.parente <[email protected]> --------- Signed-off-by: nelson.parente <[email protected]>
1 parent 44e95d5 commit 57b85bf

File tree

3 files changed

+144
-7
lines changed

3 files changed

+144
-7
lines changed

daprdocs/content/en/operations/configuration/configuration-overview.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,30 @@ metrics:
110110
rules: []
111111
http:
112112
increasedCardinality: true
113+
pathMatching:
114+
- /items
115+
- /orders/{orderID}
116+
- /orders/{orderID}/items/{itemID}
117+
- /payments/{paymentID}
118+
- /payments/{paymentID}/status
119+
- /payments/{paymentID}/refund
120+
- /payments/{paymentID}/details
121+
excludeVerbs: false
113122
```
114123

124+
In the examples above, the path filter `/orders/{orderID}/items/{itemID}` would return a single metric count matching all the `orderIDs` and all the `itemIDs`, rather than multiple metrics for each `itemID`. For more information, see [HTTP metrics path matching]({{< ref "metrics-overview.md#http-metrics-path-matching" >}}).
125+
115126
The following table lists the properties for metrics:
116127

117128
| Property | Type | Description |
118129
|--------------|--------|-------------|
119130
| `enabled` | boolean | When set to true, the default, enables metrics collection and the metrics endpoint. |
120131
| `rules` | array | Named rule to filter metrics. Each rule contains a set of `labels` to filter on and a `regex` expression to apply to the metrics path. |
121-
| `http.increasedCardinality` | boolean | When set to true, in the Dapr HTTP server each request path causes the creation of a new "bucket" of metrics. This can cause issues, including excessive memory consumption, when there many different requested endpoints (such as when interacting with RESTful APIs).<br>In Dapr 1.13 the default value is `true` (to preserve the behavior of Dapr <= 1.12), but will change to `false` in Dapr 1.14. |
132+
| `http.increasedCardinality` | boolean | When set to `true` (default), in the Dapr HTTP server, each request path causes the creation of a new "bucket" of metrics. This can cause issues, including excessive memory consumption when there many different requested endpoints (such as when interacting with RESTful APIs).<br> To mitigate high memory usage and egress costs associated with [high cardinality metrics]({{< ref "metrics-overview.md#high-cardinality-metrics" >}}) with the HTTP server, you should set the `metrics.http.increasedCardinality` property to `false`.|
133+
| `http.pathMatching` | array | Paths used for path matching, allowing users to define matching paths in order to manage cardinality. |
134+
| `http.excludeVerbs` | boolean | When set to `true` (default is `false`), the Dapr HTTP server ignores each request HTTP verb when building the method metric label. |
122135

123-
To mitigate high memory usage and egress costs associated with [high cardinality metrics]({{< ref "metrics-overview.md#high-cardinality-metrics" >}}) with the HTTP server, you should set the `metrics.http.increasedCardinality` property to `false`.
136+
To further help managing cardinality, path matching allows specified paths matched according to defined patterns, reducing the number of unique metrics paths and thus controlling metric cardinality. This feature is particularly useful for applications with dynamic URLs, ensuring that metrics remain meaningful and manageable without excessive memory consumption.
124137

125138
Using rules, you can set regular expressions for every metric exposed by the Dapr sidecar. For example:
126139

daprdocs/content/en/operations/observability/metrics/metrics-overview.md

+125-5
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,135 @@ spec:
7070
enabled: false
7171
```
7272

73-
## High cardinality metrics
73+
## Optimizing HTTP metrics reporting with path matching
7474

75-
When invoking Dapr using HTTP, the legacy behavior (and current default as of Dapr 1.13) is to create a separate "bucket" for each requested method. When working with RESTful APIs, this can cause very high cardinality, with potential negative impact on memory usage and CPU.
75+
When invoking Dapr using HTTP, metrics are created for each requested method by default. This can result in a high number of metrics, known as high cardinality, which can impact memory usage and CPU.
7676

77-
Dapr 1.13 introduces a new option for the Dapr Configuration resource `spec.metrics.http.increasedCardinality`: when set to `false`, it reports metrics for the HTTP server for each "abstract" method (for example, requesting from a state store) instead of creating a "bucket" for each concrete request path.
77+
Path matching allows you to manage and control the cardinality of HTTP metrics in Dapr. This is an aggregation of metrics, so rather than having a metric for each event, you can reduce the number of metrics events and report an overall number. For details on how to set the cardinality in configuration see ({{< ref "configuration-overview.md#metrics" >}})
78+
79+
This configuration is opt-in and is enabled via the Dapr configuration `spec.metrics.http.pathMatching`. When defined, it enables path matching, which standardizes specified paths for both metrics paths. This reduces the number of unique metrics paths, making metrics more manageable and reducing resource consumption in a controlled way.
80+
81+
When `spec.metrics.http.pathMatching` is combined with the `increasedCardinality` flag set to `false`, non-matched paths are transformed into a catch-all bucket to control and limit cardinality, preventing unbounded path growth. Conversely, when `increasedCardinality` is `true` (the default), non-matched paths are passed through as they normally would be, allowing for potentially higher cardinality but preserving the original path data.
82+
83+
### Examples of Path Matching in HTTP Metrics
84+
85+
The following examples demonstrate how to use the Path Matching API in Dapr for managing HTTP metrics. On each example, the metrics are collected from 5 HTTP requests to the `/orders` endpoint with different order IDs. By adjusting cardinality and utilizing path matching, you can fine-tune metric granularity to balance detail and resource efficiency.
86+
87+
These examples illustrate the cardinality of the metrics, highlighting that high cardinality configurations result in many entries, which correspond to higher memory usage for handling metrics. For simplicity, the following example focuses on a single metric: `dapr_http_server_request_count`.
88+
89+
#### Low cardinality with path matching (Recommendation)
90+
91+
Configuration:
92+
```yaml
93+
http:
94+
increasedCardinality: false
95+
pathMatching:
96+
- /orders/{orderID}
97+
```
98+
99+
Metrics generated:
100+
```
101+
# matched paths
102+
dapr_http_server_request_count{app_id="order-service",method="GET",path="/orders/{orderID}",status="200"} 5
103+
# unmatched paths
104+
dapr_http_server_request_count{app_id="order-service",method="GET",path="",status="200"} 1
105+
```
106+
107+
With low cardinality and path matching configured, you get the best of both worlds by grouping the metrics for the important endpoints without compromising the cardinality. This approach helps avoid high memory usage and potential security issues.
108+
109+
#### Low cardinality without path matching
110+
111+
Configuration:
112+
113+
```yaml
114+
http:
115+
increasedCardinality: false
116+
```
117+
Metrics generated:
118+
```
119+
dapr_http_server_request_count{app_id="order-service",method="GET", path="",status="200"} 5
120+
```
121+
122+
In low cardinality mode, the path, which is the main source of unbounded cardinality, is dropped. This results in metrics that primarily indicate the number of requests made to the service for a given HTTP method, but without any information about the paths invoked.
123+
124+
125+
#### High cardinality with path matching
126+
127+
Configuration:
128+
```yaml
129+
http:
130+
increasedCardinality: true
131+
pathMatching:
132+
- /orders/{orderID}
133+
```
134+
135+
Metrics generated:
136+
```
137+
dapr_http_server_request_count{app_id="order-service",method="GET",path="/orders/{orderID}",status="200"} 5
138+
```
139+
140+
This example results from the same HTTP requests as the example above, but with path matching configured for the path `/orders/{orderID}`. By using path matching, you achieve reduced cardinality by grouping the metrics based on the matched path.
141+
142+
#### High Cardinality without path matching
143+
144+
Configuration:
145+
```yaml
146+
http:
147+
increasedCardinality: true
148+
```
149+
150+
Metrics generated:
151+
```
152+
dapr_http_server_request_count{app_id="order-service",method="GET",path="/orders/1",status="200"} 1
153+
dapr_http_server_request_count{app_id="order-service",method="GET",path="/orders/2",status="200"} 1
154+
dapr_http_server_request_count{app_id="order-service",method="GET",path="/orders/3",status="200"} 1
155+
dapr_http_server_request_count{app_id="order-service",method="GET",path="/orders/4",status="200"} 1
156+
dapr_http_server_request_count{app_id="order-service",method="GET",path="/orders/5",status="200"} 1
157+
```
158+
159+
For each request, a new metric is created with the request path. This process continues for every request made to a new order ID, resulting in unbounded cardinality since the IDs are ever-growing.
160+
161+
162+
### HTTP metrics exclude verbs
163+
164+
The `excludeVerbs` option allows you to exclude specific HTTP verbs from being reported in the metrics. This can be useful in high-performance applications where memory savings are critical.
165+
166+
### Examples of excluding HTTP verbs in metrics
167+
168+
The following examples demonstrate how to exclude HTTP verbs in Dapr for managing HTTP metrics.
169+
170+
#### Default - Include HTTP verbs
171+
172+
Configuration:
173+
```yaml
174+
http:
175+
excludeVerbs: false
176+
```
177+
178+
Metrics generated:
179+
```
180+
dapr_http_server_request_count{app_id="order-service",method="GET",path="/orders",status="200"} 1
181+
dapr_http_server_request_count{app_id="order-service",method="POST",path="/orders",status="200"} 1
182+
```
183+
184+
In this example, the HTTP method is included in the metrics, resulting in a separate metric for each request to the `/orders` endpoint.
185+
186+
#### Exclude HTTP verbs
187+
188+
Configuration:
189+
```yaml
190+
http:
191+
excludeVerbs: true
192+
```
193+
194+
Metrics generated:
195+
```
196+
dapr_http_server_request_count{app_id="order-service",method="",path="/orders",status="200"} 2
197+
```
198+
199+
In this example, the HTTP method is excluded from the metrics, resulting in a single metric for all requests to the `/orders` endpoint.
78200

79-
The default value of `spec.metrics.http.increasedCardinality` is `true` in Dapr 1.13, to maintain the same behavior as Dapr 1.12 and older. However, the value will change to `false` (low-cardinality metrics by default) in Dapr 1.14.
80201

81-
Setting `spec.metrics.http.increasedCardinality` to `false` is **recommended** to all Dapr users, to reduce resource consumption. The pre-1.13 behavior, which is used when the option is `true`, is considered legacy and is only maintained for users who have special requirements around backwards-compatibility.
82202

83203
## Transform metrics with regular expressions
84204

daprdocs/content/en/reference/resource-specs/configuration-schema.md

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ spec:
3838
regex: {}
3939
http:
4040
increasedCardinality: <TRUE-OR-FALSE>
41+
pathMatching:
42+
- <PATH-A>
43+
- <PATH-B>
44+
excludeVerbs: <TRUE-OR-FALSE>
4145
httpPipeline: # for incoming http calls
4246
handlers:
4347
- name: <HANDLER-NAME>

0 commit comments

Comments
 (0)