Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PrometheusMeterRegistry continue silently on meters with same name and different tags #2400

Merged
merged 1 commit into from Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -420,7 +420,7 @@ private void applyToCollector(Meter.Id id, Consumer<MicrometerCollector> consume
" set of tag keys. There is already an existing meter named '" + id.getName() + "' 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(", ")) + "].");
return null;
return existingCollector;
});
}

Expand Down
Expand Up @@ -63,6 +63,14 @@ void before() {
registry.config().namingConvention(new PrometheusDurationNamingConvention());
}

@Test
void metersWithSameNameAndDifferentTagsContinueSilently() {
String meterName = "my.counter";
registry.counter(meterName, "k1", "v1");
registry.counter(meterName, "k2", "v2");
registry.counter(meterName, "k3", "v3");
}

@Test
void meterRegistrationFailedListenerCalledOnSameNameDifferentTags() throws InterruptedException {
CountDownLatch failedLatch = new CountDownLatch(1);
Expand All @@ -75,10 +83,13 @@ void meterRegistrationFailedListenerCalledOnSameNameDifferentTags() throws Inter
assertThatThrownBy(() -> registry
.throwExceptionOnRegistrationFailure()
.counter("my.counter", "k1", "v1")
).isInstanceOf(IllegalArgumentException.class);
)
.isInstanceOf(IllegalArgumentException.class)
.hasMessageStartingWith("Prometheus requires that all meters with the same name have the same set of tag keys.");

assertThatThrownBy(() -> registry.counter("my.counter", "k2", "v2"))
.isInstanceOf(IllegalArgumentException.class);
.isInstanceOf(IllegalArgumentException.class)
.hasMessageStartingWith("Prometheus requires that all meters with the same name have the same set of tag keys.");
}

@Test
Expand Down