> How do you deal with dynamic label names without having to create 
separate metrics counters?

You have to have separate counters.

Every combination of (metric name + set of label names/values) creates a 
distinct timeries, i.e. a different metric, by definition.  Therefore you 
need different counters for each distinct combination of label values.

Labels are not just somewhere to store a string.  If you put 
high-cardinality values in a label, i.e. values which change from request 
to request and are not bounded to a small subset of values, then you will 
risk a "cardinality explosion" where you have millions of timeseries all 
with a single value.  Under these conditions, Prometheus will crash and 
burn.

In your case, if you're using controller name and action name for labels, 
then I think it should be OK as those are values chosen from a small set 
defined in code.  For counting requests which don't have these fields, then 
use a dummy value like "-" for those labels.

On Monday, 15 August 2022 at 22:34:16 UTC+1 [email protected] wrote:

> In the default metrics exported with app.usehttpmetrics(), certain 
> metrics, such as http_requests_received_total will have scraped data that 
> only contain ''code' and 'method' labels which I see is defined here in 
> HttpRequestLabelNames.cs 
> <https://github.com/prometheus-net/prometheus-net/blob/38d45fa0a102e9afc76f031675aa0719d4f063d1/Prometheus.AspNetCore/HttpMetrics/HttpRequestLabelNames.cs>.
>  
> I'm trying to replicate the same thing with custom middleware that records 
> the response body content length. But when requests with bad query params 
> return 404 responses there is no controller, endpoint, or action fields in 
> HttpContext and I can't use my custom counters with those label names 
> specified. How do you deal with dynamic label names without having to 
> create separate metrics counters?

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/480cdc2e-825e-4c2c-94d5-c2a6cd8fe586n%40googlegroups.com.

Reply via email to