Skip to content

Commit

Permalink
(micrometer) don't add . to empty unit with prometheus naming convent…
Browse files Browse the repository at this point in the history
…ions (#8872)
  • Loading branch information
zeitlinger committed Jul 11, 2023
1 parent acbab58 commit b3932c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public String name(String name, Meter.Type type, @Nullable String baseUnit) {
if (type == Meter.Type.COUNTER
|| type == Meter.Type.DISTRIBUTION_SUMMARY
|| type == Meter.Type.GAUGE) {
if (baseUnit != null && !name.endsWith("." + baseUnit)) {
if (baseUnit != null && !baseUnit.equals("") && !name.endsWith("." + baseUnit)) {
name = name + "." + baseUnit;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void testCounter() {
Counter.builder("testPrometheusCounter")
.description("This is a test counter")
.tags("tag", "value")
.baseUnit("items")
.baseUnit("")
.register(Metrics.globalRegistry);

// when
Expand All @@ -44,13 +44,13 @@ void testCounter() {
testing()
.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testPrometheusCounter.items",
"testPrometheusCounter",
metrics ->
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDescription("This is a test counter")
.hasUnit("items")
.hasUnit("")
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
Expand Down

0 comments on commit b3932c7

Please sign in to comment.