eolivelli commented on a change in pull request #14564: URL: https://github.com/apache/pulsar/pull/14564#discussion_r820145561
########## File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/metrics/ScopeContext.java ########## @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pulsar.broker.stats.prometheus.metrics; + +import java.util.Map; +import java.util.Objects; + +/** + * Holder for a scope and a set of associated labels. + */ +public class ScopeContext { + private final String scope; + private final Map<String, String> labels; + + public ScopeContext(String scope, Map<String, String> labels) { + this.scope = scope; + this.labels = labels; + } + + public String getScope() { + return scope; + } + + @Override + public boolean equals(Object o) { Review comment: We can use lombok here for equals and hashcode probably ########## File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/stats/prometheus/metrics/ScopeContext.java ########## @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pulsar.broker.stats.prometheus.metrics; + +import java.util.Map; +import java.util.Objects; + +/** + * Holder for a scope and a set of associated labels. + */ +public class ScopeContext { Review comment: final ? ########## 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: Good idea +1 -- 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]
