From 9785f5d1c9cbe74819020886cf17efdf8db3bf4f Mon Sep 17 00:00:00 2001 From: gkanade Date: Sat, 2 May 2020 00:15:16 +0530 Subject: [PATCH] HBASE-24199 Procedure related metrics is not consumed in the JMX metric (#1616) Signed-off-by: stack --- .../master/MetricsAssignmentManagerSourceImpl.java | 11 +++++++++++ .../hbase/master/MetricsMasterProcSourceImpl.java | 3 +++ .../hadoop/hbase/master/MetricsMasterSourceImpl.java | 3 +++ .../hbase/master/TestAssignmentManagerMetrics.java | 2 ++ .../hbase/master/TestClusterRestartFailover.java | 9 +++++++++ .../apache/hadoop/hbase/master/TestMasterMetrics.java | 3 +++ 6 files changed, 31 insertions(+) diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java index 8b28d7eaafe..e8bc67825d9 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsAssignmentManagerSourceImpl.java @@ -21,6 +21,8 @@ package org.apache.hadoop.hbase.master; import org.apache.hadoop.hbase.metrics.BaseSourceImpl; import org.apache.hadoop.hbase.metrics.OperationMetrics; import org.apache.hadoop.metrics2.MetricHistogram; +import org.apache.hadoop.metrics2.MetricsCollector; +import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.lib.MutableFastCounter; import org.apache.hadoop.metrics2.lib.MutableGaugeLong; import org.apache.yetus.audience.InterfaceAudience; @@ -157,4 +159,13 @@ public class MetricsAssignmentManagerSourceImpl public OperationMetrics getCloseMetrics() { return closeMetrics; } + + @Override + public void getMetrics(MetricsCollector metricsCollector, boolean all) { + MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName); + metricsRegistry.snapshot(metricsRecordBuilder, all); + if(metricsAdapter != null) { + metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder); + } + } } diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterProcSourceImpl.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterProcSourceImpl.java index c51cd10d95a..69e7d7958fa 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterProcSourceImpl.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterProcSourceImpl.java @@ -70,6 +70,9 @@ public class MetricsMasterProcSourceImpl } metricsRegistry.snapshot(metricsRecordBuilder, all); + if(metricsAdapter != null) { + metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder); + } } } diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java index 8163050fa1c..62f3e5cc089 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSourceImpl.java @@ -126,6 +126,9 @@ public class MetricsMasterSourceImpl } metricsRegistry.snapshot(metricsRecordBuilder, all); + if(metricsAdapter != null) { + metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder); + } } @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.java index 6103de075af..c1e16bec9af 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.java @@ -161,6 +161,8 @@ public class TestAssignmentManagerMetrics { METRICS_HELPER.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_NAME, 1, amSource); METRICS_HELPER.assertGauge(MetricsAssignmentManagerSource.RIT_COUNT_OVER_THRESHOLD_NAME, 1, amSource); + METRICS_HELPER.assertCounter(MetricsAssignmentManagerSource.ASSIGN_METRIC_PREFIX + + "SubmittedCount", 2, amSource); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailover.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailover.java index 1cce2acf9a9..fb5a778e290 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailover.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailover.java @@ -29,6 +29,7 @@ import java.util.concurrent.CountDownLatch; import java.util.stream.Collectors; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.CompatibilityFactory; import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.StartMiniClusterOption; @@ -41,6 +42,7 @@ import org.apache.hadoop.hbase.master.assignment.ServerStateNode; import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure; import org.apache.hadoop.hbase.procedure2.Procedure; import org.apache.hadoop.hbase.regionserver.HRegionServer; +import org.apache.hadoop.hbase.test.MetricsAssertHelper; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.JVMClusterUtil; @@ -59,6 +61,8 @@ public class TestClusterRestartFailover extends AbstractTestRestartCluster { HBaseClassTestRule.forClass(TestClusterRestartFailover.class); private static final Logger LOG = LoggerFactory.getLogger(TestClusterRestartFailover.class); + private static final MetricsAssertHelper metricsHelper = + CompatibilityFactory.getInstance(MetricsAssertHelper.class); private volatile static CountDownLatch SCP_LATCH; private static ServerName SERVER_FOR_TEST; @@ -136,6 +140,11 @@ public class TestClusterRestartFailover extends AbstractTestRestartCluster { serverNode = UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates() .getServerNode(SERVER_FOR_TEST); assertNull("serverNode should be deleted after SCP finished", serverNode); + + MetricsMasterSource masterSource = UTIL.getHBaseCluster().getMaster().getMasterMetrics() + .getMetricsSource(); + metricsHelper.assertCounter(MetricsMasterSource.SERVER_CRASH_METRIC_PREFIX+"SubmittedCount", + 4, masterSource); } private void setupCluster() throws Exception { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java index 75d9ee199b9..2208dd0d197 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java @@ -141,6 +141,9 @@ public class TestMasterMetrics { metricsHelper.assertTag("serverName", master.getServerName().toString(), masterSource); metricsHelper.assertTag("clusterId", master.getClusterId(), masterSource); metricsHelper.assertTag("zookeeperQuorum", master.getZooKeeper().getQuorum(), masterSource); + + metricsHelper.assertCounter(MetricsMasterSource.SERVER_CRASH_METRIC_PREFIX+"SubmittedCount", + 0, masterSource); } @Test