diff --git a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientMetrics.java b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientMetrics.java index 1402ea4de640..1545429862d3 100644 --- a/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientMetrics.java +++ b/hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientMetrics.java @@ -22,10 +22,10 @@ import org.apache.hadoop.hdds.annotation.InterfaceAudience; import org.apache.hadoop.hdds.conf.OzoneConfiguration; import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; +import org.apache.hadoop.hdds.utils.BaseMetricsSource; import org.apache.hadoop.hdds.utils.IOUtils; import org.apache.hadoop.metrics2.MetricsCollector; import org.apache.hadoop.metrics2.MetricsRecordBuilder; -import org.apache.hadoop.metrics2.MetricsSource; import org.apache.hadoop.metrics2.MetricsSystem; import org.apache.hadoop.metrics2.annotation.Metric; import org.apache.hadoop.metrics2.annotation.Metrics; @@ -40,7 +40,7 @@ */ @InterfaceAudience.Private @Metrics(about = "Storage Container Client Metrics", context = "dfs") -public class XceiverClientMetrics implements MetricsSource { +public class XceiverClientMetrics extends BaseMetricsSource { public static final String SOURCE_NAME = XceiverClientMetrics.class .getSimpleName(); @@ -52,10 +52,6 @@ public class XceiverClientMetrics implements MetricsSource { private EnumMap opsArray; private EnumMap containerOpsLatency; - // TODO: https://issues.apache.org/jira/browse/HDDS-13555 - @SuppressWarnings("PMD.SingularField") - private MetricsRegistry registry; - public XceiverClientMetrics() { init(); } diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BaseMetricsSource.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BaseMetricsSource.java new file mode 100644 index 000000000000..3d8250ded351 --- /dev/null +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/utils/BaseMetricsSource.java @@ -0,0 +1,36 @@ +/* + * 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.hdds.utils; + +import org.apache.hadoop.metrics2.MetricsSource; +import org.apache.hadoop.metrics2.lib.MetricsRegistry; + +/** + * Base class for metrics sources that use MetricsRegistry. + * Eliminates the need for each metrics class to declare its own registry field. + */ +public abstract class BaseMetricsSource implements MetricsSource { + + /** + * MetricsRegistry for creating and managing metrics. + * Protected so subclasses can access it directly. + */ + @SuppressWarnings("PMD.SingularField") + protected MetricsRegistry registry; +} + diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerMetrics.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerMetrics.java index 8ee2b4e5c079..5db3e5877278 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerMetrics.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/ContainerMetrics.java @@ -65,9 +65,9 @@ public class ContainerMetrics implements Closeable { private final EnumMap opsLatency; private final EnumMap opsLatQuantiles; - // TODO: https://issues.apache.org/jira/browse/HDDS-13555 + // MetricsRegistry must be kept as instance field to prevent GC and ensure metrics work correctly @SuppressWarnings("PMD.SingularField") - private MetricsRegistry registry; + private final MetricsRegistry registry; public ContainerMetrics(int[] intervals) { final int len = intervals.length; diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeQueueMetrics.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeQueueMetrics.java index d442b95285d8..eb3e287313bc 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeQueueMetrics.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeQueueMetrics.java @@ -33,7 +33,6 @@ import org.apache.hadoop.metrics2.MetricsSource; import org.apache.hadoop.metrics2.annotation.Metrics; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; -import org.apache.hadoop.metrics2.lib.MetricsRegistry; import org.apache.hadoop.ozone.OzoneConsts; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,8 +60,6 @@ public final class DatanodeQueueMetrics implements MetricsSource { public static final String PIPELINE_ACTION_QUEUE_PREFIX = "PipelineActionQueue"; - private MetricsRegistry registry; - private DatanodeStateMachine datanodeStateMachine; private static DatanodeQueueMetrics instance; @@ -73,7 +70,6 @@ public final class DatanodeQueueMetrics implements MetricsSource { private Map pipelineActionQueueMap; public DatanodeQueueMetrics(DatanodeStateMachine datanodeStateMachine) { - this.registry = new MetricsRegistry(METRICS_SOURCE_NAME); this.datanodeStateMachine = datanodeStateMachine; initializeQueues(); diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/CSMMetrics.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/CSMMetrics.java index 57939edf51ff..dbe40dc2badd 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/CSMMetrics.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/transport/server/ratis/CSMMetrics.java @@ -52,9 +52,9 @@ public class CSMMetrics { private final EnumMap opsLatencyMs; private final EnumMap opsQueueingDelay; - // TODO: https://issues.apache.org/jira/browse/HDDS-13555 + // MetricsRegistry must be kept as instance field to prevent GC and ensure metrics work correctly @SuppressWarnings("PMD.SingularField") - private MetricsRegistry registry; + private final MetricsRegistry registry; // Failure Metrics private @Metric MutableCounterLong numWriteStateMachineFails; diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/metrics/SCMPerformanceMetrics.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/metrics/SCMPerformanceMetrics.java index 5bb6e01b28de..ba775c2d9073 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/metrics/SCMPerformanceMetrics.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/metrics/SCMPerformanceMetrics.java @@ -25,7 +25,6 @@ import org.apache.hadoop.metrics2.annotation.Metric; import org.apache.hadoop.metrics2.annotation.Metrics; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; -import org.apache.hadoop.metrics2.lib.MetricsRegistry; import org.apache.hadoop.metrics2.lib.MutableCounterLong; import org.apache.hadoop.metrics2.lib.MutableRate; import org.apache.hadoop.ozone.OzoneConsts; @@ -40,7 +39,6 @@ public final class SCMPerformanceMetrics implements MetricsSource { private static final String SOURCE_NAME = SCMPerformanceMetrics.class.getSimpleName(); - private MetricsRegistry registry; private static SCMPerformanceMetrics instance; @Metric(about = "Number of failed deleteKeys") @@ -61,7 +59,6 @@ public final class SCMPerformanceMetrics implements MetricsSource { private MutableCounterLong deleteKeyBlocksFailure; public SCMPerformanceMetrics() { - this.registry = new MetricsRegistry(SOURCE_NAME); } public static SCMPerformanceMetrics create() { diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManagerMetrics.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManagerMetrics.java index 13206e585f5d..19a2177aa695 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManagerMetrics.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/replication/ReplicationManagerMetrics.java @@ -35,7 +35,6 @@ import org.apache.hadoop.metrics2.annotation.Metrics; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.metrics2.lib.Interns; -import org.apache.hadoop.metrics2.lib.MetricsRegistry; import org.apache.hadoop.metrics2.lib.MutableCounterLong; import org.apache.hadoop.metrics2.lib.MutableRate; import org.apache.hadoop.ozone.OzoneConsts; @@ -158,8 +157,6 @@ public final class ReplicationManagerMetrics implements MetricsSource { " reaching the cluster inflight replication limit.") private MutableCounterLong pendingReplicationLimitReachedTotal; - private MetricsRegistry registry; - private final ReplicationManager replicationManager; //EC Metrics @@ -225,7 +222,6 @@ public final class ReplicationManagerMetrics implements MetricsSource { private MutableCounterLong replicateContainerCmdsDeferredTotal; public ReplicationManagerMetrics(ReplicationManager manager) { - this.registry = new MetricsRegistry(METRICS_SOURCE_NAME); this.replicationManager = manager; } diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionMetrics.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionMetrics.java index f5adcf45cc20..f06a5e09a6fc 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionMetrics.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/NodeDecommissionMetrics.java @@ -29,7 +29,6 @@ import org.apache.hadoop.metrics2.annotation.Metrics; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.metrics2.lib.Interns; -import org.apache.hadoop.metrics2.lib.MetricsRegistry; import org.apache.hadoop.metrics2.lib.MutableGaugeLong; import org.apache.hadoop.ozone.OzoneConsts; @@ -60,13 +59,10 @@ public final class NodeDecommissionMetrics implements MetricsSource { @Metric("Number of containers sufficiently replicated in tracked nodes.") private MutableGaugeLong containersSufficientlyReplicatedTotal; - private MetricsRegistry registry; - private Map metricsByHost; /** Private constructor. */ private NodeDecommissionMetrics() { - this.registry = new MetricsRegistry(METRICS_SOURCE_NAME); metricsByHost = new HashMap<>(); } diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/SCMPipelineMetrics.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/SCMPipelineMetrics.java index 187d4be74b66..6dc175d17912 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/SCMPipelineMetrics.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/SCMPipelineMetrics.java @@ -29,7 +29,6 @@ import org.apache.hadoop.metrics2.annotation.Metrics; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.metrics2.lib.Interns; -import org.apache.hadoop.metrics2.lib.MetricsRegistry; import org.apache.hadoop.metrics2.lib.MutableCounterLong; import org.apache.hadoop.metrics2.lib.MutableRate; import org.apache.hadoop.ozone.OzoneConsts; @@ -45,7 +44,6 @@ public final class SCMPipelineMetrics implements MetricsSource { private static final String SOURCE_NAME = SCMPipelineMetrics.class.getSimpleName(); - private MetricsRegistry registry; private static SCMPipelineMetrics instance; private @Metric MutableCounterLong numPipelineAllocated; @@ -61,7 +59,6 @@ public final class SCMPipelineMetrics implements MetricsSource { /** Private constructor. */ private SCMPipelineMetrics() { - this.registry = new MetricsRegistry(SOURCE_NAME); numBlocksAllocated = new ConcurrentHashMap<>(); } diff --git a/hadoop-ozone/dist/src/main/compose/ozonesecure-ha/test-haproxy-s3g.sh b/hadoop-ozone/dist/src/main/compose/ozonesecure-ha/test-haproxy-s3g.sh index a2b11418a88c..904660cdb452 100644 --- a/hadoop-ozone/dist/src/main/compose/ozonesecure-ha/test-haproxy-s3g.sh +++ b/hadoop-ozone/dist/src/main/compose/ozonesecure-ha/test-haproxy-s3g.sh @@ -23,6 +23,7 @@ COMPOSE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" export COMPOSE_DIR export SECURITY_ENABLED=true +export COMPOSE_FILE=docker-compose.yaml:s3-haproxy.yaml export OM_SERVICE_ID="omservice" export SCM=scm1.org @@ -38,7 +39,7 @@ execute_command_in_container kms hadoop key create ${OZONE_BUCKET_KEY_NAME} ## Exclude virtual-host tests. This is tested separately as it requires additional config. exclude="--exclude virtual-host" for bucket in encrypted; do - execute_robot_test recon -v BUCKET:${bucket} -N s3-${bucket} ${exclude} s3 + execute_robot_test ${SCM} -v BUCKET:${bucket} -N s3-${bucket} ${exclude} s3 # some tests are independent of the bucket type, only need to be run once ## Exclude virtual-host.robot exclude="--exclude virtual-host --exclude no-bucket-type" diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/DeletingServiceMetrics.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/DeletingServiceMetrics.java index ec4a110a4f90..d905166075b4 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/DeletingServiceMetrics.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/DeletingServiceMetrics.java @@ -24,7 +24,6 @@ import org.apache.hadoop.metrics2.annotation.Metric; import org.apache.hadoop.metrics2.annotation.Metrics; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; -import org.apache.hadoop.metrics2.lib.MetricsRegistry; import org.apache.hadoop.metrics2.lib.MutableGaugeLong; import org.apache.hadoop.ozone.OzoneConsts; @@ -36,7 +35,6 @@ public final class DeletingServiceMetrics { public static final String METRICS_SOURCE_NAME = DeletingServiceMetrics.class.getSimpleName(); - private MetricsRegistry registry; /* * Total directory deletion metrics across all iterations of DirectoryDeletingService since last restart. @@ -122,7 +120,6 @@ public final class DeletingServiceMetrics { private MutableGaugeLong lastAOSPurgeTransactionId; private DeletingServiceMetrics() { - this.registry = new MetricsRegistry(METRICS_SOURCE_NAME); } /** diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotInternalMetrics.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotInternalMetrics.java index ce5896c1b978..3570f4daaa2f 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotInternalMetrics.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotInternalMetrics.java @@ -20,7 +20,6 @@ import org.apache.hadoop.metrics2.annotation.Metric; import org.apache.hadoop.metrics2.annotation.Metrics; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; -import org.apache.hadoop.metrics2.lib.MetricsRegistry; import org.apache.hadoop.metrics2.lib.MutableCounterLong; import org.apache.hadoop.ozone.OzoneConsts; @@ -32,7 +31,6 @@ public class OmSnapshotInternalMetrics { public static final String METRICS_SOURCE_NAME = OmSnapshotInternalMetrics.class.getSimpleName(); - private MetricsRegistry registry; /* * Total internal snapshot deletion operation metrics since last restart. @@ -52,7 +50,6 @@ public class OmSnapshotInternalMetrics { private MutableCounterLong numSnapshotMoveTableKeysFails; public OmSnapshotInternalMetrics() { - this.registry = new MetricsRegistry(METRICS_SOURCE_NAME); } public static OmSnapshotInternalMetrics create() { diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java index 5bb2c2952a3d..4b37e1bcc526 100644 --- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java +++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/metrics/S3GatewayMetrics.java @@ -46,9 +46,6 @@ public final class S3GatewayMetrics implements Closeable, MetricsSource { public static final String SOURCE_NAME = S3GatewayMetrics.class.getSimpleName(); - // TODO: https://issues.apache.org/jira/browse/HDDS-13555 - @SuppressWarnings("PMD.SingularField") - private MetricsRegistry registry; private static S3GatewayMetrics instance; // BucketEndpoint @@ -286,7 +283,7 @@ public final class S3GatewayMetrics implements Closeable, MetricsSource { * Private constructor. */ private S3GatewayMetrics(OzoneConfiguration conf) { - this.registry = new MetricsRegistry(SOURCE_NAME); + MetricsRegistry registry = new MetricsRegistry(SOURCE_NAME); int[] intervals = conf.getInts(S3GatewayConfigKeys .OZONE_S3G_METRICS_PERCENTILES_INTERVALS_SECONDS_KEY); performanceMetrics = PerformanceMetrics.initializeMetrics(