client_java
client_java copied to clipboard
Counter metric name "whatever_created_total" is not allowed
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.
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