advancedxy commented on code in PR #812:
URL: https://github.com/apache/incubator-uniffle/pull/812#discussion_r1165548810
##########
common/src/main/java/org/apache/uniffle/common/metrics/MetricsManager.java:
##########
@@ -17,27 +17,34 @@
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.keySet().toArray(new String[0]);
+ this.defaultLabelValues = defaultLabels.values().toArray(new String[0]);
Review Comment:
Yeah.
> As quote from: https://docs.oracle.com/javase/8/docs/api/java/util/Map.html
> The Map interface provides three collection views, which allow a map's
contents to be viewed as a set of keys, collection of values, or set of
key-value mappings. The order of a map is defined as the order in which the
iterators on the map's collection views return their elements. Some map
implementations, like the TreeMap class, make specific guarantees as to their
order; others, like the HashMap class, do not.
I didn't see the order of a map is stable. Which means for some Map impls,
the iteration order is different for multiple calls.
It might be safe to call
```
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]