sumitagrawl commented on code in PR #7377:
URL: https://github.com/apache/ozone/pull/7377#discussion_r1855803420


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMDirectoriesPurgeRequestWithFSO.java:
##########
@@ -168,7 +173,17 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager, TermIn
             volBucketInfoMap.putIfAbsent(volBucketPair, omBucketInfo);
           }
         }
+        if (path.hasDeletedDir()) {
+          numDirsDeleted++;
+        }
       }
+      deletingServiceMetrics.incrNumSubDirectoriesPurged(numSubDirDeleted);
+      
deletingServiceMetrics.setNumSubDirectoriesPurgedInLatestRequest(numSubDirDeleted);
+      deletingServiceMetrics.incrNumSubKeysPurged(numSubFilesDeleted);
+      
deletingServiceMetrics.setNumSubKeysPurgedInLatestRequest(numSubFilesDeleted);
+      deletingServiceMetrics.incrNumDirPurged(numDirsDeleted);
+      deletingServiceMetrics.setNumDirPurgedInLatestRequest(numDirsDeleted);

Review Comment:
   do not need capture inLatestRequest()



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/DeletingServiceMetrics.java:
##########
@@ -0,0 +1,336 @@
+/**
+ * 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 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;
+
+/**
+ * Class contains metrics related to the OM Deletion services.
+ */
+@Metrics(about = "Deletion Service Metrics", context = OzoneConsts.OZONE)
+public final class DeletingServiceMetrics {
+
+  public static final String METRICS_SOURCE_NAME =
+      DeletingServiceMetrics.class.getSimpleName();
+  private MetricsRegistry registry;
+
+  private DeletingServiceMetrics() {
+    this.registry = new MetricsRegistry(METRICS_SOURCE_NAME);
+  }
+
+  /**
+   * Creates and returns DeletingServiceMetrics instance.
+   *
+   * @return DeletingServiceMetrics
+   */
+  public static DeletingServiceMetrics create() {
+    return DefaultMetricsSystem.instance().register(METRICS_SOURCE_NAME,
+        "Metrics tracking the progress of deletion of directories and keys in 
the OM",
+        new DeletingServiceMetrics());
+  }
+  /**
+   * Unregister the metrics instance.
+   */
+  public static void unregister() {
+    DefaultMetricsSystem.instance().unregisterSource(METRICS_SOURCE_NAME);
+  }
+
+
+  /*
+   * Total directory deletion metrics across all iterations of 
DirectoryDeletingService since last restart.
+   */
+  @Metric("Total no. of deleted directories sent for purge")
+  private MutableGaugeLong numDirsSentForPurge;
+  @Metric("Total no. of sub-directories sent for purge")
+  private MutableGaugeLong numSubDirsSentForPurge;
+  @Metric("Total no. of sub-files sent for purge")
+  private MutableGaugeLong numSubFilesSentForPurge;
+
+  public void incrNumDirDeleted(long dirDel) {
+    numDirsSentForPurge.incr(dirDel);
+  }
+
+  public void incrNumDirsMoved(long dirMove) {
+    numSubDirsSentForPurge.incr(dirMove);
+  }
+
+  public void incrNumFilesMoved(long filesMove) {
+    numSubFilesSentForPurge.incr(filesMove);
+  }
+
+  public void incrementDirectoryDeletionTotalMetrics(long dirDel, long 
dirMove, long filesMove) {
+    incrNumDirDeleted(dirDel);
+    incrNumDirsMoved(dirMove);
+    incrNumFilesMoved(filesMove);
+  }
+
+  /*
+   * Directory deletion metrics in the latest iteration of 
DirectoryDeletingService.
+   */
+  @Metric("Iteration run count of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirRunCount;
+  @Metric("Iteration start time of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirStartTime;
+  @Metric("Total time taken by the last iteration of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirDuration;
+  @Metric("No. of directories deleted in last iteration")
+  private MutableGaugeLong iterationDirsDeleted;
+  @Metric("No. of sub-directories deleted in last iteration")
+  private MutableGaugeLong iterationSubDirsDeleted;
+  @Metric("No. of sub-directories sent for purge in last iteration")
+  private MutableGaugeLong iterationSubDirsSentForPurge;
+  @Metric("No. of files sent for purge in last iteration")
+  private MutableGaugeLong iterationFilesSentForPurge;
+
+  public void setIterationDirRunCount(long runcount) {
+    iterationDirRunCount.set(runcount);
+  }
+
+  public void setIterationDirStartTime(long startTime) {
+    iterationDirStartTime.set(startTime);
+  }
+
+  public void setIterationDirDuration(long duration) {
+    iterationDirDuration.set(duration);
+  }
+
+  public void setIterationDirDeleted(long dirDel) {
+    iterationDirsDeleted.set(dirDel);
+  }
+
+  public void setIterationSubDirDeleted(long subdirDel) {
+    iterationSubDirsDeleted.set(subdirDel);
+  }
+
+  public void setIterationFilesSentForPurge(long filesMove) {
+    iterationFilesSentForPurge.set(filesMove);
+  }
+
+  public void setIterationSubDirsSentForPurge(long subdirMove) {
+    iterationSubDirsSentForPurge.set(subdirMove);
+  }
+
+  public void setDirectoryDeletionIterationMetrics(long runcount, long 
startTime, long duration,
+                                                   long dirDel, long subdirDel,
+                                                   long filesMove, long 
subdirMove) {
+    setIterationDirRunCount(runcount);

Review Comment:
   we do not need capture runCount and startTime



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/AbstractKeyDeletingService.java:
##########
@@ -91,12 +93,13 @@ public AbstractKeyDeletingService(String serviceName, long 
interval,
     this.movedDirsCount = new AtomicLong(0);
     this.movedFilesCount = new AtomicLong(0);
     this.runCount = new AtomicLong(0);
+    this.metrics = ozoneManager.getDeletionMetrics();
   }
 
   protected int processKeyDeletes(List<BlockGroup> keyBlocksList,
       KeyManager manager,
       HashMap<String, RepeatedOmKeyInfo> keysToModify,
-      String snapTableKey, UUID expectedPreviousSnapshotId) throws IOException 
{
+      String snapTableKey, UUID expectedPreviousSnapshotId, boolean 
shouldUpdateMetrics) throws IOException {

Review Comment:
   shouldUpdateMetrics --> isSnapshotDelete



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/AbstractKeyDeletingService.java:
##########
@@ -128,6 +131,12 @@ protected int processKeyDeletes(List<BlockGroup> 
keyBlocksList,
       }
       LOG.info("Blocks for {} (out of {}) keys are deleted from DB in {} ms",
           delCount, blockDeletionResults.size(), Time.monotonicNow() - 
startTime);
+      if (shouldUpdateMetrics) {
+        metrics.setIterationKeysDeletionRequest(blockDeletionResults.size());
+        metrics.setIterationKeysDeleteSuccess(delCount);
+        metrics.incrNumKeysDeletionRequest(blockDeletionResults.size());

Review Comment:
   do not need these metrics, caller have metrics of blockCount and keys



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMDirectoriesPurgeRequestWithFSO.java:
##########
@@ -168,7 +173,17 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager, TermIn
             volBucketInfoMap.putIfAbsent(volBucketPair, omBucketInfo);
           }
         }
+        if (path.hasDeletedDir()) {
+          numDirsDeleted++;
+        }
       }
+      deletingServiceMetrics.incrNumSubDirectoriesPurged(numSubDirDeleted);

Review Comment:
   For subdir / subfiles -- its subdirMoved, subFilesMoved.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMKeyPurgeRequest.java:
##########
@@ -93,9 +94,15 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager, TermIn
 
     List<String> keysToBePurgedList = new ArrayList<>();
 
+    int numKeysDeleted = 0;
     for (DeletedKeys bucketWithDeleteKeys : bucketDeletedKeysList) {
-      keysToBePurgedList.addAll(bucketWithDeleteKeys.getKeysList());
+      List<String> keysList = bucketWithDeleteKeys.getKeysList();
+      keysToBePurgedList.addAll(keysList);
+      numKeysDeleted = numKeysDeleted + keysList.size();
     }
+    DeletingServiceMetrics deletingServiceMetrics = 
ozoneManager.getDeletionMetrics();
+    deletingServiceMetrics.incrNumKeysPurged(numKeysDeleted);
+    deletingServiceMetrics.setNumKeysPurgedInLatestRequest(numKeysDeleted);

Review Comment:
   we do not need capture count in latest request, can be captured via 
prometheus for incrment



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -220,8 +225,15 @@ public BackgroundTaskResult call() {
           if (keyBlocksList != null && !keyBlocksList.isEmpty()) {
             delCount = processKeyDeletes(keyBlocksList,
                 getOzoneManager().getKeyManager(),
-                pendingKeysDeletion.getKeysToModify(), null, 
expectedPreviousSnapshotId);
+                pendingKeysDeletion.getKeysToModify(), null, 
expectedPreviousSnapshotId, true);
             deletedKeyCount.addAndGet(delCount);
+            metrics.setIterationKeyRunCount(run);

Review Comment:
   we do not need capture run count, start time.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/DeletingServiceMetrics.java:
##########
@@ -0,0 +1,336 @@
+/**
+ * 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 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;
+
+/**
+ * Class contains metrics related to the OM Deletion services.
+ */
+@Metrics(about = "Deletion Service Metrics", context = OzoneConsts.OZONE)
+public final class DeletingServiceMetrics {
+
+  public static final String METRICS_SOURCE_NAME =
+      DeletingServiceMetrics.class.getSimpleName();
+  private MetricsRegistry registry;
+
+  private DeletingServiceMetrics() {
+    this.registry = new MetricsRegistry(METRICS_SOURCE_NAME);
+  }
+
+  /**
+   * Creates and returns DeletingServiceMetrics instance.
+   *
+   * @return DeletingServiceMetrics
+   */
+  public static DeletingServiceMetrics create() {
+    return DefaultMetricsSystem.instance().register(METRICS_SOURCE_NAME,
+        "Metrics tracking the progress of deletion of directories and keys in 
the OM",
+        new DeletingServiceMetrics());
+  }
+  /**
+   * Unregister the metrics instance.
+   */
+  public static void unregister() {
+    DefaultMetricsSystem.instance().unregisterSource(METRICS_SOURCE_NAME);
+  }
+
+
+  /*
+   * Total directory deletion metrics across all iterations of 
DirectoryDeletingService since last restart.
+   */
+  @Metric("Total no. of deleted directories sent for purge")
+  private MutableGaugeLong numDirsSentForPurge;
+  @Metric("Total no. of sub-directories sent for purge")
+  private MutableGaugeLong numSubDirsSentForPurge;
+  @Metric("Total no. of sub-files sent for purge")
+  private MutableGaugeLong numSubFilesSentForPurge;
+
+  public void incrNumDirDeleted(long dirDel) {
+    numDirsSentForPurge.incr(dirDel);
+  }
+
+  public void incrNumDirsMoved(long dirMove) {
+    numSubDirsSentForPurge.incr(dirMove);
+  }
+
+  public void incrNumFilesMoved(long filesMove) {
+    numSubFilesSentForPurge.incr(filesMove);
+  }
+
+  public void incrementDirectoryDeletionTotalMetrics(long dirDel, long 
dirMove, long filesMove) {
+    incrNumDirDeleted(dirDel);
+    incrNumDirsMoved(dirMove);
+    incrNumFilesMoved(filesMove);
+  }
+
+  /*
+   * Directory deletion metrics in the latest iteration of 
DirectoryDeletingService.
+   */
+  @Metric("Iteration run count of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirRunCount;
+  @Metric("Iteration start time of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirStartTime;
+  @Metric("Total time taken by the last iteration of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirDuration;
+  @Metric("No. of directories deleted in last iteration")
+  private MutableGaugeLong iterationDirsDeleted;
+  @Metric("No. of sub-directories deleted in last iteration")
+  private MutableGaugeLong iterationSubDirsDeleted;
+  @Metric("No. of sub-directories sent for purge in last iteration")
+  private MutableGaugeLong iterationSubDirsSentForPurge;
+  @Metric("No. of files sent for purge in last iteration")
+  private MutableGaugeLong iterationFilesSentForPurge;
+
+  public void setIterationDirRunCount(long runcount) {
+    iterationDirRunCount.set(runcount);
+  }
+
+  public void setIterationDirStartTime(long startTime) {
+    iterationDirStartTime.set(startTime);
+  }
+
+  public void setIterationDirDuration(long duration) {
+    iterationDirDuration.set(duration);
+  }
+
+  public void setIterationDirDeleted(long dirDel) {
+    iterationDirsDeleted.set(dirDel);
+  }
+
+  public void setIterationSubDirDeleted(long subdirDel) {
+    iterationSubDirsDeleted.set(subdirDel);
+  }
+
+  public void setIterationFilesSentForPurge(long filesMove) {
+    iterationFilesSentForPurge.set(filesMove);
+  }
+
+  public void setIterationSubDirsSentForPurge(long subdirMove) {
+    iterationSubDirsSentForPurge.set(subdirMove);
+  }
+
+  public void setDirectoryDeletionIterationMetrics(long runcount, long 
startTime, long duration,
+                                                   long dirDel, long subdirDel,
+                                                   long filesMove, long 
subdirMove) {
+    setIterationDirRunCount(runcount);
+    setIterationDirStartTime(startTime);
+    setIterationDirDuration(duration);
+    setIterationDirDeleted(dirDel);
+    setIterationSubDirDeleted(subdirDel);
+    setIterationFilesSentForPurge(filesMove);
+    setIterationSubDirsSentForPurge(subdirMove);
+  }
+
+  /*
+   * Total key deletion metrics across all iterations of KeyDeletingService 
since last restart.
+   */
+  @Metric("Total no. of keys processed")
+  private MutableGaugeLong numKeysProcessed;
+  @Metric("Total no. of keys sent to scm for deletion")
+  private MutableGaugeLong numKeysDeletionRequest;
+  @Metric("Total no. of keys deleted successfully")
+  private MutableGaugeLong numKeysDeleteSuccess;
+  @Metric("Total no. of deleted keys sent for purge")
+  private MutableGaugeLong numKeysSentForPurge;
+
+  public void incrNumKeysProcessed(long keysProcessed) {
+    this.numKeysProcessed.incr(keysProcessed);
+  }
+
+  public void incrNumKeysDeletionRequest(long keysDeletionRequest) {
+    this.numKeysDeletionRequest.incr(keysDeletionRequest);
+  }
+
+  public void incrNumKeysDeleteSuccess(long keysDeleteSuccess) {
+    this.numKeysDeleteSuccess.incr(keysDeleteSuccess);
+  }
+
+  public void incrNumKeysSentForPurge(long keysPurge) {
+    this.numKeysSentForPurge.incr(keysPurge);
+  }
+
+  /*
+   * Key deletion metrics in the latest iteration of KeyDeletingService.
+   */
+  @Metric("Iteration run count of KeyDeletingService")
+  private MutableGaugeLong iterationKeyRunCount;
+  @Metric("Iteration start time of KeyDeletingService")
+  private MutableGaugeLong iterationKeyStartTime;

Review Comment:
   do not need metrics for run count and start time



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/OpenKeyCleanupService.java:
##########
@@ -228,11 +228,15 @@ public BackgroundTaskResult call() throws Exception {
         });
       }
 
+      long duration = Time.monotonicNow() - startTime;
       if (LOG.isDebugEnabled()) {
         LOG.debug("Number of expired open keys submitted for deletion: {},"
                 + " for commit: {}, elapsed time: {}ms",
-            numOpenKeys, numHsyncKeys, Time.monotonicNow() - startTime);
+            numOpenKeys, numHsyncKeys, duration);
       }
+      
ozoneManager.getDeletionMetrics().setOpenKeyCleanupIterationMetrics(runCount.get(),
 startTime,

Review Comment:
   already metrics are present for cleanup, this is not required



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -220,8 +225,15 @@ public BackgroundTaskResult call() {
           if (keyBlocksList != null && !keyBlocksList.isEmpty()) {
             delCount = processKeyDeletes(keyBlocksList,
                 getOzoneManager().getKeyManager(),
-                pendingKeysDeletion.getKeysToModify(), null, 
expectedPreviousSnapshotId);
+                pendingKeysDeletion.getKeysToModify(), null, 
expectedPreviousSnapshotId, true);
             deletedKeyCount.addAndGet(delCount);
+            metrics.setIterationKeyRunCount(run);
+            metrics.setIterationKeyStartTime(startTime);
+            metrics.setIterationKeyDuration(Time.monotonicNow() - startTime);
+            metrics.setIterationKeysProcessed(keyBlocksList.size());
+            metrics.setIterationKeysSentForPurge(delCount);
+            metrics.incrNumKeysProcessed(keyBlocksList.size());

Review Comment:
   Check for naming, blocks and keys separately.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -220,8 +225,15 @@ public BackgroundTaskResult call() {
           if (keyBlocksList != null && !keyBlocksList.isEmpty()) {
             delCount = processKeyDeletes(keyBlocksList,
                 getOzoneManager().getKeyManager(),
-                pendingKeysDeletion.getKeysToModify(), null, 
expectedPreviousSnapshotId);
+                pendingKeysDeletion.getKeysToModify(), null, 
expectedPreviousSnapshotId, true);
             deletedKeyCount.addAndGet(delCount);
+            metrics.setIterationKeyRunCount(run);
+            metrics.setIterationKeyStartTime(startTime);
+            metrics.setIterationKeyDuration(Time.monotonicNow() - startTime);
+            metrics.setIterationKeysProcessed(keyBlocksList.size());

Review Comment:
   do not need capture iteration information, as its present as part of info 
log. 



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/DeletingServiceMetrics.java:
##########
@@ -0,0 +1,336 @@
+/**
+ * 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 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;
+
+/**
+ * Class contains metrics related to the OM Deletion services.
+ */
+@Metrics(about = "Deletion Service Metrics", context = OzoneConsts.OZONE)
+public final class DeletingServiceMetrics {
+
+  public static final String METRICS_SOURCE_NAME =
+      DeletingServiceMetrics.class.getSimpleName();
+  private MetricsRegistry registry;
+
+  private DeletingServiceMetrics() {
+    this.registry = new MetricsRegistry(METRICS_SOURCE_NAME);
+  }
+
+  /**
+   * Creates and returns DeletingServiceMetrics instance.
+   *
+   * @return DeletingServiceMetrics
+   */
+  public static DeletingServiceMetrics create() {
+    return DefaultMetricsSystem.instance().register(METRICS_SOURCE_NAME,
+        "Metrics tracking the progress of deletion of directories and keys in 
the OM",
+        new DeletingServiceMetrics());
+  }
+  /**
+   * Unregister the metrics instance.
+   */
+  public static void unregister() {
+    DefaultMetricsSystem.instance().unregisterSource(METRICS_SOURCE_NAME);
+  }
+
+
+  /*
+   * Total directory deletion metrics across all iterations of 
DirectoryDeletingService since last restart.
+   */
+  @Metric("Total no. of deleted directories sent for purge")
+  private MutableGaugeLong numDirsSentForPurge;
+  @Metric("Total no. of sub-directories sent for purge")
+  private MutableGaugeLong numSubDirsSentForPurge;
+  @Metric("Total no. of sub-files sent for purge")
+  private MutableGaugeLong numSubFilesSentForPurge;
+
+  public void incrNumDirDeleted(long dirDel) {
+    numDirsSentForPurge.incr(dirDel);
+  }
+
+  public void incrNumDirsMoved(long dirMove) {
+    numSubDirsSentForPurge.incr(dirMove);
+  }
+
+  public void incrNumFilesMoved(long filesMove) {
+    numSubFilesSentForPurge.incr(filesMove);
+  }
+
+  public void incrementDirectoryDeletionTotalMetrics(long dirDel, long 
dirMove, long filesMove) {
+    incrNumDirDeleted(dirDel);
+    incrNumDirsMoved(dirMove);
+    incrNumFilesMoved(filesMove);
+  }
+
+  /*
+   * Directory deletion metrics in the latest iteration of 
DirectoryDeletingService.
+   */
+  @Metric("Iteration run count of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirRunCount;
+  @Metric("Iteration start time of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirStartTime;
+  @Metric("Total time taken by the last iteration of DirectoryDeletingService")
+  private MutableGaugeLong iterationDirDuration;
+  @Metric("No. of directories deleted in last iteration")
+  private MutableGaugeLong iterationDirsDeleted;
+  @Metric("No. of sub-directories deleted in last iteration")
+  private MutableGaugeLong iterationSubDirsDeleted;
+  @Metric("No. of sub-directories sent for purge in last iteration")
+  private MutableGaugeLong iterationSubDirsSentForPurge;
+  @Metric("No. of files sent for purge in last iteration")
+  private MutableGaugeLong iterationFilesSentForPurge;
+
+  public void setIterationDirRunCount(long runcount) {
+    iterationDirRunCount.set(runcount);
+  }
+
+  public void setIterationDirStartTime(long startTime) {
+    iterationDirStartTime.set(startTime);
+  }
+
+  public void setIterationDirDuration(long duration) {
+    iterationDirDuration.set(duration);
+  }
+
+  public void setIterationDirDeleted(long dirDel) {
+    iterationDirsDeleted.set(dirDel);
+  }
+
+  public void setIterationSubDirDeleted(long subdirDel) {
+    iterationSubDirsDeleted.set(subdirDel);
+  }
+
+  public void setIterationFilesSentForPurge(long filesMove) {
+    iterationFilesSentForPurge.set(filesMove);
+  }
+
+  public void setIterationSubDirsSentForPurge(long subdirMove) {
+    iterationSubDirsSentForPurge.set(subdirMove);
+  }
+
+  public void setDirectoryDeletionIterationMetrics(long runcount, long 
startTime, long duration,
+                                                   long dirDel, long subdirDel,
+                                                   long filesMove, long 
subdirMove) {
+    setIterationDirRunCount(runcount);
+    setIterationDirStartTime(startTime);
+    setIterationDirDuration(duration);
+    setIterationDirDeleted(dirDel);
+    setIterationSubDirDeleted(subdirDel);
+    setIterationFilesSentForPurge(filesMove);

Review Comment:
   iteration level merics not required as its logged and overall metrics is 
there and information can be derived from that.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/DeletingServiceMetrics.java:
##########
@@ -0,0 +1,336 @@
+/**
+ * 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 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;
+
+/**
+ * Class contains metrics related to the OM Deletion services.
+ */
+@Metrics(about = "Deletion Service Metrics", context = OzoneConsts.OZONE)
+public final class DeletingServiceMetrics {
+
+  public static final String METRICS_SOURCE_NAME =
+      DeletingServiceMetrics.class.getSimpleName();
+  private MetricsRegistry registry;
+
+  private DeletingServiceMetrics() {
+    this.registry = new MetricsRegistry(METRICS_SOURCE_NAME);
+  }
+
+  /**
+   * Creates and returns DeletingServiceMetrics instance.
+   *
+   * @return DeletingServiceMetrics
+   */
+  public static DeletingServiceMetrics create() {
+    return DefaultMetricsSystem.instance().register(METRICS_SOURCE_NAME,
+        "Metrics tracking the progress of deletion of directories and keys in 
the OM",
+        new DeletingServiceMetrics());
+  }
+  /**
+   * Unregister the metrics instance.
+   */
+  public static void unregister() {
+    DefaultMetricsSystem.instance().unregisterSource(METRICS_SOURCE_NAME);
+  }
+
+
+  /*
+   * Total directory deletion metrics across all iterations of 
DirectoryDeletingService since last restart.
+   */
+  @Metric("Total no. of deleted directories sent for purge")
+  private MutableGaugeLong numDirsSentForPurge;
+  @Metric("Total no. of sub-directories sent for purge")
+  private MutableGaugeLong numSubDirsSentForPurge;
+  @Metric("Total no. of sub-files sent for purge")
+  private MutableGaugeLong numSubFilesSentForPurge;
+
+  public void incrNumDirDeleted(long dirDel) {

Review Comment:
   method name and field param should match, else will give wrong info



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyDeletingService.java:
##########
@@ -220,8 +225,15 @@ public BackgroundTaskResult call() {
           if (keyBlocksList != null && !keyBlocksList.isEmpty()) {
             delCount = processKeyDeletes(keyBlocksList,
                 getOzoneManager().getKeyManager(),
-                pendingKeysDeletion.getKeysToModify(), null, 
expectedPreviousSnapshotId);
+                pendingKeysDeletion.getKeysToModify(), null, 
expectedPreviousSnapshotId, true);
             deletedKeyCount.addAndGet(delCount);
+            metrics.setIterationKeyRunCount(run);
+            metrics.setIterationKeyStartTime(startTime);
+            metrics.setIterationKeyDuration(Time.monotonicNow() - startTime);
+            metrics.setIterationKeysProcessed(keyBlocksList.size());
+            metrics.setIterationKeysSentForPurge(delCount);
+            metrics.incrNumKeysProcessed(keyBlocksList.size());

Review Comment:
   numKeysProcessed --> number of keys operated 
   



-- 
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]

Reply via email to