Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public interface MetricsMasterSource extends BaseSource {

String CLUSTER_REQUESTS_NAME = "clusterRequests";
String OLD_WAL_DIR_SIZE_NAME = "oldWALsDirSize";
String BALANCER_ENABLED_NAME = "balancerEnabled";
String NORMALIZER_ENABLED_NAME = "normalizerEnabled";
String SPLIT_ENABLED_NAME = "splitEnabled";
String MERGE_ENABLED_NAME = "mergeEnabled";
String CLEANER_CHORE_ENABLED_NAME = "cleanerChoreEnabled";
String CATALOG_JANITOR_ENABLED_NAME = "catalogJanitorEnabled";
String SNAPSHOT_CLEANUP_ENABLED_NAME = "snapshotCleanupEnabled";
String REPLICATION_PEER_MODIFICATION_ENABLED_NAME = "replicationPeerModificationEnabled";
String RPC_THROTTLE_ENABLED_NAME = "rpcThrottleEnabled";
String SWITCH_STATE_DESC = "Switch state: 1 enabled, 0 disabled";
String MASTER_ACTIVE_TIME_DESC = "Master Active Time";
String MASTER_START_TIME_DESC = "Master Start Time";
String MASTER_FINISHED_INITIALIZATION_TIME_DESC =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,11 @@ public interface MetricsMasterWrapper {
* Get the size of old WALs directory in bytes.
*/
long getOldWALsDirSize();

/**
* Returns known switch states (1 enabled, 0 disabled), or an empty map unless this Master is
* active and initialized. Unavailable states are omitted. Implementations must not perform remote
* reads.
*/
Map<String, Integer> getSwitchStates();
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
String.valueOf(masterWrapper.getIsActiveMaster()))
.addGauge(Interns.info(OLD_WAL_DIR_SIZE_NAME, OLD_WAL_DIR_SIZE_DESC),
masterWrapper.getOldWALsDirSize());

masterWrapper.getSwitchStates().forEach((name, state) -> metricsRecordBuilder
.addGauge(Interns.info(name, SWITCH_STATE_DESC), state));
}

metricsRegistry.snapshot(metricsRecordBuilder, all);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.MasterSwitchType;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
import org.apache.hadoop.hbase.procedure2.Procedure;
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
import org.apache.hadoop.hbase.quotas.QuotaObserverChore;
import org.apache.hadoop.hbase.quotas.QuotaUtil;
import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
Expand Down Expand Up @@ -238,4 +241,34 @@ public long getOldWALsDirSize() {
}
return master.getMasterWalManager().getOldWALsDirSize();
}

@Override
public Map<String, Integer> getSwitchStates() {
if (!master.isActiveMaster() || !master.isInitialized()) {
return Collections.emptyMap();
}
Map<String, Integer> states = new HashMap<>();
states.put(MetricsMasterSource.BALANCER_ENABLED_NAME, master.isBalancerOn() ? 1 : 0);
states.put(MetricsMasterSource.NORMALIZER_ENABLED_NAME, master.isNormalizerOn() ? 1 : 0);
states.put(MetricsMasterSource.SPLIT_ENABLED_NAME,
master.isSplitOrMergeEnabled(MasterSwitchType.SPLIT) ? 1 : 0);
states.put(MetricsMasterSource.MERGE_ENABLED_NAME,
master.isSplitOrMergeEnabled(MasterSwitchType.MERGE) ? 1 : 0);
states.put(MetricsMasterSource.CLEANER_CHORE_ENABLED_NAME,
master.isCleanerChoreEnabled() ? 1 : 0);
states.put(MetricsMasterSource.CATALOG_JANITOR_ENABLED_NAME,
master.isCatalogJanitorEnabled() ? 1 : 0);
states.put(MetricsMasterSource.SNAPSHOT_CLEANUP_ENABLED_NAME,
master.snapshotCleanupStateStore.get() ? 1 : 0);
states.put(MetricsMasterSource.REPLICATION_PEER_MODIFICATION_ENABLED_NAME,
master.isReplicationPeerModificationEnabled() ? 1 : 0);
MasterQuotaManager quotaManager = master.getMasterQuotaManager();
if (quotaManager != null) {
states.put(MetricsMasterSource.RPC_THROTTLE_ENABLED_NAME,
quotaManager.isRpcThrottleEnabled() ? 1 : 0);
} else if (!QuotaUtil.isQuotaEnabled(master.getConfiguration())) {
states.put(MetricsMasterSource.RPC_THROTTLE_ENABLED_NAME, 0);
}
return states;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public IsRpcThrottleEnabledResponse isRpcThrottleEnabled(IsRpcThrottleEnabledReq
}
}

public boolean isRpcThrottleEnabled() throws IOException {
public boolean isRpcThrottleEnabled() {
return initialized && masterServices.getRpcThrottleStateStore().get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CompatibilityFactory;
import org.apache.hadoop.hbase.HBaseTestingUtility;
Expand All @@ -28,6 +29,7 @@
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.StartMiniClusterOption;
import org.apache.hadoop.hbase.YouAreDeadException;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.regionserver.RSRpcServices;
import org.apache.hadoop.hbase.test.MetricsAssertHelper;
import org.apache.hadoop.hbase.testclassification.MasterTests;
Expand Down Expand Up @@ -121,6 +123,44 @@ public static void after() throws Exception {
}
}

@FunctionalInterface
private interface SwitchSetter {
void accept(boolean enabled) throws IOException;
}

@Test
public void testSwitchMetricsFollowAdminChanges() throws IOException {
Admin admin = TEST_UTIL.getAdmin();
MetricsMasterSource source = master.getMasterMetrics().getMetricsSource();
Map<String, SwitchSetter> switches = new HashMap<>();
switches.put(MetricsMasterSource.BALANCER_ENABLED_NAME,
enabled -> admin.balancerSwitch(enabled, false));
switches.put(MetricsMasterSource.NORMALIZER_ENABLED_NAME, admin::normalizerSwitch);
switches.put(MetricsMasterSource.SPLIT_ENABLED_NAME,
enabled -> admin.splitSwitch(enabled, false));
switches.put(MetricsMasterSource.MERGE_ENABLED_NAME,
enabled -> admin.mergeSwitch(enabled, false));
switches.put(MetricsMasterSource.CLEANER_CHORE_ENABLED_NAME, admin::cleanerChoreSwitch);
switches.put(MetricsMasterSource.CATALOG_JANITOR_ENABLED_NAME, admin::catalogJanitorSwitch);
switches.put(MetricsMasterSource.SNAPSHOT_CLEANUP_ENABLED_NAME,
enabled -> admin.snapshotCleanupSwitch(enabled, false));
switches.put(MetricsMasterSource.REPLICATION_PEER_MODIFICATION_ENABLED_NAME,
admin::replicationPeerModificationSwitch);
Map<String, Integer> initialStates = new MetricsMasterWrapperImpl(master).getSwitchStates();
for (Map.Entry<String, SwitchSetter> entry : switches.entrySet()) {
try {
for (boolean enabled : new boolean[] { false, true }) {
entry.getValue().accept(enabled);
metricsHelper.assertGauge(entry.getKey(), enabled ? 1L : 0L, source);
}
} finally {
entry.getValue().accept(initialStates.get(entry.getKey()) == 1);
}
}
// Quota support is disabled by default.
metricsHelper.assertGauge(MetricsMasterSource.RPC_THROTTLE_ENABLED_NAME, 0L, source);
}

@Test
public void testClusterRequests() throws Exception {
// sending fake request to master to see how metric value has changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@
*/
package org.apache.hadoop.hbase.master;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CompatibilityFactory;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.StartMiniClusterOption;
Expand All @@ -39,6 +44,8 @@
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.quotas.QuotaUtil;
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.Bytes;
Expand Down Expand Up @@ -98,6 +105,33 @@ public void testNewCluster() throws Exception {
}
}

@Test
public void testSwitchMetricsWithQuotasEnabled() throws Exception {
enableMaintenanceMode();
TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true);
TEST_UTIL.startMiniCluster(
StartMiniClusterOption.builder().numRegionServers(0).numDataNodes(1).build());

HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
assertTrue(master.isInMaintenanceMode());
assertNull(master.getMasterQuotaManager());
MetricsMasterSource source = master.getMasterMetrics().getMetricsSource();
MetricsAssertHelper metricsHelper = CompatibilityFactory.getInstance(MetricsAssertHelper.class);
Map<String, Integer> states = new MetricsMasterWrapperImpl(master).getSwitchStates();
assertEquals(8, states.size());
assertFalse(states.containsKey(MetricsMasterSource.RPC_THROTTLE_ENABLED_NAME));
assertFalse(
metricsHelper.checkGaugeExists(MetricsMasterSource.RPC_THROTTLE_ENABLED_NAME, source));
states.forEach((name, state) -> {
assertTrue(state == 0 || state == 1);
metricsHelper.assertGauge(name, state.longValue(), source);
});
metricsHelper.assertGauge(MetricsMasterSource.BALANCER_ENABLED_NAME, 0L, source);
metricsHelper.assertGauge(MetricsMasterSource.NORMALIZER_ENABLED_NAME, 0L, source);
metricsHelper.assertGauge(MetricsMasterSource.SPLIT_ENABLED_NAME, 0L, source);
metricsHelper.assertGauge(MetricsMasterSource.MERGE_ENABLED_NAME, 0L, source);
}

@Test
public void testExistingCluster() throws Exception {
TableName testRepairMode = TableName.valueOf(testMethodName);
Expand Down
Loading
Loading