From dbf73e16b1ea91b1de3dc96fa65481f03fd58bca Mon Sep 17 00:00:00 2001 From: zhangshuyan0 <81411509+zhangshuyan0@users.noreply.github.com> Date: Thu, 4 Aug 2022 13:00:37 +0800 Subject: [PATCH] HADOOP-18364. All method metrics related to the RPC protocol should be initialized. (#4624). Contributed by Shuyan Zhang. Reviewed-by: Erik Krogen Reviewed-by: Chao Sun Signed-off-by: He Xiaoqiao --- .../metrics2/lib/MutableRatesWithAggregation.java | 2 +- .../namenode/metrics/TestNameNodeMetrics.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java index 4c5f0a844aa..60b33a84b51 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableRatesWithAggregation.java @@ -72,7 +72,7 @@ public class MutableRatesWithAggregation extends MutableMetric { return; } protocolCache.add(protocol); - for (Method method : protocol.getDeclaredMethods()) { + for (Method method : protocol.getMethods()) { String name = method.getName(); LOG.debug(name); addMetricIfNotExists(name); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java index aaedb8288e4..4d472d74b46 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/metrics/TestNameNodeMetrics.java @@ -48,6 +48,9 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.List; import java.util.Random; + +import org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer; +import org.apache.hadoop.ipc.metrics.RpcDetailedMetrics; import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableList; import org.slf4j.Logger; @@ -1128,4 +1131,14 @@ public class TestNameNodeMetrics { } } + + @Test + public void testNNRPCMetricIntegrity() { + RpcDetailedMetrics metrics = + ((NameNodeRpcServer) cluster.getNameNode() + .getRpcServer()).getClientRpcServer().getRpcDetailedMetrics(); + MetricsRecordBuilder rb = getMetrics(metrics.name()); + // CommitBlockSynchronizationNumOps should exist. + assertCounter("CommitBlockSynchronizationNumOps", 0L, rb); + } }