Skip to content

Conversation

jonatan-ivanov
Copy link
Member

Closes gh-5923

Copy link
Member Author

@jonatan-ivanov jonatan-ivanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking if we should fix this starting from 1.13.x or just in main (starting from 1.15.x).
The behavior is changing (well, it's a bug) for those who use PrometheusNamingConvention directly, but otherwise the change should be transparent for others except the error message.

Comment on lines -594 to +597
+ " set of tag keys. There is already an existing meter named '" + id.getName()
+ " set of tag keys. There is already an existing meter named '" + getConventionName(id)
+ "' containing tag keys ["
+ String.join(", ", collectorMap.get(getConventionName(id)).getTagKeys())
+ "]. The meter you are attempting to register" + " has keys ["
+ getConventionTags(id).stream().map(Tag::getKey).collect(joining(", ")) + "].");
+ "]. The meter you are attempting to register" + " has keys [" + String.join(", ", tagKeys)
+ "].");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the message to use _, previously it was using .; with the 0.x client we are using them mixed (name uses ., tags use _).

So this will be something like:

[...] There is already an existing meter named 'my_counter' containing tag keys [test_k1]. The meter you are attempting to register has keys [test_k2]."

@@ -85,7 +85,7 @@ else if (!conventionName.endsWith("_seconds")) {
*/
@Override
public String tagKey(String key) {
return PrometheusNaming.sanitizeLabelName(key);
return PrometheusNaming.sanitizeLabelName(PrometheusNaming.prometheusName(key));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the change that makes label names consistent to metric names inside of the registry and for users who directly want to use this NamingConvention.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we need to do this since we're already calling the Prometheus library's sanitizeLabelName. I would expect that to do any needed transformation of a label name. I wonder if its current behavior is intentional or not. It seems possible that there could be subtle intended differences in the rules about metric names vs labels, so using both here could be problematic in the future if it isn't already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: we asked @fstab, for now we should do prometheusName + sanitizeXyz.

@jonatan-ivanov jonatan-ivanov requested a review from shakuzen March 21, 2025 00:24
@jonatan-ivanov jonatan-ivanov merged commit 40454df into micrometer-metrics:main Apr 8, 2025
9 checks passed
@jonatan-ivanov jonatan-ivanov deleted the prometheus-tag-names branch April 8, 2025 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Prometheus Metric and Label naming conventions consistent
2 participants