-
Notifications
You must be signed in to change notification settings - Fork 614
HDDS-7361. Add general metrics for queues in Datanode #3863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a3aeec
HDDS-7361. Add general metrics for queues in Datanode
symious 8dc1f0f
HDDS-7361. Fix unit test
symious c981e58
HDDS-7361. Add Size to metrics name
symious f3bc3f0
HDDS-7361. Fix unit test
symious dda47fb
HDDS-7361. Use loose assertion
symious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
...main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeQueueMetrics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| /* | ||
| * 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 | ||
| * <p/> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p/> | ||
| * 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.container.common.statemachine; | ||
|
|
||
| import com.google.common.base.CaseFormat; | ||
| import org.apache.commons.text.WordUtils; | ||
| import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto; | ||
| import org.apache.hadoop.metrics2.MetricsCollector; | ||
| import org.apache.hadoop.metrics2.MetricsInfo; | ||
| import org.apache.hadoop.metrics2.MetricsRecordBuilder; | ||
| 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; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import static org.apache.hadoop.metrics2.lib.Interns.info; | ||
|
|
||
| /** | ||
| * Class contains metrics related to Datanode queues. | ||
| */ | ||
| @Metrics(about = "Datanode Queue Metrics", context = OzoneConsts.OZONE) | ||
| public final class DatanodeQueueMetrics implements MetricsSource { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(DatanodeQueueMetrics.class); | ||
|
|
||
| public static final String METRICS_SOURCE_NAME = | ||
| DatanodeQueueMetrics.class.getSimpleName(); | ||
|
|
||
| public static final String STATE_CONTEXT_COMMAND_QUEUE_PREFIX = | ||
| "StateContextCommandQueue"; | ||
| public static final String COMMAND_DISPATCHER_QUEUE_PREFIX = | ||
| "CommandDispatcherCommandQueue"; | ||
| public static final String INCREMENTAL_REPORT_QUEUE_PREFIX = | ||
| "IncrementalReportQueue"; | ||
| public static final String CONTAINER_ACTION_QUEUE_PREFIX = | ||
| "ContainerActionQueue"; | ||
| public static final String PIPELINE_ACTION_QUEUE_PREFIX = | ||
| "PipelineActionQueue"; | ||
|
|
||
| private MetricsRegistry registry; | ||
|
|
||
| private DatanodeStateMachine datanodeStateMachine; | ||
| private static DatanodeQueueMetrics instance; | ||
|
|
||
| private Map<SCMCommandProto.Type, MetricsInfo> stateContextCommandQueueMap; | ||
| private Map<SCMCommandProto.Type, MetricsInfo> commandDispatcherQueueMap; | ||
| private Map<InetSocketAddress, MetricsInfo> incrementalReportsQueueMap; | ||
| private Map<InetSocketAddress, MetricsInfo> containerActionQueueMap; | ||
| private Map<InetSocketAddress, MetricsInfo> pipelineActionQueueMap; | ||
|
|
||
| public DatanodeQueueMetrics(DatanodeStateMachine datanodeStateMachine) { | ||
| this.registry = new MetricsRegistry(METRICS_SOURCE_NAME); | ||
| this.datanodeStateMachine = datanodeStateMachine; | ||
|
|
||
| initializeQueues(); | ||
| } | ||
|
|
||
| public static synchronized DatanodeQueueMetrics create(DatanodeStateMachine | ||
| datanodeStateMachine) { | ||
| if (instance != null) { | ||
| return instance; | ||
| } | ||
| instance = DefaultMetricsSystem.instance().register(METRICS_SOURCE_NAME, | ||
| "Queue metrics in Datanode", | ||
| new DatanodeQueueMetrics(datanodeStateMachine)); | ||
| return instance; | ||
| } | ||
|
|
||
| private void initializeQueues() { | ||
| // Add queue from StateContext.commandQueue | ||
| stateContextCommandQueueMap = new HashMap<>(); | ||
| for (SCMCommandProto.Type type: SCMCommandProto.Type.values()) { | ||
| stateContextCommandQueueMap.put(type, getMetricsInfo( | ||
| STATE_CONTEXT_COMMAND_QUEUE_PREFIX, String.valueOf(type))); | ||
| } | ||
|
|
||
| // Add queue from DatanodeStateMachine.commandDispatcher | ||
| commandDispatcherQueueMap = new HashMap<>(); | ||
| for (SCMCommandProto.Type type: SCMCommandProto.Type.values()) { | ||
| commandDispatcherQueueMap.put(type, getMetricsInfo( | ||
| COMMAND_DISPATCHER_QUEUE_PREFIX, String.valueOf(type))); | ||
| } | ||
|
|
||
| // Initialize queue for StateContext.incrementalReportQueue, | ||
| // containerActionQueue, pipelineActionQueue | ||
| incrementalReportsQueueMap = new HashMap<>(); | ||
| containerActionQueueMap = new HashMap<>(); | ||
| pipelineActionQueueMap = new HashMap<>(); | ||
| } | ||
|
|
||
| @Override | ||
| public void getMetrics(MetricsCollector collector, boolean b) { | ||
| MetricsRecordBuilder builder = collector.addRecord(METRICS_SOURCE_NAME); | ||
|
|
||
| Map<SCMCommandProto.Type, Integer> tmpMap = | ||
| datanodeStateMachine.getContext().getCommandQueueSummary(); | ||
| for (Map.Entry<SCMCommandProto.Type, MetricsInfo> entry: | ||
| stateContextCommandQueueMap.entrySet()) { | ||
| builder.addGauge(entry.getValue(), | ||
| (long) tmpMap.getOrDefault(entry.getKey(), 0)); | ||
| } | ||
|
|
||
| tmpMap = datanodeStateMachine.getCommandDispatcher() | ||
| .getQueuedCommandCount(); | ||
| for (Map.Entry<SCMCommandProto.Type, MetricsInfo> entry: | ||
| commandDispatcherQueueMap.entrySet()) { | ||
| builder.addGauge(entry.getValue(), | ||
| (long) tmpMap.getOrDefault(entry.getKey(), 0)); | ||
| } | ||
|
|
||
| for (Map.Entry<InetSocketAddress, MetricsInfo> entry: | ||
| incrementalReportsQueueMap.entrySet()) { | ||
| builder.addGauge(entry.getValue(), | ||
| datanodeStateMachine.getContext() | ||
| .getIncrementalReportQueueSize().getOrDefault(entry.getKey(), 0)); | ||
| } | ||
| for (Map.Entry<InetSocketAddress, MetricsInfo> entry: | ||
| containerActionQueueMap.entrySet()) { | ||
| builder.addGauge(entry.getValue(), | ||
| datanodeStateMachine.getContext() | ||
| .getContainerActionQueueSize().getOrDefault(entry.getKey(), 0)); | ||
| } | ||
| for (Map.Entry<InetSocketAddress, MetricsInfo> entry: | ||
| pipelineActionQueueMap.entrySet()) { | ||
| builder.addGauge(entry.getValue(), | ||
| datanodeStateMachine.getContext().getPipelineActionQueueSize() | ||
| .getOrDefault(entry.getKey(), 0)); | ||
| } | ||
| } | ||
|
|
||
| public static synchronized void unRegister() { | ||
| instance = null; | ||
| DefaultMetricsSystem.instance().unregisterSource(METRICS_SOURCE_NAME); | ||
| } | ||
|
|
||
| public void addEndpoint(InetSocketAddress endpoint) { | ||
| incrementalReportsQueueMap.computeIfAbsent(endpoint, | ||
| k -> getMetricsInfo(INCREMENTAL_REPORT_QUEUE_PREFIX, | ||
| CaseFormat.UPPER_UNDERSCORE | ||
| .to(CaseFormat.UPPER_CAMEL, k.getHostName()))); | ||
| containerActionQueueMap.computeIfAbsent(endpoint, | ||
| k -> getMetricsInfo(CONTAINER_ACTION_QUEUE_PREFIX, | ||
| CaseFormat.UPPER_UNDERSCORE | ||
| .to(CaseFormat.UPPER_CAMEL, k.getHostName()))); | ||
| pipelineActionQueueMap.computeIfAbsent(endpoint, | ||
| k -> getMetricsInfo(PIPELINE_ACTION_QUEUE_PREFIX, | ||
| CaseFormat.UPPER_UNDERSCORE | ||
| .to(CaseFormat.UPPER_CAMEL, k.getHostName()))); | ||
| } | ||
|
|
||
| private MetricsInfo getMetricsInfo(String prefix, String metricName) { | ||
| String metric = prefix + WordUtils.capitalize(metricName); | ||
| String description = "Queue size of " + metricName + " from " + prefix; | ||
| return info(metric, description); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...est/src/test/java/org/apache/hadoop/ozone/container/metrics/TestDatanodeQueueMetrics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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.container.metrics; | ||
|
|
||
| import org.apache.commons.text.WordUtils; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto; | ||
| import org.apache.hadoop.hdds.scm.ScmConfigKeys; | ||
| import org.apache.hadoop.ozone.MiniOzoneCluster; | ||
| import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl; | ||
| import org.apache.hadoop.ozone.container.common.statemachine.DatanodeQueueMetrics; | ||
| import org.junit.Rule; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.rules.Timeout; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.apache.hadoop.ozone.container.common.statemachine.DatanodeQueueMetrics.COMMAND_DISPATCHER_QUEUE_PREFIX; | ||
| import static org.apache.hadoop.ozone.container.common.statemachine.DatanodeQueueMetrics.STATE_CONTEXT_COMMAND_QUEUE_PREFIX; | ||
| import static org.apache.hadoop.test.MetricsAsserts.getLongGauge; | ||
| import static org.apache.hadoop.test.MetricsAsserts.getMetrics; | ||
|
|
||
| /** | ||
| * Test for queue metrics of datanodes. | ||
| */ | ||
| public class TestDatanodeQueueMetrics { | ||
|
|
||
| private MiniOzoneHAClusterImpl cluster = null; | ||
| private OzoneConfiguration conf; | ||
| private String clusterId; | ||
| private String scmId; | ||
| private String omServiceId; | ||
| private static int numOfOMs = 3; | ||
| private String scmServiceId; | ||
| private static int numOfSCMs = 3; | ||
|
|
||
| private static final Logger LOG = LoggerFactory | ||
| .getLogger(TestDatanodeQueueMetrics.class); | ||
|
|
||
| @Rule | ||
| public Timeout timeout = new Timeout(300_000); | ||
|
|
||
| /** | ||
| * Create a MiniDFSCluster for testing. | ||
| * <p> | ||
| * Ozone is made active by setting OZONE_ENABLED = true | ||
| * | ||
| * @throws IOException | ||
| */ | ||
| @BeforeEach | ||
| public void init() throws Exception { | ||
| conf = new OzoneConfiguration(); | ||
| conf.set(ScmConfigKeys.OZONE_SCM_PIPELINE_CREATION_INTERVAL, "10s"); | ||
| clusterId = UUID.randomUUID().toString(); | ||
| scmId = UUID.randomUUID().toString(); | ||
| omServiceId = "om-service-test1"; | ||
| scmServiceId = "scm-service-test1"; | ||
| cluster = (MiniOzoneHAClusterImpl) MiniOzoneCluster.newHABuilder(conf) | ||
| .setClusterId(clusterId) | ||
| .setScmId(scmId) | ||
| .setOMServiceId(omServiceId) | ||
| .setSCMServiceId(scmServiceId) | ||
| .setNumOfStorageContainerManagers(numOfSCMs) | ||
| .setNumOfOzoneManagers(numOfOMs) | ||
| .setNumDatanodes(1) | ||
| .build(); | ||
| cluster.waitForClusterToBeReady(); | ||
| } | ||
| /** | ||
| * Set a timeout for each test. | ||
| */ | ||
|
|
||
| @Test | ||
| public void testQueueMetrics() { | ||
|
|
||
| for (SCMCommandProto.Type type: SCMCommandProto.Type.values()) { | ||
| Assertions.assertEquals(0, | ||
| getGauge(STATE_CONTEXT_COMMAND_QUEUE_PREFIX + | ||
| WordUtils.capitalize(String.valueOf(type)))); | ||
| Assertions.assertEquals(0, | ||
| getGauge(COMMAND_DISPATCHER_QUEUE_PREFIX + | ||
| WordUtils.capitalize(String.valueOf(type)))); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private long getGauge(String metricName) { | ||
| return getLongGauge(metricName, | ||
| getMetrics(DatanodeQueueMetrics.METRICS_SOURCE_NAME)); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we should append count / size / total to the end of the metric name? Most counters seem to end in something like this.