Skip to content

Commit 84f3331

Browse files
committed
add journalNode Id for metrics.
1 parent 1f8f53f commit 84f3331

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,29 @@ public static void assertQuantileGauges(String prefix,
401401
geq(0l));
402402
}
403403
}
404+
405+
/**
406+
* Assert a tag of metric as expected.
407+
* @param name of the metric tag
408+
* @param expected value of the metric tag
409+
* @param rb the record builder mock used to getMetrics
410+
*/
411+
public static void assertTag(String name, String expected,
412+
MetricsRecordBuilder rb) {
413+
Assert.assertEquals("Bad Tag for metric " + name,
414+
expected, getStringTag(name, rb));
415+
}
416+
417+
/**
418+
* get the value tag for the metric.
419+
* @param name of the metric tag
420+
* @param rb value of the metric tag
421+
* @return the value tag for the metric
422+
*/
423+
public static String getStringTag(String name, MetricsRecordBuilder rb) {
424+
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
425+
verify(rb).tag(eqName(info(name, "")), captor.capture());
426+
checkCaptured(captor, name);
427+
return captor.getValue();
428+
}
404429
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/JournalMetrics.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121

2222
import org.apache.hadoop.metrics2.annotation.Metric;
23+
import org.apache.hadoop.metrics2.annotation.Metric.Type;
2324
import org.apache.hadoop.metrics2.annotation.Metrics;
2425
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
2526
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
@@ -99,6 +100,11 @@ String getName() {
99100
return "Journal-" + journal.getJournalId();
100101
}
101102

103+
@Metric(value={"JournalId", "Current JournalId"}, type= Type.TAG)
104+
public String getJournalId() {
105+
return journal.getJournalId();
106+
}
107+
102108
@Metric("Current writer's epoch")
103109
public long getLastWriterEpoch() {
104110
try {

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/server/TestJournalNode.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public void setup() throws Exception {
9797
conf.set(DFSConfigKeys.DFS_JOURNALNODE_EDITS_DIR_KEY,
9898
editsDir.getAbsolutePath());
9999
} else if (testName.getMethodName().equals(
100-
"testJournalDefaultDirForOneNameSpace")) {
100+
"testJournalDefaultDirForOneNameSpace") ||
101+
testName.getMethodName().equals("testJournalMetricTags")) {
101102
FileUtil.fullyDelete(new File(DFSConfigKeys
102103
.DFS_JOURNALNODE_EDITS_DIR_DEFAULT));
103104
setFederationConf();
@@ -151,7 +152,8 @@ public void setup() throws Exception {
151152
testName.getMethodName().equals(
152153
"testJournalCommonDirAcrossNameSpace") ||
153154
testName.getMethodName().equals(
154-
"testJournalDefaultDirForOneNameSpace")) {
155+
"testJournalDefaultDirForOneNameSpace") ||
156+
testName.getMethodName().equals("testJournalMetricTags")) {
155157
Collection<String> nameServiceIds = DFSUtilClient.getNameServiceIds(conf);
156158
for(String nsId: nameServiceIds) {
157159
journalId = "test-journalid-" + nsId;
@@ -240,6 +242,23 @@ public void testJournalDefaultDirForOneNameSpace() {
240242
File.separator + jid);
241243
assertEquals(editsDir.toString(), journalStorage.getRoot().toString());
242244
}
245+
246+
@Test(timeout=100000)
247+
public void testJournalMetricTags() {
248+
setupStaticHostResolution(2, "journalnode");
249+
String jid = "test-journalid-ns1";
250+
Journal nsJournal = jn.getJournal(jid);
251+
MetricsRecordBuilder metrics = MetricsAsserts.getMetrics(
252+
nsJournal.getMetrics().getName());
253+
MetricsAsserts.assertTag("JournalId", jid, metrics);
254+
255+
jid = "test-journalid-ns2";
256+
nsJournal = jn.getJournal(jid);
257+
metrics = MetricsAsserts.getMetrics(
258+
nsJournal.getMetrics().getName());
259+
MetricsAsserts.assertTag("JournalId", jid, metrics);
260+
}
261+
243262
@Test(timeout=100000)
244263
public void testJournal() throws Exception {
245264
MetricsRecordBuilder metrics = MetricsAsserts.getMetrics(
@@ -281,7 +300,6 @@ public void testJournal() throws Exception {
281300

282301
}
283302

284-
285303
@Test(timeout=100000)
286304
public void testReturnsSegmentInfoAtEpochTransition() throws Exception {
287305
ch.newEpoch(1).get();

0 commit comments

Comments
 (0)