advancedxy commented on code in PR #812:
URL: https://github.com/apache/incubator-uniffle/pull/812#discussion_r1168206767
##########
common/src/main/java/org/apache/uniffle/common/metrics/MetricsManager.java:
##########
@@ -17,27 +17,38 @@
package org.apache.uniffle.common.metrics;
+import java.util.Map;
+
+import com.google.common.collect.Maps;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.Gauge;
import io.prometheus.client.Histogram;
import io.prometheus.client.Summary;
public class MetricsManager {
- private CollectorRegistry collectorRegistry;
+ private final CollectorRegistry collectorRegistry;
+ private final String[] defaultLabelNames;
+ private final String[] defaultLabelValues;
private static final double[] QUANTILES = {0.50, 0.75, 0.90, 0.95, 0.99};
private static final double QUANTILE_ERROR = 0.01;
public MetricsManager() {
- this(null);
+ this(null, Maps.newHashMap());
}
- public MetricsManager(CollectorRegistry collectorRegistry) {
+ public MetricsManager(CollectorRegistry collectorRegistry, Map<String,
String> defaultLabels) {
if (collectorRegistry == null) {
this.collectorRegistry = CollectorRegistry.defaultRegistry;
} else {
this.collectorRegistry = collectorRegistry;
}
+ this.defaultLabelNames = defaultLabels.entrySet().stream()
+ .map(Map.Entry::getKey)
+ .toArray(String[]::new);
+ this.defaultLabelValues = defaultLabels.entrySet().stream()
+ .map(Map.Entry::getValue)
+ .toArray(String[]::new);
Review Comment:
Maybe I didn't make it clear, these line are the same with your previous
commit. I was previously providing a wrong example.
```suggestion
this.defaultLabelNames = defaultLabels.keySet().toArray(new String[0]);
this.defaultLabelValues = Arrays.stream(defaultLabelNames)
.map(defaultLabels::get)
.toArray(String[]::new);
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]