szetszwo commented on code in PR #742:
URL: https://github.com/apache/ratis/pull/742#discussion_r972075506


##########
ratis-grpc/src/main/java/org/apache/ratis/grpc/metrics/MessageMetrics.java:
##########
@@ -17,49 +17,71 @@
  */
 package org.apache.ratis.grpc.metrics;
 
+import org.apache.ratis.metrics.LongCounter;
 import org.apache.ratis.metrics.MetricRegistryInfo;
 import org.apache.ratis.metrics.RatisMetrics;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import java.util.Map;
 
 public class MessageMetrics extends RatisMetrics {
-  static final Logger LOG = LoggerFactory.getLogger(MessageMetrics.class);
   public static final String GRPC_MESSAGE_METRICS = "%s_message_metrics";
   public static final String GRPC_MESSAGE_METRICS_DESC = "Outbound/Inbound 
message counters";
 
+  private enum Type {
+    STARTED("_started_total"),
+    COMPLETED("_completed_total"),
+    RECEIVED("_received_executed");
+
+    private final String suffix;
+
+    Type(String suffix) {
+      this.suffix = suffix;
+    }
+
+    String getSuffix() {
+      return suffix;
+    }
+  }
+
+  private final Map<Type, Map<String, LongCounter>> types;
+
   public MessageMetrics(String endpointId, String endpointType) {
-    this.registry = create(
+    super(create(
         new MetricRegistryInfo(endpointId,
             RATIS_APPLICATION_NAME_METRICS,
             String.format(GRPC_MESSAGE_METRICS, endpointType),
             GRPC_MESSAGE_METRICS_DESC)
-    );
+    ));
+
+    this.types = newCounterMaps(Type.class);
+  }
+
+  private void inc(Type t, String rpcType) {
+    types.get(t)
+        .computeIfAbsent(rpcType, key -> getRegistry().counter(key + 
t.getSuffix()))
+        .inc();
   }
 
   /**
    * Increments the count of RPCs that are started.
    * Both client and server use this.
-   * @param rpcType
    */
   public void rpcStarted(String rpcType){

Review Comment:
   Let's use `metricNamePrefix` since the callers (e.g. `MetricClientCall`) use 
i.



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

Reply via email to