Skip to content

Commit bae11b9

Browse files
committed
HDFS-17725. DataNodeVolumeMetrics and BalancerMetrics class add MetricTag.
1 parent 19bd575 commit bae11b9

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancerMetrics.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ final class BalancerMetrics {
4343
@Metric("Number of over utilized nodes")
4444
private MutableGaugeInt numOfOverUtilizedNodes;
4545

46+
@Metric(value = {"BlockPoolID", "Current BlockPoolID"}, type = Metric.Type.TAG)
47+
public String getBlockPoolID() {
48+
return balancer.getNnc().getBlockpoolID();
49+
}
50+
4651
private BalancerMetrics(Balancer b) {
4752
this.balancer = b;
4853
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/DataNodeVolumeMetrics.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.apache.hadoop.metrics2.lib.MutableRate;
3232

3333
import java.util.concurrent.ThreadLocalRandom;
34+
import java.util.regex.Matcher;
35+
import java.util.regex.Pattern;
3436

3537
/**
3638
* This class is for maintaining Datanode Volume IO related statistics and
@@ -43,6 +45,13 @@
4345
public class DataNodeVolumeMetrics {
4446
private final MetricsRegistry registry = new MetricsRegistry("FsVolume");
4547

48+
@Metric(value = {"VolumeName", "Current VolumeName"}, type = Metric.Type.TAG)
49+
public String getVolumeName() {
50+
Pattern pattern = Pattern.compile("(?:DataNodeVolume-|UndefinedDataNodeVolume)(.*)");
51+
Matcher matcher = pattern.matcher(name);
52+
return matcher.find() ? matcher.group(1) : name;
53+
}
54+
4655
@Metric("number of metadata operations")
4756
private MutableCounterLong totalMetadataOperations;
4857
@Metric("metadata operation rate")

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/balancer/TestBalancerService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,19 @@ public void testBalancerServiceMetrics() throws Exception {
242242
}
243243
}, 100, 10000);
244244

245+
GenericTestUtils.waitFor(() -> {
246+
final String balancerMetricsName =
247+
"Balancer-" + cluster.getNameNode(0).getNamesystem().getBlockPoolId();
248+
String blockPoolId = cluster.getNameNode(0).getNamesystem().getBlockPoolId();
249+
MetricsRecordBuilder metrics = MetricsAsserts.getMetrics(balancerMetricsName);
250+
try {
251+
MetricsAsserts.assertTag("BlockPoolID", blockPoolId, metrics);
252+
return true;
253+
} catch (Exception e) {
254+
return false;
255+
}
256+
}, 100, 10000);
257+
245258
TestBalancer.waitForBalancer(totalUsedSpace, totalCapacity, client, cluster,
246259
BalancerParameters.DEFAULT);
247260

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeVolumeMetrics.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import org.apache.hadoop.hdfs.server.datanode.fsdataset.DataNodeVolumeMetrics;
4545
import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi;
4646
import org.apache.hadoop.metrics2.MetricsRecordBuilder;
47+
import org.apache.hadoop.test.MetricsAsserts;
48+
4749
import org.junit.Rule;
4850
import org.junit.Test;
4951
import org.junit.rules.Timeout;
@@ -187,6 +189,8 @@ private void verifyDataNodeVolumeMetrics(final FileSystem fs,
187189
+ metrics.getFileIoErrorSampleCount());
188190
LOG.info("fileIoErrorMean : " + metrics.getFileIoErrorMean());
189191
LOG.info("fileIoErrorStdDev : " + metrics.getFileIoErrorStdDev());
192+
193+
MetricsAsserts.assertTag("VolumeName", metrics.getVolumeName(), rb);
190194
}
191195

192196
@Test

0 commit comments

Comments
 (0)