HBASE-20857 balancer status tag in jmx metrics
Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
209d0a8a16
commit
b7c2b953bc
|
@ -41,6 +41,7 @@ public interface MetricsBalancerSource extends BaseSource {
|
|||
|
||||
String BALANCE_CLUSTER = "balancerCluster";
|
||||
String MISC_INVOATION_COUNT = "miscInvocationCount";
|
||||
String BALANCER_STATUS = "isBalancerActive";
|
||||
|
||||
/**
|
||||
* Description
|
||||
|
@ -50,4 +51,6 @@ public interface MetricsBalancerSource extends BaseSource {
|
|||
void updateBalanceCluster(long time);
|
||||
|
||||
void incrMiscInvocations();
|
||||
|
||||
void updateBalancerStatus(boolean status);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ public class MetricsBalancerSourceImpl extends BaseSourceImpl implements Metrics
|
|||
String metricsDescription,
|
||||
String metricsContext, String metricsJmxContext) {
|
||||
super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
|
||||
updateBalancerStatus(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,4 +54,9 @@ public class MetricsBalancerSourceImpl extends BaseSourceImpl implements Metrics
|
|||
public void incrMiscInvocations() {
|
||||
miscCount.incr();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBalancerStatus(boolean status) {
|
||||
metricsRegistry.tag(BALANCER_STATUS,"", String.valueOf(status), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -473,4 +473,8 @@ public class RSGroupBasedLoadBalancer implements RSGroupableBalancer {
|
|||
public void postMasterStartupInitialize() {
|
||||
this.internalBalancer.postMasterStartupInitialize();
|
||||
}
|
||||
|
||||
public void updateBalancerStatus(boolean status) {
|
||||
internalBalancer.updateBalancerStatus(status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,6 +164,9 @@ public interface LoadBalancer extends Configurable, Stoppable, ConfigurationObse
|
|||
*/
|
||||
void postMasterStartupInitialize();
|
||||
|
||||
/*Updates balancer status tag reported to JMX*/
|
||||
void updateBalancerStatus(boolean status);
|
||||
|
||||
/**
|
||||
* @return true if Master carries regions
|
||||
*/
|
||||
|
|
|
@ -419,6 +419,7 @@ public class MasterRpcServices extends RSRpcServices
|
|||
if (master.cpHost != null) {
|
||||
master.cpHost.postBalanceSwitch(oldValue, newValue);
|
||||
}
|
||||
master.getLoadBalancer().updateBalancerStatus(newValue);
|
||||
} catch (IOException ioe) {
|
||||
LOG.warn("Error flipping balance switch", ioe);
|
||||
}
|
||||
|
|
|
@ -1552,6 +1552,13 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
|||
stopped = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the balancer status tag reported to JMX
|
||||
*/
|
||||
public void updateBalancerStatus(boolean status) {
|
||||
metricsBalancer.balancerStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to assign a single region to a random server.
|
||||
*/
|
||||
|
|
|
@ -48,4 +48,8 @@ public class MetricsBalancer {
|
|||
public void incrMiscInvocations() {
|
||||
source.incrMiscInvocations();
|
||||
}
|
||||
|
||||
public void balancerStatus(boolean status) {
|
||||
source.updateBalancerStatus(status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,14 @@ public class MetricsStochasticBalancer extends MetricsBalancer {
|
|||
stochasticSource.incrMiscInvocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the balancer status tag reported to JMX
|
||||
*/
|
||||
@Override
|
||||
public void balancerStatus(boolean status) {
|
||||
stochasticSource.updateBalancerStatus(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the number of metrics reported to JMX
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
|
||||
* agreements. See the NOTICE file distributed with this work for additional information regarding
|
||||
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License. You may obtain a
|
||||
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
|
||||
* law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
|
||||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.hbase.master.balancer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.MiniHBaseCluster;
|
||||
import org.apache.hadoop.hbase.master.HMaster;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.metrics2.MetricsSource;
|
||||
import org.apache.hadoop.metrics2.MetricsTag;
|
||||
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category({ MediumTests.class })
|
||||
public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestBalancerStatusTagInJMXMetrics.class);
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(TestBalancerStatusTagInJMXMetrics.class);
|
||||
private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
|
||||
private static int connectorPort = 61120;
|
||||
private static HMaster master;
|
||||
private static MiniHBaseCluster cluster;
|
||||
private static Configuration conf = null;
|
||||
|
||||
/**
|
||||
* Setup the environment for the test.
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setupBeforeClass() throws Exception {
|
||||
|
||||
conf = UTIL.getConfiguration();
|
||||
Random rand = new Random();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
do {
|
||||
int sign = i % 2 == 0 ? 1 : -1;
|
||||
connectorPort += sign * rand.nextInt(100);
|
||||
} while (!HBaseTestingUtility.available(connectorPort));
|
||||
try {
|
||||
conf.setInt("regionserver.rmi.registry.port", connectorPort);
|
||||
cluster = UTIL.startMiniCluster();
|
||||
LOG.info("Waiting for active/ready master");
|
||||
cluster.waitForActiveAndReadyMaster();
|
||||
master = cluster.getMaster();
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
LOG.debug("Encountered exception when starting mini cluster. Trying port " + connectorPort,
|
||||
e);
|
||||
try {
|
||||
// this is to avoid "IllegalStateException: A mini-cluster is already running"
|
||||
UTIL.shutdownMiniCluster();
|
||||
} catch (Exception ex) {
|
||||
LOG.debug("Encountered exception shutting down cluster", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the status change using the Default Metrics System
|
||||
*/
|
||||
@Test
|
||||
public void testJmxMetrics() throws Exception {
|
||||
|
||||
assertEquals(getStatus(), "true");
|
||||
master.getLoadBalancer().updateBalancerStatus(false);
|
||||
assertEquals(getStatus(), "false");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the balancer status tag from the Metrics registry
|
||||
*/
|
||||
public String getStatus() throws Exception {
|
||||
MetricsSource source =
|
||||
DefaultMetricsSystem.instance().getSource(MetricsBalancerSource.METRICS_JMX_CONTEXT);
|
||||
if (source instanceof MetricsBalancerSourceImpl) {
|
||||
MetricsTag status = ((MetricsBalancerSourceImpl) source).getMetricsRegistry()
|
||||
.getTag(MetricsBalancerSource.BALANCER_STATUS);
|
||||
return status.value();
|
||||
} else {
|
||||
LOG.warn("Balancer JMX Metrics not registered");
|
||||
throw new Exception("MetricsBalancer JMX Context not found");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue