Skip to content

Commit

Permalink
Make PrometheusMeterRegistry continue silently on meters with same na…
Browse files Browse the repository at this point in the history
…me and different tags (#2400)

See gh-2068
Fixes gh-2399
  • Loading branch information
izeye committed Jan 21, 2021
1 parent 40b6c71 commit b31d0e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit b31d0e8

Please sign in to comment.