Shawyeok commented on a change in pull request #14564:
URL: https://github.com/apache/pulsar/pull/14564#discussion_r820115248
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/metrics/PrometheusTextFormatUtil.java
##########
@@ -167,4 +182,33 @@ public static void
writeMetricsCollectedByPrometheusClient(Writer w, CollectorRe
}
}
}
+
+ private static void writeLabels(Writer w, Map<String, String> labels)
throws IOException {
+ if (labels.isEmpty()) {
+ return;
+ }
+
+ w.append('{');
+ writeLabelsNoBraces(w, labels);
+ w.append('}');
+ }
+
+ private static void writeLabelsNoBraces(Writer w, Map<String, String>
labels) throws IOException {
+ if (labels.isEmpty()) {
+ return;
+ }
+
+ boolean isFirst = true;
+ for (Map.Entry<String, String> e : labels.entrySet()) {
+ if (!isFirst) {
+ w.append(',');
+ }
+ isFirst = false;
+ w.append(e.getKey())
+ .append("=\"")
+ .append(e.getValue())
Review comment:
In the future, the label (key or value) could be user input or
configuration, is it safer if we do the escape job for special characters
before write out? e.g. `\` `"` `\n`, reference
`io.prometheus.client.exporter.common.TextFormat#writeEscapedLabelValue`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]