This is an automated email from the ASF dual-hosted git repository.

tanvipenumudy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 6e826d527c HDDS-10407. Introduce metrics for deleteKey operation in 
SCM service. (#6439)
6e826d527c is described below

commit 6e826d527c20a89282085609d8725ba6c56e03fe
Author: muskan1012 <[email protected]>
AuthorDate: Tue Jun 18 13:03:47 2024 +0530

    HDDS-10407. Introduce metrics for deleteKey operation in SCM service. 
(#6439)
---
 .../placement/metrics/SCMPerformanceMetrics.java   | 94 ++++++++++++++++++++++
 .../hdds/scm/server/SCMBlockProtocolServer.java    |  8 ++
 .../hdds/scm/server/StorageContainerManager.java   | 19 +++++
 3 files changed, 121 insertions(+)

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
new file mode 100644
index 0000000000..b9d9750da0
--- /dev/null
+++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/metrics/SCMPerformanceMetrics.java
@@ -0,0 +1,94 @@
+/**
+ * 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.scm.container.placement.metrics;
+
+import org.apache.hadoop.hdds.annotation.InterfaceAudience;
+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;
+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;
+import org.apache.hadoop.util.Time;
+
+/**
+ * Including SCM performance related metrics.
+ */
[email protected]
+@Metrics(about = "SCM Performance Metrics", context = OzoneConsts.OZONE)
+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 deleteKey operations")
+  private MutableCounterLong deleteKeyFailure;
+  @Metric(about = "Number of successful deleteKey operations")
+  private MutableCounterLong deleteKeySuccess;
+  @Metric(about = "Latency for deleteKey failure in nanoseconds")
+  private MutableRate deleteKeyFailureLatencyNs;
+  @Metric(about = "Latency for deleteKey success in nanoseconds")
+  private MutableRate deleteKeySuccessLatencyNs;
+
+  public SCMPerformanceMetrics() {
+    this.registry = new MetricsRegistry(SOURCE_NAME);
+  }
+
+  public static SCMPerformanceMetrics create() {
+    if (instance != null) {
+      return instance;
+    }
+    MetricsSystem ms = DefaultMetricsSystem.instance();
+    instance = ms.register(SOURCE_NAME, "SCM Performance Metrics",
+        new SCMPerformanceMetrics());
+    return instance;
+  }
+
+  public void unRegister() {
+    MetricsSystem ms = DefaultMetricsSystem.instance();
+    ms.unregisterSource(SOURCE_NAME);
+  }
+
+  @Override
+  public void getMetrics(MetricsCollector collector, boolean all) {
+    MetricsRecordBuilder recordBuilder = collector.addRecord(SOURCE_NAME);
+    deleteKeySuccess.snapshot(recordBuilder, true);
+    deleteKeySuccessLatencyNs.snapshot(recordBuilder, true);
+    deleteKeyFailure.snapshot(recordBuilder, true);
+    deleteKeyFailureLatencyNs.snapshot(recordBuilder, true);
+  }
+
+  public void updateDeleteKeySuccessStats(long startNanos) {
+    deleteKeySuccess.incr();
+    deleteKeySuccessLatencyNs.add(Time.monotonicNowNanos() - startNanos);
+  }
+
+  public void updateDeleteKeyFailureStats(long startNanos) {
+    deleteKeyFailure.incr();
+    deleteKeyFailureLatencyNs.add(Time.monotonicNowNanos() - startNanos);
+  }
+}
+
diff --git 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMBlockProtocolServer.java
 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMBlockProtocolServer.java
index 79002e27a2..a035751796 100644
--- 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMBlockProtocolServer.java
+++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMBlockProtocolServer.java
@@ -42,6 +42,7 @@ import org.apache.hadoop.hdds.scm.ScmInfo;
 import org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock;
 import org.apache.hadoop.hdds.scm.container.common.helpers.DeleteBlockResult;
 import org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList;
+import 
org.apache.hadoop.hdds.scm.container.placement.metrics.SCMPerformanceMetrics;
 import org.apache.hadoop.hdds.scm.exceptions.SCMException;
 import org.apache.hadoop.hdds.scm.net.InnerNode;
 import org.apache.hadoop.hdds.scm.net.Node;
@@ -75,11 +76,13 @@ import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_BLOCK_HANDLER_C
 import static 
org.apache.hadoop.hdds.scm.exceptions.SCMException.ResultCodes.IO_EXCEPTION;
 import static org.apache.hadoop.hdds.scm.net.NetConstants.NODE_COST_DEFAULT;
 import static org.apache.hadoop.hdds.scm.net.NetConstants.ROOT;
+import static 
org.apache.hadoop.hdds.scm.server.StorageContainerManager.getPerfMetrics;
 import static 
org.apache.hadoop.hdds.scm.server.StorageContainerManager.startRpcServer;
 import static org.apache.hadoop.hdds.server.ServerUtils.getRemoteUserName;
 import static org.apache.hadoop.hdds.server.ServerUtils.updateRPCListenAddress;
 import static org.apache.hadoop.hdds.utils.HddsServerUtil.getRemoteUser;
 
+import org.apache.hadoop.util.Time;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -101,6 +104,7 @@ public class SCMBlockProtocolServer implements
   private final InetSocketAddress blockRpcAddress;
   private final ProtocolMessageMetrics<ProtocolMessageEnum>
       protocolMessageMetrics;
+  private final SCMPerformanceMetrics perfMetrics;
 
   /**
    * The RPC server that listens to requests from block service clients.
@@ -109,6 +113,7 @@ public class SCMBlockProtocolServer implements
       StorageContainerManager scm) throws IOException {
     this.scm = scm;
     this.conf = conf;
+    this.perfMetrics = getPerfMetrics();
     final int handlerCount = conf.getInt(OZONE_SCM_BLOCK_HANDLER_COUNT_KEY,
         OZONE_SCM_HANDLER_COUNT_KEY, OZONE_SCM_HANDLER_COUNT_DEFAULT,
             LOG::info);
@@ -262,12 +267,15 @@ public class SCMBlockProtocolServer implements
     Map<String, String> auditMap = Maps.newHashMap();
     ScmBlockLocationProtocolProtos.DeleteScmBlockResult.Result resultCode;
     Exception e = null;
+    long startNanos = Time.monotonicNowNanos();
     try {
       scm.getScmBlockManager().deleteBlocks(keyBlocksInfoList);
+      perfMetrics.updateDeleteKeySuccessStats(startNanos);
       resultCode = ScmBlockLocationProtocolProtos.
           DeleteScmBlockResult.Result.success;
     } catch (IOException ioe) {
       e = ioe;
+      perfMetrics.updateDeleteKeyFailureStats(startNanos);
       LOG.warn("Fail to delete {} keys", keyBlocksInfoList.size(), ioe);
       switch (ioe instanceof SCMException ? ((SCMException) ioe).getResult() :
           IO_EXCEPTION) {
diff --git 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
index 513361bf3d..63cce60bcf 100644
--- 
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
+++ 
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java
@@ -50,6 +50,7 @@ import org.apache.hadoop.hdds.scm.container.ContainerManager;
 import org.apache.hadoop.hdds.scm.container.ContainerManagerImpl;
 import org.apache.hadoop.hdds.scm.PlacementPolicyValidateProxy;
 import org.apache.hadoop.hdds.scm.container.balancer.MoveManager;
+import 
org.apache.hadoop.hdds.scm.container.placement.metrics.SCMPerformanceMetrics;
 import 
org.apache.hadoop.hdds.scm.container.replication.ContainerReplicaPendingOps;
 import 
org.apache.hadoop.hdds.scm.container.replication.DatanodeCommandCountUpdatedHandler;
 import 
org.apache.hadoop.hdds.scm.container.replication.LegacyReplicationManager;
@@ -233,6 +234,7 @@ public final class StorageContainerManager extends 
ServiceRuntimeInfoImpl
    * SCM metrics.
    */
   private static SCMMetrics metrics;
+  private static SCMPerformanceMetrics perfMetrics;
   private SCMHAMetrics scmHAMetrics;
 
   /*
@@ -364,6 +366,7 @@ public final class StorageContainerManager extends 
ServiceRuntimeInfoImpl
     scmHANodeDetails = SCMHANodeDetails.loadSCMHAConfig(conf, 
scmStorageConfig);
     configuration = conf;
     initMetrics();
+    initPerfMetrics();
 
     boolean ratisEnabled = SCMHAUtils.isSCMHAEnabled(conf);
     if (scmStorageConfig.getState() != StorageState.INITIALIZED) {
@@ -1407,6 +1410,18 @@ public final class StorageContainerManager extends 
ServiceRuntimeInfoImpl
   public static SCMMetrics getMetrics() {
     return metrics == null ? SCMMetrics.create() : metrics;
   }
+  /**
+   * Initialize SCMPerformance metrics.
+   */
+  public static void initPerfMetrics() {
+    perfMetrics = SCMPerformanceMetrics.create();
+  }
+  /**
+   * Return SCMPerformance metrics instance.
+   */
+  public static SCMPerformanceMetrics getPerfMetrics() {
+    return perfMetrics == null ? SCMPerformanceMetrics.create() : perfMetrics;
+  }
 
   public SCMStorageConfig getScmStorageConfig() {
     return scmStorageConfig;
@@ -1695,6 +1710,10 @@ public final class StorageContainerManager extends 
ServiceRuntimeInfoImpl
       metrics.unRegister();
     }
 
+    if (perfMetrics != null) {
+      perfMetrics.unRegister();
+    }
+
     unregisterMXBean();
     if (scmContainerMetrics != null) {
       scmContainerMetrics.unRegister();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to