From 830d2895b27fa0cf39a28d3af9673a4126ea8258 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Thu, 4 Mar 2021 12:47:57 +0530 Subject: [PATCH] HBASE-25460 : Expose drainingServers as cluster metric (#2995) Signed-off-by: Viraj Jasani --- .../hbase/master/MetricsMasterSource.java | 4 ++++ .../hbase/master/MetricsMasterSourceImpl.java | 4 ++++ .../hbase/master/MetricsMasterWrapper.java | 14 ++++++++++++++ .../hbase/master/MetricsMasterWrapperImpl.java | 18 ++++++++++++++++++ .../hadoop/hbase/master/TestMasterMetrics.java | 1 + 5 files changed, 41 insertions(+) diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSource.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSource.java index f947a3acb9c..71eb1b26ff6 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSource.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterSource.java @@ -55,8 +55,10 @@ public interface MetricsMasterSource extends BaseSource { String AVERAGE_LOAD_NAME = "averageLoad"; String LIVE_REGION_SERVERS_NAME = "liveRegionServers"; String DEAD_REGION_SERVERS_NAME = "deadRegionServers"; + String DRAINING_REGION_SERVER_NAME = "draininigRegionServers"; String NUM_REGION_SERVERS_NAME = "numRegionServers"; String NUM_DEAD_REGION_SERVERS_NAME = "numDeadRegionServers"; + String NUM_DRAINING_REGION_SERVERS_NAME = "numDrainingRegionServers"; String ZOOKEEPER_QUORUM_NAME = "zookeeperQuorum"; String SERVER_NAME_NAME = "serverName"; String CLUSTER_ID_NAME = "clusterId"; @@ -76,6 +78,8 @@ public interface MetricsMasterSource extends BaseSource { String NUMBER_OF_REGION_SERVERS_DESC = "Number of RegionServers"; String DEAD_REGION_SERVERS_DESC = "Names of dead RegionServers"; String NUMBER_OF_DEAD_REGION_SERVERS_DESC = "Number of dead RegionServers"; + String DRAINING_REGION_SERVER_DESC = "Names of draining RegionServers"; + String NUMBER_OF_DRAINING_REGION_SERVERS_DESC = "Number of draining RegionServers"; String ZOOKEEPER_QUORUM_DESC = "ZooKeeper Quorum"; String SERVER_NAME_DESC = "Server Name"; String CLUSTER_ID_DESC = "Cluster Id"; 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 62f3e5cc089..dacb7a5aa20 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 @@ -117,6 +117,10 @@ public class MetricsMasterSourceImpl .addGauge(Interns.info(NUM_DEAD_REGION_SERVERS_NAME, NUMBER_OF_DEAD_REGION_SERVERS_DESC), masterWrapper.getNumDeadRegionServers()) + .tag(Interns.info(DRAINING_REGION_SERVER_NAME, DRAINING_REGION_SERVER_DESC), + masterWrapper.getDrainingRegionServers()) + .addGauge(Interns.info(NUM_DRAINING_REGION_SERVERS_NAME, NUMBER_OF_REGION_SERVERS_DESC), + masterWrapper.getNumDrainingRegionServers()) .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC), masterWrapper.getZookeeperQuorum()) .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), masterWrapper.getServerName()) diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapper.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapper.java index 77b357f315e..1b3a75c3b84 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapper.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapper.java @@ -118,6 +118,20 @@ public interface MetricsMasterWrapper { */ int getNumDeadRegionServers(); + /** + * Get the draining region servers + * + * @return Draining region server + */ + String getDrainingRegionServers(); + + /** + * Get the number of draining region servers + * + * @return number of draining region servers + */ + int getNumDrainingRegionServers(); + /** * Get the number of master WAL files. */ diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapperImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapperImpl.java index aeaae929209..e03c4df3aa3 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapperImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MetricsMasterWrapperImpl.java @@ -138,6 +138,24 @@ public class MetricsMasterWrapperImpl implements MetricsMasterWrapper { return !(master.isStopped() || master.isStopping()); } + @Override + public String getDrainingRegionServers() { + ServerManager serverManager = this.master.getServerManager(); + if (serverManager == null) { + return ""; + } + return StringUtils.join(serverManager.getDrainingServersList() , ";"); + } + + @Override + public int getNumDrainingRegionServers() { + ServerManager serverManager = this.master.getServerManager(); + if (serverManager == null) { + return 0; + } + return serverManager.getDrainingServersList().size(); + } + @Override public String getServerName() { ServerName serverName = master.getServerName(); 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 2208dd0d197..780be02a974 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 @@ -133,6 +133,7 @@ public class TestMasterMetrics { metricsHelper.assertGauge("numRegionServers", 1 + (tablesOnMaster ? 1 : 0), masterSource); metricsHelper.assertGauge("averageLoad", 1, masterSource); metricsHelper.assertGauge("numDeadRegionServers", 0, masterSource); + metricsHelper.assertGauge("numDrainingRegionServers", 0, masterSource); metricsHelper.assertGauge("masterStartTime", master.getMasterStartTime(), masterSource); metricsHelper.assertGauge("masterActiveTime", master.getMasterActiveTime(), masterSource);