Skip to content

Commit

Permalink
Merge pull request #6970 from pdudits/fish-9806-p6
Browse files Browse the repository at this point in the history
FISH-9806 FISH-8522: Prevent duplicate HELP metadata in OpenMetrics endpoint
  • Loading branch information
luiseufrasio authored Oct 10, 2024
2 parents 23b53ce + b02c20c commit 129acc2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> description = metadata.description();
out.append("# HELP ").append(globalName).append(' ').append(description.isPresent() ? description.get(): "").append('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 129acc2

Please sign in to comment.