xichen01 commented on code in PR #5479:
URL: https://github.com/apache/ozone/pull/5479#discussion_r1393649737


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/ProtocolMessageMetrics.java:
##########
@@ -40,32 +44,59 @@ public class ProtocolMessageMetrics<KEY> implements 
MetricsSource {
 
   private final String description;
 
+  private final MetricsRegistry registry;
+
+  private final boolean quantileEnable;
+
   private final Map<KEY, AtomicLong> counters =
       new ConcurrentHashMap<>();
 
   private final Map<KEY, AtomicLong> elapsedTimes =
       new ConcurrentHashMap<>();
 
+  private final Map<KEY, MutableQuantiles[]> quantiles =
+      new ConcurrentHashMap<>();
+
   private final AtomicInteger concurrency = new AtomicInteger(0);
 
   public static <KEY> ProtocolMessageMetrics<KEY> create(String name,
-      String description, KEY[] types) {
-    return new ProtocolMessageMetrics<KEY>(name, description, types);
+      String description, KEY[] types, ConfigurationSource conf) {
+    return new ProtocolMessageMetrics<KEY>(name, description, types, conf);
   }
 
   public ProtocolMessageMetrics(String name, String description,
-      KEY[] values) {
+      KEY[] values, ConfigurationSource conf) {
     this.name = name;
     this.description = description;
+    registry = new MetricsRegistry(name + "MessageMetrics");
+    int[] intervals = conf.getInts(
+        OzoneConfigKeys.OZONE_PROTOCOL_MESSAGE_METRICS_PERCENTILES_INTERVALS);
+    quantileEnable = (intervals.length > 0);
     for (KEY value : values) {
       counters.put(value, new AtomicLong(0));
       elapsedTimes.put(value, new AtomicLong(0));
+      if (quantileEnable) {
+        MutableQuantiles[] mutableQuantiles =
+            new MutableQuantiles[intervals.length];
+        quantiles.put(value, mutableQuantiles);
+        for (int i = 0; i < intervals.length; i++) {
+          mutableQuantiles[i] = registry.newQuantiles(
+              value.toString() + "RpcTime" + intervals[i] + "s",
+              value.toString() + "rpc time in milli second",
+              "ops", "latency", intervals[i]);

Review Comment:
   Sorry for not expressing it clearly, I think we can remove the type from the 
Metrics name when we move it to the tag, so the name can be 
`127s90thPercentileLatencyMs`
   ```suggestion
       for (KEY value : values) {
         MetricsRegistry registry = new MetricsRegistry(name + 
"MessageMetrics");
         registries.put(value, registry);
         //...
         if (quantileEnable) {
             mutableQuantiles[i] = registry.newQuantiles(
                 "_" + intervals[i] + "s_",
                 value.toString() + "rpc time in milli second",
                 "ops", "latencyMS", intervals[i]);
   ```
   
   The Metrics name will be like this 
```om_client_protocol_127s_99th_percentile_latency_ms{type="TransferLeadership",hostname="xxx"}
 0
   om_client_protocol_127s_num_ops{type="TransferLeadership",hostname="xxx"}```
   This name is consistent with the original Metrics style and is simpler.
   



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