Copilot commented on code in PR #8758:
URL: https://github.com/apache/hbase/pull/8758#discussion_r4250713813
##########
hbase-website/app/pages/_docs/docs/_mdx/(multi-page)/operational-management/metrics-and-monitoring.mdx:
##########
@@ -133,6 +133,37 @@ The number of regions that have been in transition longer
than a threshold time
**hbase.master.ritOldestAge**
The age of the longest region in transition, in milliseconds
+#### Master switch states
+
+The active, initialized Master exposes numeric switch-state gauges under
+`Hadoop:service=HBase,name=Master,sub=Server`. A value of `1` means enabled and
+`0` means disabled. A value of `-1` means the state is unknown. The gauges are
+absent on backup Masters and before the Master is initialized.
+Enabled states indicate that an operation is permitted, rather than that it is
+currently running.
+
+| Gauge | HBase shell command
|
+| ------------------------------------ |
---------------------------------------------- |
+| `balancerEnabled` | `balance_switch true\|false`
|
+| `normalizerEnabled` | `normalizer_switch true\|false`
|
+| `splitEnabled` | `splitormerge_switch 'SPLIT',
true\|false` |
+| `mergeEnabled` | `splitormerge_switch 'MERGE',
true\|false` |
+| `cleanerChoreEnabled` | `cleaner_chore_switch true\|false`
|
+| `catalogJanitorEnabled` | `catalogjanitor_switch true\|false`
|
+| `snapshotCleanupEnabled` | `snapshot_cleanup_switch true\|false`
|
+| `replicationPeerModificationEnabled` | `peer_modification_switch
true\|false` |
Review Comment:
The backslash escapes (`\\|`) are inside inline code spans, where the
backslash typically renders literally, so the docs will show `true\\|false`
instead of `true|false`. Consider removing the backslashes inside the code
spans (and, if needed for table parsing, escape the pipe outside the code span
or use an HTML entity).
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterSwitchMetrics.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.CompatibilityFactory;
+import org.apache.hadoop.hbase.client.MasterSwitchType;
+import org.apache.hadoop.hbase.master.snapshot.SnapshotCleanupStateStore;
+import org.apache.hadoop.hbase.metrics.MetricRegistries;
+import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
+import org.apache.hadoop.hbase.quotas.QuotaUtil;
+import org.apache.hadoop.hbase.quotas.RpcThrottleStateStore;
+import org.apache.hadoop.hbase.test.MetricsAssertHelper;
+import org.apache.hadoop.hbase.testclassification.MasterTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+@Tag(MasterTests.TAG)
+@Tag(SmallTests.TAG)
+public class TestMasterSwitchMetrics {
+ private static final MetricsAssertHelper METRICS_HELPER =
+ CompatibilityFactory.getInstance(MetricsAssertHelper.class);
+
+ private HMaster master;
+ private Configuration conf;
+ private RpcThrottleStateStore rpcThrottleStateStore;
+ private MetricsMasterWrapperImpl wrapper;
+ private MetricsMasterSourceImpl source;
+
+ @BeforeEach
+ public void setUp() {
+ master = mock(HMaster.class);
+ conf = new Configuration(false);
+ conf.setBoolean(QuotaUtil.QUOTA_CONF_KEY, true);
+ when(master.getConfiguration()).thenReturn(conf);
+ when(master.isActiveMaster()).thenReturn(true);
+ when(master.isInitialized()).thenReturn(true);
+
when(master.getMasterWalManager()).thenReturn(mock(MasterWalManager.class));
+
when(master.getMasterQuotaManager()).thenReturn(mock(MasterQuotaManager.class));
+ master.snapshotCleanupStateStore = mock(SnapshotCleanupStateStore.class);
+ rpcThrottleStateStore = mock(RpcThrottleStateStore.class);
+ when(master.getRpcThrottleStateStore()).thenReturn(rpcThrottleStateStore);
+ wrapper = new MetricsMasterWrapperImpl(master);
+ source = new MetricsMasterSourceImpl(wrapper);
+ }
+
+ @AfterEach
+ public void tearDown() {
+
DefaultMetricsSystem.instance().unregisterSource(MetricsMasterSource.METRICS_JMX_CONTEXT);
+ MetricRegistries.global().remove(source.getMetricRegistryInfo());
+ }
+
+ @Test
+ public void testEachSwitchChangesItsGauge() {
+ Map<String, Consumer<Boolean>> switches = new HashMap<>();
+ switches.put("balancerEnabled", enabled ->
when(master.isBalancerOn()).thenReturn(enabled));
+ switches.put("normalizerEnabled", enabled ->
when(master.isNormalizerOn()).thenReturn(enabled));
+ switches.put("splitEnabled",
+ enabled ->
when(master.isSplitOrMergeEnabled(MasterSwitchType.SPLIT)).thenReturn(enabled));
+ switches.put("mergeEnabled",
+ enabled ->
when(master.isSplitOrMergeEnabled(MasterSwitchType.MERGE)).thenReturn(enabled));
+ switches.put("cleanerChoreEnabled",
+ enabled -> when(master.isCleanerChoreEnabled()).thenReturn(enabled));
+ switches.put("catalogJanitorEnabled",
+ enabled -> when(master.isCatalogJanitorEnabled()).thenReturn(enabled));
+ switches.put("snapshotCleanupEnabled",
+ enabled ->
when(master.snapshotCleanupStateStore.get()).thenReturn(enabled));
+ switches.put("replicationPeerModificationEnabled",
+ enabled ->
when(master.isReplicationPeerModificationEnabled()).thenReturn(enabled));
+ switches.put("rpcThrottleEnabled",
+ enabled -> when(rpcThrottleStateStore.get()).thenReturn(enabled));
+ Map<String, Integer> expected = new HashMap<>();
+ switches.keySet().forEach(name -> expected.put(name, 0));
+ for (Map.Entry<String, Consumer<Boolean>> entry : switches.entrySet()) {
+ for (boolean enabled : new boolean[] { true, false }) {
+ entry.getValue().accept(enabled);
+ expected.put(entry.getKey(), enabled ? 1 : 0);
+ assertEquals(expected, wrapper.getSwitchStates());
+ expected
+ .forEach((name, state) -> METRICS_HELPER.assertGauge(name,
state.longValue(), source));
+ }
+ }
+ verifyNoInteractions(master.getMasterQuotaManager());
Review Comment:
`verifyNoInteractions(master.getMasterQuotaManager())` calls
`getMasterQuotaManager()` as part of the verification statement, which makes
the intent slightly harder to read and couples the check to the stubbing.
Prefer storing the quota manager mock in a local field/variable in `setUp()`
(e.g., `MasterQuotaManager quotaManager = ...`) and then verifying
`verifyNoInteractions(quotaManager)`.
##########
hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterSwitchMetrics.java:
##########
@@ -0,0 +1,137 @@
+/*
+ * 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;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.CompatibilityFactory;
+import org.apache.hadoop.hbase.client.MasterSwitchType;
+import org.apache.hadoop.hbase.master.snapshot.SnapshotCleanupStateStore;
+import org.apache.hadoop.hbase.metrics.MetricRegistries;
+import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
+import org.apache.hadoop.hbase.quotas.QuotaUtil;
+import org.apache.hadoop.hbase.quotas.RpcThrottleStateStore;
+import org.apache.hadoop.hbase.test.MetricsAssertHelper;
+import org.apache.hadoop.hbase.testclassification.MasterTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+@Tag(MasterTests.TAG)
+@Tag(SmallTests.TAG)
+public class TestMasterSwitchMetrics {
+ private static final MetricsAssertHelper METRICS_HELPER =
+ CompatibilityFactory.getInstance(MetricsAssertHelper.class);
+
+ private HMaster master;
+ private Configuration conf;
+ private RpcThrottleStateStore rpcThrottleStateStore;
+ private MetricsMasterWrapperImpl wrapper;
+ private MetricsMasterSourceImpl source;
+
+ @BeforeEach
+ public void setUp() {
+ master = mock(HMaster.class);
+ conf = new Configuration(false);
+ conf.setBoolean(QuotaUtil.QUOTA_CONF_KEY, true);
+ when(master.getConfiguration()).thenReturn(conf);
+ when(master.isActiveMaster()).thenReturn(true);
+ when(master.isInitialized()).thenReturn(true);
+
when(master.getMasterWalManager()).thenReturn(mock(MasterWalManager.class));
+
when(master.getMasterQuotaManager()).thenReturn(mock(MasterQuotaManager.class));
+ master.snapshotCleanupStateStore = mock(SnapshotCleanupStateStore.class);
+ rpcThrottleStateStore = mock(RpcThrottleStateStore.class);
+ when(master.getRpcThrottleStateStore()).thenReturn(rpcThrottleStateStore);
+ wrapper = new MetricsMasterWrapperImpl(master);
+ source = new MetricsMasterSourceImpl(wrapper);
+ }
+
+ @AfterEach
+ public void tearDown() {
+
DefaultMetricsSystem.instance().unregisterSource(MetricsMasterSource.METRICS_JMX_CONTEXT);
+ MetricRegistries.global().remove(source.getMetricRegistryInfo());
+ }
+
+ @Test
+ public void testEachSwitchChangesItsGauge() {
+ Map<String, Consumer<Boolean>> switches = new HashMap<>();
+ switches.put("balancerEnabled", enabled ->
when(master.isBalancerOn()).thenReturn(enabled));
+ switches.put("normalizerEnabled", enabled ->
when(master.isNormalizerOn()).thenReturn(enabled));
+ switches.put("splitEnabled",
+ enabled ->
when(master.isSplitOrMergeEnabled(MasterSwitchType.SPLIT)).thenReturn(enabled));
+ switches.put("mergeEnabled",
+ enabled ->
when(master.isSplitOrMergeEnabled(MasterSwitchType.MERGE)).thenReturn(enabled));
+ switches.put("cleanerChoreEnabled",
+ enabled -> when(master.isCleanerChoreEnabled()).thenReturn(enabled));
+ switches.put("catalogJanitorEnabled",
+ enabled -> when(master.isCatalogJanitorEnabled()).thenReturn(enabled));
+ switches.put("snapshotCleanupEnabled",
+ enabled ->
when(master.snapshotCleanupStateStore.get()).thenReturn(enabled));
+ switches.put("replicationPeerModificationEnabled",
+ enabled ->
when(master.isReplicationPeerModificationEnabled()).thenReturn(enabled));
+ switches.put("rpcThrottleEnabled",
Review Comment:
The test hard-codes metric names as string literals. To reduce brittleness
and ensure refactors don’t silently break tests/docs alignment, consider using
the constants added in `MetricsMasterSource` (e.g.,
`MetricsMasterSource.BALANCER_ENABLED_NAME`, etc.) for these keys.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]