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

slfan1989 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1a81c3b564e HDFS-17725. DataNodeVolumeMetrics and BalancerMetrics 
class add MetricTag. (#7382) Contributed by Zhaobo Huang.
1a81c3b564e is described below

commit 1a81c3b564e35574ccabd864500618c708a88ee6
Author: Zhaobo Huang <huangzhaob...@126.com>
AuthorDate: Mon Feb 24 16:23:55 2025 +0800

    HDFS-17725. DataNodeVolumeMetrics and BalancerMetrics class add MetricTag. 
(#7382) Contributed by Zhaobo Huang.
    
    Signed-off-by: Shilun Fan <slfan1...@apache.org>
---
 .../apache/hadoop/hdfs/server/balancer/BalancerMetrics.java |  5 +++++
 .../server/datanode/fsdataset/DataNodeVolumeMetrics.java    |  9 +++++++++
 .../hadoop/hdfs/server/balancer/TestBalancerService.java    | 13 +++++++++++++
 .../hdfs/server/datanode/TestDataNodeVolumeMetrics.java     |  4 ++++
 4 files changed, 31 insertions(+)

diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancerMetrics.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancerMetrics.java
index 77f3795bf69..648039da584 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancerMetrics.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancerMetrics.java
@@ -43,6 +43,11 @@ final class BalancerMetrics {
   @Metric("Number of over utilized nodes")
   private MutableGaugeInt numOfOverUtilizedNodes;
 
+  @Metric(value = {"BlockPoolID", "Current BlockPoolID"}, type = 
Metric.Type.TAG)
+  public String getBlockPoolID() {
+    return balancer.getNnc().getBlockpoolID();
+  }
+
   private BalancerMetrics(Balancer b) {
     this.balancer = b;
   }
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/DataNodeVolumeMetrics.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/DataNodeVolumeMetrics.java
index 0ce57efd595..ff2a07b02a4 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/DataNodeVolumeMetrics.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/DataNodeVolumeMetrics.java
@@ -31,6 +31,8 @@
 import org.apache.hadoop.metrics2.lib.MutableRate;
 
 import java.util.concurrent.ThreadLocalRandom;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * This class is for maintaining Datanode Volume IO related statistics and
@@ -43,6 +45,13 @@
 public class DataNodeVolumeMetrics {
   private final MetricsRegistry registry = new MetricsRegistry("FsVolume");
 
+  @Metric(value = {"VolumeName", "Current VolumeName"}, type = Metric.Type.TAG)
+  public String getVolumeName() {
+    Pattern pattern = 
Pattern.compile("(?:DataNodeVolume-|UndefinedDataNodeVolume)(.*)");
+    Matcher matcher = pattern.matcher(name);
+    return matcher.find() ? matcher.group(1) : name;
+  }
+
   @Metric("number of metadata operations")
   private MutableCounterLong totalMetadataOperations;
   @Metric("metadata operation rate")
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerService.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerService.java
index 6256e858e3c..230945d0963 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerService.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerService.java
@@ -242,6 +242,19 @@ public void testBalancerServiceMetrics() throws Exception {
         }
       }, 100, 10000);
 
+      GenericTestUtils.waitFor(() -> {
+        final String balancerMetricsName =
+            "Balancer-" + 
cluster.getNameNode(0).getNamesystem().getBlockPoolId();
+        String blockPoolId = 
cluster.getNameNode(0).getNamesystem().getBlockPoolId();
+        MetricsRecordBuilder metrics = 
MetricsAsserts.getMetrics(balancerMetricsName);
+        try {
+          MetricsAsserts.assertTag("BlockPoolID", blockPoolId, metrics);
+          return true;
+        } catch (Exception e) {
+          return false;
+        }
+      }, 100, 10000);
+
       TestBalancer.waitForBalancer(totalUsedSpace, totalCapacity, client, 
cluster,
           BalancerParameters.DEFAULT);
 
diff --git 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeVolumeMetrics.java
 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeVolumeMetrics.java
index 7a62f8da6a1..39dca28638f 100644
--- 
a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeVolumeMetrics.java
+++ 
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeVolumeMetrics.java
@@ -44,6 +44,8 @@
 import org.apache.hadoop.hdfs.server.datanode.fsdataset.DataNodeVolumeMetrics;
 import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi;
 import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.test.MetricsAsserts;
+
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.Timeout;
@@ -187,6 +189,8 @@ private void verifyDataNodeVolumeMetrics(final FileSystem 
fs,
         + metrics.getFileIoErrorSampleCount());
     LOG.info("fileIoErrorMean : " + metrics.getFileIoErrorMean());
     LOG.info("fileIoErrorStdDev : " + metrics.getFileIoErrorStdDev());
+
+    MetricsAsserts.assertTag("VolumeName", metrics.getVolumeName(), rb);
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to