Skip to content

Make Prometheus Metric and Label naming conventions consistent #5923

@dpozinen

Description

@dpozinen

Since 1.13 the behaviour of has been changed.

For metrics the _counter prefix has been removed, as is well documented and the snake case convention remains:

public String name(String name, Meter.Type type, @Nullable String baseUnit) {
String conventionName = NamingConvention.snakeCase.name(name, type, baseUnit);

But for labels snake case has been removed in #4866:

public String tagKey(String key) {
return PrometheusNaming.sanitizeLabelName(key);
}

But even though Prometheus client supports dots in metrics and labels since prometheus/client_java@1a955b1 , it still replaces dots with underscores via https://github.com/prometheus/client_java/blob/5e93f4b2af0321061865bad1f39f531f3d19bd0e/prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots/Labels.java#L119-L130

For people using PrometheusNamingConvention in their own code the change to label handling is undocumented in the migration guide and actually the java doc for the method has an incorrect regex (without .):

* Label names may contain ASCII letters, numbers, as well as underscores. They must
* match the regex [a-zA-Z_][a-zA-Z0-9_]*. Label names beginning with __ are reserved
* for internal use.
*/
@Override
public String tagKey(String key) {

Now, I am generally confused with the . and _ changes in Prometheus where they are allowed and yet... not allowed really? Maybe you know more about this.

I think it is a good idea to either mention the change regarding labels in PrometheusNamingConvention in the guide and fix the javadoc, or revert the snake case change to align with the way metrics are evaluated. To me the latter is preferable.

Let me know what you think, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions