client_java icon indicating copy to clipboard operation
client_java copied to clipboard

Counter metric name "whatever_created_total" is not allowed

Open sandrinr opened this issue 8 months ago • 1 comments

Consider this metric registration:

Counter.builder().name("whatever_created_total").register();

It will end up with the exception:

java.lang.IllegalArgumentException: 'whatever_created': Illegal metric name: The metric name must not include the '_created' suffix.
	at io.prometheus.metrics.core.metrics.MetricWithFixedMetadata$Builder.name(MetricWithFixedMetadata.java:62)
	at io.prometheus.metrics.core.metrics.Counter$Builder.name(Counter.java:240)

This happens because the Counter strips the _total suffix before, sending it to the validation logic. The validation has a suffix list which is denying _created, even though in the example case _created is not the suffix of the metric.

Looking at the code, I think it is too naive to have one general static metrics validation logic for all metric types. For example, Counter should have validation logic, which allows _total suffixes.

sandrinr avatar May 19 '25 04:05 sandrinr

This will be fixed in https://github.com/prometheus/OpenMetrics/issues/286 - which basically says that metric names are not changed or checked in client sdks

zeitlinger avatar May 19 '25 12:05 zeitlinger