smengcl commented on code in PR #10941:
URL: https://github.com/apache/ozone/pull/10941#discussion_r4333048825
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/volume/MutableVolumeSet.java:
##########
@@ -361,6 +361,17 @@ public void shutdown() {
}
volumeMap.clear();
+ // Shut down failed volumes too: their VolumeInfoMetrics is registered on
+ // creation (HDDS-7086) and must be unregistered on shutdown.
+ for (StorageVolume volume : failedVolumeMap.values()) {
+ try {
+ volume.shutdown();
+ } catch (Exception ex) {
+ LOG.error("Failed to shutdown failed volume : " +
volume.getStorageDir(), ex);
+ }
+ }
+ failedVolumeMap.clear();
Review Comment:
`failedVolumeMap` also holds volumes failed at runtime by
`failVolume(volumeRoot)`. For those, `shutdown()` saves usage and deletes tmp
and deleted-container files on the failed disk, which can block datanode
shutdown on a hung disk. Maybe only unregister `VolumeInfoMetrics` like:
```suggestion
// Failed volumes keep VolumeInfoMetrics registered (HDDS-7086) while
the datanode runs.
for (StorageVolume volume : failedVolumeMap.values()) {
if (volume instanceof HddsVolume && ((HddsVolume)
volume).getVolumeInfoStats() != null) {
((HddsVolume) volume).getVolumeInfoStats().unregister();
}
}
failedVolumeMap.clear();
```
##########
hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MetricsLeakAssertion.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.ozone;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.apache.hadoop.metrics2.MetricsSource;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * Asserts that no metrics sources remain registered in the
+ * {@link DefaultMetricsSystem} after a mini cluster is shut down.
+ *
+ * <p>Hadoop's {@code MetricsSystemImpl} does not remove registered sources on
+ * {@code stop()} or {@code shutdown()}; a metrics class that forgets to call
+ * {@code unregisterSource(...)} leaks its registration silently. This helper
+ * inspects the private {@code allSources} map via reflection and fails the
+ * test if anything is still registered.
+ */
+public final class MetricsLeakAssertion {
+
+ private static final String ALL_SOURCES_FIELD = "allSources";
+
+ /**
+ * Metrics sources that are registered once per JVM (or once per service)
+ * and intentionally never unregistered, so they are expected to still be
+ * present after a mini cluster shuts down. These are JVM-level singletons
+ * with no per-service owner; do not add per-service metrics here.
+ *
+ * <p>For the matching rules see {@link #isExpectedLeftover(String)}.
+ */
+ private static final List<String> EXPECTED_LEFTOVER_SOURCES = Arrays.asList(
+ "JvmMetrics*", // per service, via HddsServerUtil.initializeMetrics
+ "JvmMetricsCpu",
+ "UgiMetrics", // Hadoop security UGI metrics
+ "ManagedRocksObjectMetrics",
+ "ContainerCacheMetrics" // ContainerCache singleton, created once per JVM
+ );
+
+ /**
+ * Metrics sources that leak: they should be unregistered when the mini
+ * cluster shuts down but currently are not. This is a transitional list to
+ * keep the integration suite green while the leaks are being fixed. Each
+ * entry should be removed once the corresponding source unregisters
+ * properly; do not add new entries, fix the leak instead.
+ *
+ * <p>For the matching rules see {@link #isExpectedLeftover(String)}.
+ */
+ private static final List<String> TODO_LEFTOVER_SOURCES = Arrays.asList(
+ // RPC / HTTP server metrics (name embeds the listening port).
+ "RpcActivityForPort*",
+ "RpcDetailedActivityForPort*",
+ "HttpServer2*",
Review Comment:
Is this needed? This PR gives `HttpServer2Metrics` a per instance name and
`stop()` unregisters it. With this entry, that change is not checked.
##########
hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MetricsLeakAssertion.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.ozone;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.apache.hadoop.metrics2.MetricsSource;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * Asserts that no metrics sources remain registered in the
+ * {@link DefaultMetricsSystem} after a mini cluster is shut down.
+ *
+ * <p>Hadoop's {@code MetricsSystemImpl} does not remove registered sources on
+ * {@code stop()} or {@code shutdown()}; a metrics class that forgets to call
+ * {@code unregisterSource(...)} leaks its registration silently. This helper
+ * inspects the private {@code allSources} map via reflection and fails the
+ * test if anything is still registered.
+ */
+public final class MetricsLeakAssertion {
+
+ private static final String ALL_SOURCES_FIELD = "allSources";
+
+ /**
+ * Metrics sources that are registered once per JVM (or once per service)
+ * and intentionally never unregistered, so they are expected to still be
+ * present after a mini cluster shuts down. These are JVM-level singletons
+ * with no per-service owner; do not add per-service metrics here.
+ *
+ * <p>For the matching rules see {@link #isExpectedLeftover(String)}.
+ */
+ private static final List<String> EXPECTED_LEFTOVER_SOURCES = Arrays.asList(
+ "JvmMetrics*", // per service, via HddsServerUtil.initializeMetrics
+ "JvmMetricsCpu",
+ "UgiMetrics", // Hadoop security UGI metrics
+ "ManagedRocksObjectMetrics",
+ "ContainerCacheMetrics" // ContainerCache singleton, created once per JVM
+ );
+
+ /**
+ * Metrics sources that leak: they should be unregistered when the mini
+ * cluster shuts down but currently are not. This is a transitional list to
+ * keep the integration suite green while the leaks are being fixed. Each
+ * entry should be removed once the corresponding source unregisters
+ * properly; do not add new entries, fix the leak instead.
+ *
+ * <p>For the matching rules see {@link #isExpectedLeftover(String)}.
+ */
+ private static final List<String> TODO_LEFTOVER_SOURCES = Arrays.asList(
+ // RPC / HTTP server metrics (name embeds the listening port).
+ "RpcActivityForPort*",
+ "RpcDetailedActivityForPort*",
+ "HttpServer2*",
+ "LocalJobRunnerMetrics*",
+
+ // Datanode per-instance metrics.
+ "StorageContainerMetrics",
+ "ContainerDataScannerMetrics*", // name embeds the volume path
+ "ContainerMetadataScannerMetrics",
+ "On-demand container scanner metrics",
+ "BackgroundVolumeScannerMetrics",
+ "VolumeHealthMetrics-*",
+ "VolumeIOStats-*", // name embeds the volume path
+ // Name embeds the volume path. Also intentionally kept registered for
+ // failed volumes (HDDS-7086), so only the healthy-volume case is a leak.
+ "VolumeInfoMetrics-*",
+ "CommandHandlerMetrics",
+ "HddsDispatcher",
+ "ECReconstructionMetrics",
+ "ReplicationSupervisorMetrics",
+ "ContainerReplicator/push",
+ "BlockDeletingService",
+ "GrpcMetrics",
+
+ // SCM metrics.
+ "SCMNodeMetrics",
+ "SCMContainerManagerMetrics",
+ "SafeModeMetrics",
+ "ContainerBalancerMetrics",
+ "NodeDecommissionMetrics",
+ "SCMDatanodeProtocol",
+ "ScmBlockLocationProtocol",
+ "ScmContainerLocationProtocol",
+ "ScmSecurityProtocol",
+ "EventQueue*", // per event/handler pair, registered by SCM EventQueue
+
+ // OM metrics.
+ "OMMetrics",
+ "OMPerformanceMetrics",
+ "OMLockMetrics",
+ "OMHAMetrics",
+ "OMSnapshotDirectoryMetrics",
+ "OmSnapshotMetrics",
+ "OmClientProtocol",
+ "DeletingServiceMetrics",
+ "KeyLifecycleServiceMetrics",
+ "BucketUtilizationMetrics",
+ "DelegationTokenSecretManagerMetrics",
+
+ // OM / SCM RocksDB table cache and DB metrics (name embeds path/uuid).
+ "Rocksdb_*",
+ "SSTFilePruningMetrics-*",
+ "DBCheckpointMetrics",
+ "*TableCache",
+
+ // Ratis / third-party infrastructure metrics.
+ "CSMMetricsgroup-*", // Ratis container state machine, embeds a random id
+ "CacheMetrics-*", // Hadoop cache metrics (XceiverClientManager, etc.)
+ "NettyMetrics*",
+ "ContainerClientMetrics1",
+ "ReconTaskMetrics",
+ "ReconTaskControllerMetrics"
+ );
+
+ private MetricsLeakAssertion() {
+ }
+
+ /**
+ * Throws an {@link AssertionError} if any metrics sources are still
+ * registered with the default metrics system, or if the expected
+ * {@code allSources} field cannot be found or read (e.g. a Hadoop version
+ * change restructured {@code MetricsSystemImpl}), so that a broken or
+ * missing check fails loudly instead of going unnoticed.
+ */
+ public static void assertNoLeaks() {
+ try {
+ MetricsSystem ms = DefaultMetricsSystem.instance();
+ Field field = findAllSourcesField(ms.getClass());
+ if (field == null) {
+ throw new AssertionError("Cannot check for metrics leaks: '" +
ALL_SOURCES_FIELD +
+ "' field not found on " + ms.getClass().getName() +
+ ". The metrics system implementation may have changed.");
+ }
+ field.setAccessible(true);
+ Object value = field.get(ms);
+ if (!(value instanceof Map)) {
+ throw new AssertionError("Cannot check for metrics leaks: '" +
ALL_SOURCES_FIELD +
+ "' on " + ms.getClass().getName() + " is not a Map.");
+ }
+ @SuppressWarnings("unchecked")
+ Map<String, MetricsSource> sources = (Map<String, MetricsSource>) value;
+ Set<String> leaked = new TreeSet<>(sources.keySet());
+ leaked.removeIf(MetricsLeakAssertion::isExpectedLeftover);
+ if (!leaked.isEmpty()) {
+ throw new AssertionError("Found " + leaked.size() +
Review Comment:
Leaked sources stay registered: `DefaultMetricsSystem.shutdown()` only
clears `allSources` when its refcount reaches 0, and every service calls
`initialize()`. Later clusters in the same test class then fail on the same
names. Unregister them before throwing:
```suggestion
if (!leaked.isEmpty()) {
leaked.forEach(ms::unregisterSource);
```
##########
hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MetricsLeakAssertion.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.ozone;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.apache.hadoop.metrics2.MetricsSource;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * Asserts that no metrics sources remain registered in the
+ * {@link DefaultMetricsSystem} after a mini cluster is shut down.
+ *
+ * <p>Hadoop's {@code MetricsSystemImpl} does not remove registered sources on
+ * {@code stop()} or {@code shutdown()}; a metrics class that forgets to call
+ * {@code unregisterSource(...)} leaks its registration silently. This helper
+ * inspects the private {@code allSources} map via reflection and fails the
+ * test if anything is still registered.
+ */
+public final class MetricsLeakAssertion {
+
+ private static final String ALL_SOURCES_FIELD = "allSources";
+
+ /**
+ * Metrics sources that are registered once per JVM (or once per service)
+ * and intentionally never unregistered, so they are expected to still be
+ * present after a mini cluster shuts down. These are JVM-level singletons
+ * with no per-service owner; do not add per-service metrics here.
+ *
+ * <p>For the matching rules see {@link #isExpectedLeftover(String)}.
+ */
+ private static final List<String> EXPECTED_LEFTOVER_SOURCES = Arrays.asList(
+ "JvmMetrics*", // per service, via HddsServerUtil.initializeMetrics
+ "JvmMetricsCpu",
+ "UgiMetrics", // Hadoop security UGI metrics
+ "ManagedRocksObjectMetrics",
+ "ContainerCacheMetrics" // ContainerCache singleton, created once per JVM
+ );
+
+ /**
+ * Metrics sources that leak: they should be unregistered when the mini
+ * cluster shuts down but currently are not. This is a transitional list to
+ * keep the integration suite green while the leaks are being fixed. Each
+ * entry should be removed once the corresponding source unregisters
+ * properly; do not add new entries, fix the leak instead.
+ *
+ * <p>For the matching rules see {@link #isExpectedLeftover(String)}.
+ */
+ private static final List<String> TODO_LEFTOVER_SOURCES = Arrays.asList(
+ // RPC / HTTP server metrics (name embeds the listening port).
+ "RpcActivityForPort*",
+ "RpcDetailedActivityForPort*",
+ "HttpServer2*",
+ "LocalJobRunnerMetrics*",
+
+ // Datanode per-instance metrics.
+ "StorageContainerMetrics",
+ "ContainerDataScannerMetrics*", // name embeds the volume path
+ "ContainerMetadataScannerMetrics",
+ "On-demand container scanner metrics",
+ "BackgroundVolumeScannerMetrics",
+ "VolumeHealthMetrics-*",
+ "VolumeIOStats-*", // name embeds the volume path
+ // Name embeds the volume path. Also intentionally kept registered for
+ // failed volumes (HDDS-7086), so only the healthy-volume case is a leak.
+ "VolumeInfoMetrics-*",
+ "CommandHandlerMetrics",
+ "HddsDispatcher",
+ "ECReconstructionMetrics",
+ "ReplicationSupervisorMetrics",
+ "ContainerReplicator/push",
+ "BlockDeletingService",
+ "GrpcMetrics",
+
+ // SCM metrics.
+ "SCMNodeMetrics",
+ "SCMContainerManagerMetrics",
+ "SafeModeMetrics",
+ "ContainerBalancerMetrics",
+ "NodeDecommissionMetrics",
+ "SCMDatanodeProtocol",
+ "ScmBlockLocationProtocol",
+ "ScmContainerLocationProtocol",
+ "ScmSecurityProtocol",
+ "EventQueue*", // per event/handler pair, registered by SCM EventQueue
+
+ // OM metrics.
+ "OMMetrics",
+ "OMPerformanceMetrics",
+ "OMLockMetrics",
+ "OMHAMetrics",
+ "OMSnapshotDirectoryMetrics",
+ "OmSnapshotMetrics",
+ "OmClientProtocol",
+ "DeletingServiceMetrics",
+ "KeyLifecycleServiceMetrics",
+ "BucketUtilizationMetrics",
+ "DelegationTokenSecretManagerMetrics",
+
+ // OM / SCM RocksDB table cache and DB metrics (name embeds path/uuid).
+ "Rocksdb_*",
+ "SSTFilePruningMetrics-*",
+ "DBCheckpointMetrics",
+ "*TableCache",
+
+ // Ratis / third-party infrastructure metrics.
+ "CSMMetricsgroup-*", // Ratis container state machine, embeds a random id
+ "CacheMetrics-*", // Hadoop cache metrics (XceiverClientManager, etc.)
+ "NettyMetrics*",
+ "ContainerClientMetrics1",
+ "ReconTaskMetrics",
+ "ReconTaskControllerMetrics"
+ );
+
+ private MetricsLeakAssertion() {
+ }
+
+ /**
+ * Throws an {@link AssertionError} if any metrics sources are still
+ * registered with the default metrics system, or if the expected
+ * {@code allSources} field cannot be found or read (e.g. a Hadoop version
+ * change restructured {@code MetricsSystemImpl}), so that a broken or
+ * missing check fails loudly instead of going unnoticed.
+ */
+ public static void assertNoLeaks() {
+ try {
+ MetricsSystem ms = DefaultMetricsSystem.instance();
+ Field field = findAllSourcesField(ms.getClass());
+ if (field == null) {
+ throw new AssertionError("Cannot check for metrics leaks: '" +
ALL_SOURCES_FIELD +
+ "' field not found on " + ms.getClass().getName() +
+ ". The metrics system implementation may have changed.");
+ }
+ field.setAccessible(true);
+ Object value = field.get(ms);
+ if (!(value instanceof Map)) {
+ throw new AssertionError("Cannot check for metrics leaks: '" +
ALL_SOURCES_FIELD +
+ "' on " + ms.getClass().getName() + " is not a Map.");
+ }
+ @SuppressWarnings("unchecked")
+ Map<String, MetricsSource> sources = (Map<String, MetricsSource>) value;
+ Set<String> leaked = new TreeSet<>(sources.keySet());
+ leaked.removeIf(MetricsLeakAssertion::isExpectedLeftover);
+ if (!leaked.isEmpty()) {
+ throw new AssertionError("Found " + leaked.size() +
+ " metrics source(s) still registered after cluster shutdown: " +
leaked);
+ }
+ } catch (IllegalAccessException | RuntimeException e) {
+ throw new AssertionError("Cannot check for metrics leaks: unable to
inspect '" +
+ ALL_SOURCES_FIELD + "' in the default metrics system.", e);
+ }
+ }
+
+ /**
+ * Matching rules for {@link #EXPECTED_LEFTOVER_SOURCES} and
+ * {@link #TODO_LEFTOVER_SOURCES}:
+ * <ul>
+ * <li>An entry ending in {@code *} is a prefix match, used for sources
+ * whose registered name embeds a random id, an absolute path, or a port
+ * (e.g. {@code RpcActivityForPort15000}).</li>
+ * <li>An entry starting with {@code *} is a suffix match, used for sources
+ * whose registered name embeds a table-specific prefix (e.g.
+ * {@code keyTableCache-1}).</li>
+ * <li>Any other entry matches the source name exactly, or the name with a
+ * numeric suffix the metrics system appends for repeated registrations
+ * (e.g. {@code JvmMetrics-1}).</li>
+ * </ul>
+ */
+ private static boolean isExpectedLeftover(String name) {
+ return matches(EXPECTED_LEFTOVER_SOURCES, name) ||
matches(TODO_LEFTOVER_SOURCES, name);
+ }
+
+ private static boolean matches(List<String> entries, String name) {
+ for (String entry : entries) {
+ if (entry.startsWith("*")) {
+ // Suffix match, also tolerating a trailing numeric suffix (-N).
+ String suffix = entry.substring(1);
+ if (name.endsWith(suffix) ||
stripNumericSuffix(name).endsWith(suffix)) {
+ return true;
+ }
+ } else if (entry.endsWith("*")) {
+ if (name.startsWith(entry.substring(0, entry.length() - 1))) {
+ return true;
+ }
+ } else if (name.equals(entry) || stripNumericSuffix(name).equals(entry))
{
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static String stripNumericSuffix(String name) {
+ int idx = name.lastIndexOf('-');
+ if (idx > 0 && idx < name.length() - 1) {
+ String tail = name.substring(idx + 1);
+ boolean numeric = true;
+ for (int i = 0; i < tail.length(); i++) {
+ if (!Character.isDigit(tail.charAt(i))) {
+ numeric = false;
+ break;
+ }
+ }
+ if (numeric) {
+ return name.substring(0, idx);
+ }
+ }
+ return name;
+ }
Review Comment:
nit:
```suggestion
private static String stripNumericSuffix(String name) {
return name.replaceFirst("-\\d+$", "");
}
```
##########
hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MetricsLeakAssertion.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.ozone;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.apache.hadoop.metrics2.MetricsSource;
+import org.apache.hadoop.metrics2.MetricsSystem;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+
+/**
+ * Asserts that no metrics sources remain registered in the
+ * {@link DefaultMetricsSystem} after a mini cluster is shut down.
+ *
+ * <p>Hadoop's {@code MetricsSystemImpl} does not remove registered sources on
+ * {@code stop()} or {@code shutdown()}; a metrics class that forgets to call
+ * {@code unregisterSource(...)} leaks its registration silently. This helper
+ * inspects the private {@code allSources} map via reflection and fails the
+ * test if anything is still registered.
+ */
+public final class MetricsLeakAssertion {
+
+ private static final String ALL_SOURCES_FIELD = "allSources";
+
+ /**
+ * Metrics sources that are registered once per JVM (or once per service)
+ * and intentionally never unregistered, so they are expected to still be
+ * present after a mini cluster shuts down. These are JVM-level singletons
+ * with no per-service owner; do not add per-service metrics here.
+ *
+ * <p>For the matching rules see {@link #isExpectedLeftover(String)}.
+ */
+ private static final List<String> EXPECTED_LEFTOVER_SOURCES = Arrays.asList(
+ "JvmMetrics*", // per service, via HddsServerUtil.initializeMetrics
+ "JvmMetricsCpu",
Review Comment:
nit: already covered by `JvmMetrics*`.
```suggestion
```
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/http/TestHttpServer2Metrics.java:
##########
@@ -88,4 +97,37 @@ public void testMetrics() {
verify(recorder).addGauge(HttpServerThreadQueueWaitingTaskCount,
threadQueueWaitingTaskCount);
}
+
+ @Test
+ void testUnregisterWithMultipleMetricsSourceIds() throws Exception {
+ MetricsSystem metricsSystem =
+ DefaultMetricsSystem.initialize("TestHttpServer2Metrics");
+ Field field = metricsSystem.getClass().getDeclaredField("allSources");
Review Comment:
nit: `MetricsSystem.getSource(name)` is public, no need to reflect on
`allSources` (same in `TestOmSnapshotInternalMetrics` and
`TestVolumeUtilizationMetrics`). See `TestVolumeSet`.
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestGetDBUpdatesAuthorizationWithoutRecon.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.ozone.om;
+
+import static
org.apache.hadoop.hdds.recon.ReconConfig.ConfigStrings.OZONE_RECON_KERBEROS_PRINCIPAL_KEY;
+import static
org.apache.hadoop.ozone.om.TestGetDBUpdatesAuthorization.authTestConfiguration;
+import static
org.apache.hadoop.ozone.om.TestGetDBUpdatesAuthorization.getDBUpdates;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests getDBUpdates authorization when the Recon service principal is not
configured.
+ */
+class TestGetDBUpdatesAuthorizationWithoutRecon {
+
+ @Test
+ void accessDeniedWhenReconPrincipalNotConfigured() throws Exception {
+ OzoneConfiguration conf = authTestConfiguration();
+ conf.unset(OZONE_RECON_KERBEROS_PRINCIPAL_KEY);
+ MiniOzoneCluster cluster =
MiniOzoneCluster.newBuilder(conf).setNumDatanodes(1).build();
+ try {
+ cluster.waitForClusterToBeReady();
+ UserGroupInformation reconLikeUser =
+ UserGroupInformation.createUserForTesting("reconsvc", new String[]
{"recon"});
Review Comment:
nit: reuse `TestGetDBUpdatesAuthorization.RECON_PRINCIPAL`
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManagerHttpServer.java:
##########
@@ -33,7 +33,8 @@ public class OzoneManagerHttpServer extends BaseHttpServer {
public OzoneManagerHttpServer(MutableConfigurationSource conf,
OzoneManager om) throws IOException {
- super(conf, "ozoneManager");
+ super(conf, "ozoneManager", om == null ? null
+ : om.getOMServiceId() + '-' + om.getOMNodeId());
Review Comment:
nit: non-HA OM has a null service id, giving
`HttpServer2Metrics-null-<omId>`. Node id is unique on its own:
```suggestion
super(conf, "ozoneManager", om == null ? null : om.getOMNodeId());
```
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/TestMiniOzoneCluster.java:
##########
@@ -85,6 +96,37 @@ public void cleanup() {
}
}
+ @Test
+ void testSnapshotMetricsAfterOmRestart() throws Exception {
+ cluster = MiniOzoneCluster.newBuilder(conf).withoutDatanodes().build();
+ OmSnapshotInternalMetrics metrics =
cluster.getOzoneManager().getOmSnapshotIntMetrics();
+ Field field =
OmSnapshotInternalMetrics.class.getDeclaredField("sourceName");
+ field.setAccessible(true);
+ String sourceName = (String) field.get(metrics);
+ assertNotNull(DefaultMetricsSystem.instance().getSource(sourceName));
+ metrics.incNumSnapshotPurges();
+
+ cluster.restartOzoneManager();
+
+ assertNotNull(DefaultMetricsSystem.instance().getSource(sourceName));
+ assertCounter("NumSnapshotPurges", 1L,
getMetrics(DefaultMetricsSystem.instance().getSource(sourceName)));
+ }
+
+ @Test
+ void testMetricsSystemShutdownOnLeak() throws Exception {
+ cluster = MiniOzoneCluster.newBuilder(conf).withoutDatanodes().build();
+ String sourceName = "TestMiniOzoneClusterLeakedMetrics";
+ DefaultMetricsSystem.instance().register(sourceName, "Test metrics",
(MetricsSource) (collector, all) -> { });
+ try (MockedStatic<DefaultMetricsSystem> metricsSystem =
+ mockStatic(DefaultMetricsSystem.class, CALLS_REAL_METHODS)) {
+ AssertionError error = assertThrows(AssertionError.class,
cluster::shutdown);
+ assertTrue(error.getMessage().contains(sourceName));
Review Comment:
nit:
```suggestion
assertThat(error).hasMessageContaining(sourceName);
```
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/utils/ContainerCacheMetrics.java:
##########
@@ -28,6 +28,8 @@
*/
public final class ContainerCacheMetrics {
+ private static final String SOURCE_NAME = "ContainerCacheMetrics";
Review Comment:
nit: unrelated change, leftover from the reverted `unregister()`. drop this?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]