diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporter.java b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporter.java index 3be2b056597..a27e205a385 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporter.java +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/main/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporter.java @@ -285,16 +285,17 @@ public void export(MetricID metricID, Timer timer, Metadata metadata) { } protected void appendTYPE(String globalName, OpenMetricsType type) { - if (typeWrittenByGlobalName.contains(globalName)) { + if (!typeWrittenByGlobalName.add(globalName)) { + // write metadata only once per metric return; } - typeWrittenByGlobalName.add(globalName); out.append("# TYPE ").append(globalName).append(' ').append(type.name()).append('\n'); } protected void appendHELP(String globalName, Metadata metadata) { - if(!helpWrittenByGlobalName.contains(globalName)) { - helpWrittenByGlobalName.add(globalName); + if (!helpWrittenByGlobalName.add(globalName)) { + // write metadata only once per metric + return; } Optional description = metadata.description(); out.append("# HELP ").append(globalName).append(' ').append(description.isPresent() ? description.get(): "").append('\n'); diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/test/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporterTest.java b/appserver/payara-appserver-modules/microprofile/metrics/src/test/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporterTest.java index 5ab4a2fd45e..9a70d3cb618 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/test/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporterTest.java +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/test/java/fish/payara/microprofile/metrics/writer/OpenMetricsExporterTest.java @@ -210,7 +210,6 @@ public void eachTypeAndHelpLineOccursOnlyOnceForEachOpenMetricsName() { assertEquals("# TYPE common gauge\n" + "# HELP common description\n" + "common{a=\"b\"} 1\n" + - "# HELP common description\n"+ "common{some=\"other\"} 2\n", actual.getBuffer().toString()); } diff --git a/appserver/payara-appserver-modules/microprofile/metrics/src/test/resources/examples/GaugeTags.txt b/appserver/payara-appserver-modules/microprofile/metrics/src/test/resources/examples/GaugeTags.txt index 119df2f2541..6f43ca6614d 100644 --- a/appserver/payara-appserver-modules/microprofile/metrics/src/test/resources/examples/GaugeTags.txt +++ b/appserver/payara-appserver-modules/microprofile/metrics/src/test/resources/examples/GaugeTags.txt @@ -4,5 +4,4 @@ fooVal_seconds{store="webshop"} 12.345 # TYPE barVal_bytes gauge # HELP barVal_bytes barVal_bytes{component="backend",store="webshop"} 42000.0 -# HELP barVal_bytes barVal_bytes{component="frontend",store="webshop"} 63000.0