advancedxy commented on code in PR #812:
URL: https://github.com/apache/incubator-uniffle/pull/812#discussion_r1168094509


##########
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:
   >  I think this just means that the order of map.Entry is unstable, but the 
key and value are still one-on-one.
   
   From my understanding, the order of `map.Entry` is not specified, which 
means you cannot guarantee that the order of `map.Entry` is stable. The key 
value pairs are of course one to one mapped. 
   The problem of not stable order is that you may get different result for two 
consecutive calls for some special Map implementations. For example, the 
iteration order of `Set{1,2,3}` is not stable, you may get 
   ```
   1,2,3 # the first iteration
   3,1,2 # the second iteration
   ```
   The above might apply to some Map implementations.  Thus for that special 
implementation, the above code 
   ```
   this.defaultLabelNames = defaultLabels.keySet().toArray(new String[0]);
   this.defaultLabelValues = defaultLabels.values().toArray(new String[0]);
   ```
   might produce values not mapped to keys.



-- 
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]

Reply via email to