[ 
https://issues.apache.org/jira/browse/HADOOP-18364?focusedWorklogId=795082&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-795082
 ]

ASF GitHub Bot logged work on HADOOP-18364:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Jul/22 23:34
            Start Date: 25/Jul/22 23:34
    Worklog Time Spent: 10m 
      Work Description: xkrogen commented on code in PR #4624:
URL: https://github.com/apache/hadoop/pull/4624#discussion_r929389912


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java:
##########
@@ -71,11 +74,20 @@ public void init(Class<?> protocol) {
     if (protocolCache.contains(protocol)) {
       return;
     }
-    protocolCache.add(protocol);
-    for (Method method : protocol.getDeclaredMethods()) {
-      String name = method.getName();
-      LOG.debug(name);
-      addMetricIfNotExists(name);
+
+    List<Class<?>> protocols = new ArrayList<>();
+    protocols.add(protocol);
+    if (protocol.getDeclaredMethods().length == 0) {
+      protocols.addAll(Arrays.asList(protocol.getInterfaces()));
+    }
+
+    for (Class<?> pClass : protocols) {
+      protocolCache.add(pClass);
+      for (Method method : pClass.getDeclaredMethods()) {
+        String name = method.getName();
+        LOG.debug(name);
+        addMetricIfNotExists(name);
+      }

Review Comment:
   Seems we can fix this much more simply by just using 
[getMethods()](https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethods--)
 which includes inherited methods. The main difference is that we'll only get 
public methods, not private/package-private, but I don't think we have any use 
cases which need those methods anyway. This is focused on protocol classes for 
which we only need the public methods.
   
   ```suggestion
       protocolCache.add(protocol);
       for (Method method : protocol.getMethods()) {
         String name = method.getName();
         LOG.debug(name);
         addMetricIfNotExists(name);
   ```





Issue Time Tracking
-------------------

    Worklog Id:     (was: 795082)
    Time Spent: 0.5h  (was: 20m)

> All method metrics related to the rpc protocol should be initialized
> --------------------------------------------------------------------
>
>                 Key: HADOOP-18364
>                 URL: https://issues.apache.org/jira/browse/HADOOP-18364
>             Project: Hadoop Common
>          Issue Type: Bug
>            Reporter: Shuyan Zhang
>            Assignee: Shuyan Zhang
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> When an RPC protocol is used, the metric of protocol-related methods should 
> be initialized; otherwise, metric information will be incomplete. For 
> example, when we call HAServiceProtocol#monitorHealth(), only the metric of 
> monitorHealth() are initialized, and the metric of transitionToStandby() are 
> still not reported. This incompleteness caused a little trouble for our 
> monitoring system.
> The root cause is that the parameter passed by RpcEngine to 
> MutableRatesWithAggregation#init(java.lang.Class<?>)  is always 
> XXXProtocolPB, which is inherited from BlockingInterface and does not 
> implement any methods. We should fix this bug.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to