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

sarvekshayr 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 e62603cf3ca HDDS-16611. Use MutableGaugeLong for total count metrics 
in OMMetrics (#11410)
e62603cf3ca is described below

commit e62603cf3cafb11b0afc58a16ef15e7d47e5e309
Author: Chi-Hsuan Huang <[email protected]>
AuthorDate: Wed Oct 7 16:33:12 2026 +0800

    HDDS-16611. Use MutableGaugeLong for total count metrics in OMMetrics 
(#11410)
---
 .../Ozone - Memory Consumption Metrics.json        |  4 +-
 .../org/apache/hadoop/ozone/om/TestOmMetrics.java  | 53 ++++++++++----------
 .../java/org/apache/hadoop/ozone/om/OMMetrics.java | 34 ++++++-------
 .../hadoop/ozone/om/TestOMMetricsSetters.java      | 58 ++++++++++++++++++++++
 4 files changed, 102 insertions(+), 47 deletions(-)

diff --git a/hadoop-ozone/dist/src/main/compose/common/grafana/dashboards/Ozone 
- Memory Consumption Metrics.json 
b/hadoop-ozone/dist/src/main/compose/common/grafana/dashboards/Ozone - Memory 
Consumption Metrics.json
index 4398b526eb5..d4c243386eb 100644
--- a/hadoop-ozone/dist/src/main/compose/common/grafana/dashboards/Ozone - 
Memory Consumption Metrics.json      
+++ b/hadoop-ozone/dist/src/main/compose/common/grafana/dashboards/Ozone - 
Memory Consumption Metrics.json      
@@ -231,7 +231,7 @@
           },
           "disableTextWrap": false,
           "editorMode": "builder",
-          "expr": "rate(om_metrics_num_keys[1m])",
+          "expr": "deriv(om_metrics_num_keys[1m])",
           "fullMetaSearch": false,
           "includeNullMetadata": true,
           "instant": false,
@@ -241,7 +241,7 @@
           "useBackend": false
         }
       ],
-      "title": "Key Creation Rate",
+      "title": "Key Count Change Rate",
       "type": "timeseries"
     },
     {
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java
index 92974a69ee9..7ca715d7d26 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmMetrics.java
@@ -25,6 +25,7 @@
 import static 
org.apache.hadoop.ozone.security.acl.OzoneObj.ResourceType.VOLUME;
 import static org.apache.hadoop.ozone.security.acl.OzoneObj.StoreType.OZONE;
 import static org.apache.ozone.test.MetricsAsserts.getLongCounter;
+import static org.apache.ozone.test.MetricsAsserts.getLongGauge;
 import static org.apache.ozone.test.MetricsAsserts.getMetrics;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -153,7 +154,7 @@ public void testVolumeOps() throws Exception {
     long initialNumVolumeInfos = getLongCounter("NumVolumeInfos", omMetrics);
     long initialNumVolumeDeletes = getLongCounter("NumVolumeDeletes", 
omMetrics);
     long initialNumVolumeLists = getLongCounter("NumVolumeLists", omMetrics);
-    long initialNumVolumes = getLongCounter("NumVolumes", omMetrics);
+    long initialNumVolumes = getLongGauge("NumVolumes", omMetrics);
 
     long initialNumVolumeCreateFails = getLongCounter("NumVolumeCreateFails", 
omMetrics);
     long initialNumVolumeUpdateFails = getLongCounter("NumVolumeUpdateFails", 
omMetrics);
@@ -171,7 +172,7 @@ public void testVolumeOps() throws Exception {
     assertEquals(initialNumVolumeInfos + 1, getLongCounter("NumVolumeInfos", 
omMetrics));
     assertEquals(initialNumVolumeDeletes + 1, 
getLongCounter("NumVolumeDeletes", omMetrics));
     assertEquals(initialNumVolumeLists + 1, getLongCounter("NumVolumeLists", 
omMetrics));
-    assertEquals(initialNumVolumes, getLongCounter("NumVolumes", omMetrics));
+    assertEquals(initialNumVolumes, getLongGauge("NumVolumes", omMetrics));
 
     volumeArgs = createVolumeArgs();
     writeClient.createVolume(volumeArgs);
@@ -183,7 +184,7 @@ public void testVolumeOps() throws Exception {
 
     omMetrics = getMetrics("OMMetrics");
     // Accounting 's3v' volume which is created by default.
-    assertEquals(initialNumVolumes + 2, getLongCounter("NumVolumes", 
omMetrics));
+    assertEquals(initialNumVolumes + 2, getLongGauge("NumVolumes", omMetrics));
 
     // inject exception to test for Failure Metrics on the read path
     doThrow(exception).when(mockVm).getVolumeInfo(any());
@@ -211,7 +212,7 @@ public void testVolumeOps() throws Exception {
     assertEquals(initialNumVolumeInfoFails + 1, 
getLongCounter("NumVolumeInfoFails", omMetrics));
     assertEquals(initialNumVolumeDeleteFails + 1, 
getLongCounter("NumVolumeDeleteFails", omMetrics));
     assertEquals(initialNumVolumeListFails + 1, 
getLongCounter("NumVolumeListFails", omMetrics));
-    assertEquals(initialNumVolumes + 2, getLongCounter("NumVolumes", 
omMetrics));
+    assertEquals(initialNumVolumes + 2, getLongGauge("NumVolumes", omMetrics));
 
     // restore state
     HddsWhiteboxTestUtils.setInternalState(ozoneManager,
@@ -235,7 +236,7 @@ public void testBucketOps() throws Exception {
     long initialNumBucketInfos = getLongCounter("NumBucketInfos", omMetrics);
     long initialNumBucketDeletes = getLongCounter("NumBucketDeletes", 
omMetrics);
     long initialNumBucketLists = getLongCounter("NumBucketLists", omMetrics);
-    long initialNumBuckets = getLongCounter("NumBuckets", omMetrics);
+    long initialNumBuckets = getLongGauge("NumBuckets", omMetrics);
     long initialEcBucketCreateTotal = getLongCounter("EcBucketCreateTotal", 
omMetrics);
     long initialEcBucketCreateFailsTotal = 
getLongCounter("EcBucketCreateFailsTotal", omMetrics);
 
@@ -255,7 +256,7 @@ public void testBucketOps() throws Exception {
     assertEquals(initialNumBucketInfos + 1, getLongCounter("NumBucketInfos", 
omMetrics));
     assertEquals(initialNumBucketDeletes + 1, 
getLongCounter("NumBucketDeletes", omMetrics));
     assertEquals(initialNumBucketLists + 1, getLongCounter("NumBucketLists", 
omMetrics));
-    assertEquals(initialNumBuckets, getLongCounter("NumBuckets", omMetrics));
+    assertEquals(initialNumBuckets, getLongGauge("NumBuckets", omMetrics));
 
     OmBucketInfo ecBucketInfo = createBucketInfo(true);
     writeClient.createBucket(ecBucketInfo);
@@ -275,7 +276,7 @@ public void testBucketOps() throws Exception {
         bucketInfo.getBucketName());
 
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumBuckets + 2, getLongCounter("NumBuckets", 
omMetrics));
+    assertEquals(initialNumBuckets + 2, getLongGauge("NumBuckets", omMetrics));
 
     // inject exception to test for Failure Metrics on the read path
     doThrow(exception).when(mockBm).getBucketInfo(any(), any());
@@ -309,7 +310,7 @@ public void testBucketOps() throws Exception {
     assertEquals(initialNumBucketInfoFails + 1, 
getLongCounter("NumBucketInfoFails", omMetrics));
     assertEquals(initialNumBucketDeleteFails + 1, 
getLongCounter("NumBucketDeleteFails", omMetrics));
     assertEquals(initialNumBucketListFails + 1, 
getLongCounter("NumBucketListFails", omMetrics));
-    assertEquals(initialNumBuckets + 2, getLongCounter("NumBuckets", 
omMetrics));
+    assertEquals(initialNumBuckets + 2, getLongGauge("NumBuckets", omMetrics));
 
     // restore state
     HddsWhiteboxTestUtils.setInternalState(ozoneManager,
@@ -333,7 +334,7 @@ public void testKeyOps() throws Exception {
     long initialNumKeyLookup = getLongCounter("NumKeyLookup", omMetrics);
     long initialNumKeyDeletes = getLongCounter("NumKeyDeletes", omMetrics);
     long initialNumKeyLists = getLongCounter("NumKeyLists", omMetrics);
-    long initialNumKeys = getLongCounter("NumKeys", omMetrics);
+    long initialNumKeys = getLongGauge("NumKeys", omMetrics);
     long initialNumInitiateMultipartUploads = 
getLongCounter("NumInitiateMultipartUploads", omMetrics);
     long initialNumGetObjectTagging = getLongCounter("NumGetObjectTagging", 
omMetrics);
     long initialNumPutObjectTagging = getLongCounter("NumPutObjectTagging", 
omMetrics);
@@ -364,7 +365,7 @@ public void testKeyOps() throws Exception {
     assertEquals(initialNumKeyLookup + 1, getLongCounter("NumKeyLookup", 
omMetrics));
     assertEquals(initialNumKeyDeletes + 1, getLongCounter("NumKeyDeletes", 
omMetrics));
     assertEquals(initialNumKeyLists + 1, getLongCounter("NumKeyLists", 
omMetrics));
-    assertEquals(initialNumKeys, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys, getLongGauge("NumKeys", omMetrics));
     assertEquals(initialNumInitiateMultipartUploads + 1, 
getLongCounter("NumInitiateMultipartUploads", omMetrics));
     assertEquals(initialNumGetObjectTagging + 1, 
getLongCounter("NumGetObjectTagging", omMetrics));
     assertEquals(initialNumPutObjectTagging + 1, 
getLongCounter("NumPutObjectTagging", omMetrics));
@@ -375,7 +376,7 @@ public void testKeyOps() throws Exception {
     doKeyOps(keyArgs);
 
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumKeys, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys, getLongGauge("NumKeys", omMetrics));
     assertEquals(initialEcKeyCreateTotal + 1, 
getLongCounter("EcKeyCreateTotal", omMetrics));
 
     keyArgs = createKeyArgs(volumeName, bucketName,
@@ -403,7 +404,7 @@ public void testKeyOps() throws Exception {
     }
 
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumKeys + 2, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys + 2, getLongGauge("NumKeys", omMetrics));
     assertEquals(initialNumBlockAllocationFails + 1, 
getLongCounter("NumBlockAllocationFails", omMetrics));
 
     // inject exception to test for Failure Metrics on the read path
@@ -439,7 +440,7 @@ public void testKeyOps() throws Exception {
     assertEquals(initialNumKeyListFails + 1, getLongCounter("NumKeyListFails", 
omMetrics));
     assertEquals(initialNumInitiateMultipartUploadFails + 1, getLongCounter(
         "NumInitiateMultipartUploadFails", omMetrics));
-    assertEquals(initialNumKeys + 2, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys + 2, getLongGauge("NumKeys", omMetrics));
     assertEquals(initialNumGetObjectTaggingFails + 1,  
getLongCounter("NumGetObjectTaggingFails", omMetrics));
     assertEquals(initialNumPutObjectTaggingFails + 1, 
getLongCounter("NumPutObjectTaggingFails", omMetrics));
     assertEquals(initialNumDeleteObjectTaggingFails + 1, 
getLongCounter("NumDeleteObjectTaggingFails", omMetrics));
@@ -467,7 +468,7 @@ public void testKeyOps() throws Exception {
   public void testDirectoryOps(BucketLayout bucketLayout) throws Exception {
     // get initial values for metrics
     MetricsRecordBuilder omMetrics = getMetrics("OMMetrics");
-    long initialNumKeys = getLongCounter("NumKeys", omMetrics);
+    long initialNumKeys = getLongGauge("NumKeys", omMetrics);
     long initialNumCreateDirectory = getLongCounter("NumCreateDirectory", 
omMetrics);
     long initialNumKeyDeletes = getLongCounter("NumKeyDeletes", omMetrics);
     long initialNumKeyRenames = getLongCounter("NumKeyRenames", omMetrics);
@@ -496,7 +497,7 @@ public void testDirectoryOps(BucketLayout bucketLayout) 
throws Exception {
     assertEquals(bucketLayout,
         
client.getObjectStore().getVolume(volumeName).getBucket(bucketName).getBucketLayout());
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumKeys + 2, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys + 2, getLongGauge("NumKeys", omMetrics));
     // Only one directory create command is given, even though it created two 
directories.
     assertEquals(initialNumCreateDirectory + 1, 
getLongCounter("NumCreateDirectory", omMetrics));
     assertEquals(initialNumKeyDeletes, getLongCounter("NumKeyDeletes", 
omMetrics));
@@ -507,7 +508,7 @@ public void testDirectoryOps(BucketLayout bucketLayout) 
throws Exception {
     ContractTestUtils.touch(fs, new Path(dirPath, "file1"));
     ContractTestUtils.touch(fs, new Path(dirPath.getParent(), "file2"));
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumKeys + 4, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys + 4, getLongGauge("NumKeys", omMetrics));
     assertEquals(initialNumCreateDirectory + 1, 
getLongCounter("NumCreateDirectory", omMetrics));
     assertEquals(initialNumKeyDeletes, getLongCounter("NumKeyDeletes", 
omMetrics));
     assertEquals(initialNumKeyRenames, getLongCounter("NumKeyRenames", 
omMetrics));
@@ -515,7 +516,7 @@ public void testDirectoryOps(BucketLayout bucketLayout) 
throws Exception {
     // Rename the child directory.
     fs.rename(dirPath, new Path(dirPath.getParent(), "new-name"));
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumKeys + 4, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys + 4, getLongGauge("NumKeys", omMetrics));
     assertEquals(initialNumCreateDirectory + 1, 
getLongCounter("NumCreateDirectory", omMetrics));
     assertEquals(initialNumKeyDeletes, getLongCounter("NumKeyDeletes", 
omMetrics));
     long expectedRenames = 1;
@@ -526,17 +527,17 @@ public void testDirectoryOps(BucketLayout bucketLayout) 
throws Exception {
     assertEquals(initialNumKeyRenames + expectedRenames, 
getLongCounter("NumKeyRenames", omMetrics));
 
     // Delete metric should be decremented by directory deleting service in 
the background.
-    long numKeysBeforeDeletion = getLongCounter("NumKeys", omMetrics);
+    long numKeysBeforeDeletion = getLongGauge("NumKeys", omMetrics);
     fs.delete(dirPath.getParent(), true);
     GenericTestUtils.waitFor(() -> {
-      long keyCount = getLongCounter("NumKeys", getMetrics("OMMetrics"));
+      long keyCount = getLongGauge("NumKeys", getMetrics("OMMetrics"));
       return keyCount == 0;
     }, timeoutMillis / 5, timeoutMillis);
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumKeys, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys, getLongGauge("NumKeys", omMetrics));
     // This is the number of times the create directory command was given, not 
the current number of directories.
     assertEquals(initialNumCreateDirectory + 1, 
getLongCounter("NumCreateDirectory", omMetrics));
-    numKeysDeleted += numKeysBeforeDeletion - getLongCounter("NumKeys", 
omMetrics);
+    numKeysDeleted += numKeysBeforeDeletion - getLongGauge("NumKeys", 
omMetrics);
     assertEquals(initialNumKeyDeletes + numKeysDeleted, 
getLongCounter("NumKeyDeletes", omMetrics));
     assertEquals(initialNumKeyRenames + expectedRenames, 
getLongCounter("NumKeyRenames", omMetrics));
 
@@ -546,17 +547,17 @@ public void testDirectoryOps(BucketLayout bucketLayout) 
throws Exception {
     ContractTestUtils.touch(fs, new Path(dirPath, "file1"));
     ContractTestUtils.touch(fs, new Path(dirPath.getParent(), "file2"));
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumKeys + 4, getLongCounter("NumKeys", omMetrics));
-    numKeysBeforeDeletion = getLongCounter("NumKeys", omMetrics);
+    assertEquals(initialNumKeys + 4, getLongGauge("NumKeys", omMetrics));
+    numKeysBeforeDeletion = getLongGauge("NumKeys", omMetrics);
     fs.delete(bucketPath, true);
     GenericTestUtils.waitFor(() -> {
-      long keyCount = getLongCounter("NumKeys", getMetrics("OMMetrics"));
+      long keyCount = getLongGauge("NumKeys", getMetrics("OMMetrics"));
       return keyCount == 0;
     }, timeoutMillis / 5, timeoutMillis);
     omMetrics = getMetrics("OMMetrics");
-    assertEquals(initialNumKeys, getLongCounter("NumKeys", omMetrics));
+    assertEquals(initialNumKeys, getLongGauge("NumKeys", omMetrics));
     assertEquals(initialNumCreateDirectory + 2, 
getLongCounter("NumCreateDirectory", omMetrics));
-    numKeysDeleted += numKeysBeforeDeletion - getLongCounter("NumKeys", 
omMetrics);
+    numKeysDeleted += numKeysBeforeDeletion - getLongGauge("NumKeys", 
omMetrics);
     assertEquals(initialNumKeyDeletes + numKeysDeleted, 
getLongCounter("NumKeyDeletes", omMetrics));
     assertEquals(initialNumKeyRenames + expectedRenames, 
getLongCounter("NumKeyRenames", omMetrics));
   }
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMetrics.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMetrics.java
index 57697fb4b01..ff74e6b6e67 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMetrics.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OMMetrics.java
@@ -29,6 +29,7 @@
 import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
 import org.apache.hadoop.metrics2.lib.MutableCounterLong;
 import org.apache.hadoop.metrics2.lib.MutableGaugeInt;
+import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
 import org.apache.hadoop.ozone.om.snapshot.OMSnapshotDirectoryMetrics;
 import org.apache.hadoop.util.Time;
 
@@ -219,14 +220,14 @@ public class OMMetrics implements OmMetadataReaderMetrics 
{
 
   // Metrics for total number of volumes, buckets and keys
 
-  private @Metric MutableCounterLong numVolumes;
-  private @Metric MutableCounterLong numBuckets;
+  private @Metric MutableGaugeLong numVolumes;
+  private @Metric MutableGaugeLong numBuckets;
   private @Metric MutableCounterLong numS3Buckets;
 
   //TODO: This metric is an estimate and it may be inaccurate on restart if the
   // OM process was not shutdown cleanly. Key creations/deletions in the last
   // few minutes before restart may not be included in this count.
-  private @Metric MutableCounterLong numKeys;
+  private @Metric MutableGaugeLong numKeys;
 
   private @Metric MutableCounterLong numBucketS3Creates;
   private @Metric MutableCounterLong numBucketS3CreateFails;
@@ -256,8 +257,8 @@ public class OMMetrics implements OmMetadataReaderMetrics {
   private @Metric MutableCounterLong numTrashAtomicDirDeletes;
 
   //FSO Metrics
-  private @Metric MutableCounterLong numDirs;
-  private @Metric MutableCounterLong numFiles;
+  private @Metric MutableGaugeLong numDirs;
+  private @Metric MutableGaugeLong numFiles;
 
   //EC Metrics
   private @Metric MutableCounterLong ecKeyCreateTotal;
@@ -353,7 +354,7 @@ public void incNumVolumes() {
   }
 
   public void decNumVolumes() {
-    numVolumes.incr(-1);
+    numVolumes.decr();
   }
 
   public void incNumBuckets() {
@@ -361,7 +362,7 @@ public void incNumBuckets() {
   }
 
   public void decNumBuckets() {
-    numBuckets.incr(-1);
+    numBuckets.decr();
   }
 
   public void incNumKeys() {
@@ -373,36 +374,31 @@ public void incNumKeys(int count) {
   }
 
   public void decNumKeys() {
-    numKeys.incr(-1);
+    numKeys.decr();
   }
 
   public void setNumVolumes(long val) {
-    long oldVal = this.numVolumes.value();
-    this.numVolumes.incr(val - oldVal);
+    this.numVolumes.set(val);
   }
 
   public void setNumBuckets(long val) {
-    long oldVal = this.numBuckets.value();
-    this.numBuckets.incr(val - oldVal);
+    this.numBuckets.set(val);
   }
 
   public void setNumKeys(long val) {
-    long oldVal = this.numKeys.value();
-    this.numKeys.incr(val - oldVal);
+    this.numKeys.set(val);
   }
 
   public void setNumDirs(long val) {
-    long oldVal = this.numDirs.value();
-    this.numDirs.incr(val - oldVal);
+    this.numDirs.set(val);
   }
 
   public void setNumFiles(long val) {
-    long oldVal = this.numDirs.value();
-    this.numDirs.incr(val - oldVal);
+    this.numFiles.set(val);
   }
 
   public void decNumKeys(long val) {
-    this.numKeys.incr(-val);
+    this.numKeys.decr(val);
   }
 
   public long getNumVolumes() {
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOMMetricsSetters.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOMMetricsSetters.java
new file mode 100644
index 00000000000..c5b3db104d2
--- /dev/null
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOMMetricsSetters.java
@@ -0,0 +1,58 @@
+/*
+ * 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.ozone.test.MetricsAsserts.assertGauge;
+import static org.apache.ozone.test.MetricsAsserts.getMetrics;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link OMMetrics}.
+ */
+public class TestOMMetricsSetters {
+
+  private OMMetrics metrics;
+
+  @AfterEach
+  public void cleanUp() {
+    if (metrics != null) {
+      metrics.unRegister();
+    }
+  }
+
+  @Test
+  public void testSetTotals() {
+    metrics = OMMetrics.create(new OzoneConfiguration());
+    metrics.setNumVolumes(1);
+    metrics.setNumBuckets(2);
+    metrics.setNumKeys(3);
+    metrics.setNumDirs(4);
+    metrics.setNumFiles(5);
+
+    MetricsRecordBuilder rb = getMetrics("OMMetrics");
+    assertGauge("NumVolumes", 1L, rb);
+    assertGauge("NumBuckets", 2L, rb);
+    assertGauge("NumKeys", 3L, rb);
+    assertGauge("NumDirs", 4L, rb);
+    assertGauge("NumFiles", 5L, rb);
+  }
+}


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

Reply via email to