Duplicate Tags caused by the conversion between '.' and '_' #5808
Closed as not planned
Description
Describe the bug
If a tag exists a.b
and a_b
, duplicate labels will be created in the prometheus output.
my_metric_name{a_b="alpha", a_b="alpha"}
Environment
- Micrometer version: 1.11.9
- Micrometer registry: 1.11.9
- OS: docker-alpine, and Windows
- Java version: 17
To Reproduce
@Test
public void TagTest() {
Tags tags = Tags.of(Tag.of("a.b", "alpha"), Tag.of("a_b", "alpha"));
assertThat(tags.stream()).hasSize(1);
}
Here is the current workaround that i put in place to account for this issue.
registry.config().meterFilter(
new MeterFilter() {
@Override
public Meter.Id map(Meter.Id id) {
HashSet<String> tagKeys = new HashSet<>();
List<Tag> tags = new ArrayList<>();
for (Tag tag : id.getTagsAsIterable()) {
if (!tagKeys.contains(tag.getKey().replace(".", "_"))) {
tags.add(tag);
tagKeys.add(tag.getKey().replace(".", "_"));
}
else {
System.out.println("Duplicate Tag: " + tag.getKey());
}
}
return id.replaceTags(tags);
}
});
Expected behavior
duplicates will be detected in both output forms a.b
and a_b