Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,29 @@ public static void assertQuantileGauges(String prefix,
geq(0l));
}
}

/**
* Assert a tag of metric as expected.
* @param name of the metric tag
* @param expected value of the metric tag
* @param rb the record builder mock used to getMetrics
*/
public static void assertTag(String name, String expected,
MetricsRecordBuilder rb) {
Assert.assertEquals("Bad Tag for metric " + name,
expected, getStringTag(name, rb));
}

/**
* get the value tag for the metric.
* @param name of the metric tag
* @param rb value of the metric tag
* @return the value tag for the metric
*/
public static String getStringTag(String name, MetricsRecordBuilder rb) {
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(rb).tag(eqName(info(name, "")), captor.capture());
checkCaptured(captor, name);
return captor.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;

import org.apache.hadoop.metrics2.annotation.Metric;
import org.apache.hadoop.metrics2.annotation.Metric.Type;
import org.apache.hadoop.metrics2.annotation.Metrics;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.metrics2.lib.MetricsRegistry;
Expand Down Expand Up @@ -99,6 +100,11 @@ String getName() {
return "Journal-" + journal.getJournalId();
}

@Metric(value={"JournalId", "Current JournalId"}, type=Type.TAG)
public String getJournalId() {
return journal.getJournalId();
}

@Metric("Current writer's epoch")
public long getLastWriterEpoch() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public void setup() throws Exception {
conf.set(DFSConfigKeys.DFS_JOURNALNODE_EDITS_DIR_KEY,
editsDir.getAbsolutePath());
} else if (testName.getMethodName().equals(
"testJournalDefaultDirForOneNameSpace")) {
"testJournalDefaultDirForOneNameSpace") ||
testName.getMethodName().equals("testJournalMetricTags")) {
FileUtil.fullyDelete(new File(DFSConfigKeys
.DFS_JOURNALNODE_EDITS_DIR_DEFAULT));
setFederationConf();
Expand Down Expand Up @@ -151,7 +152,8 @@ public void setup() throws Exception {
testName.getMethodName().equals(
"testJournalCommonDirAcrossNameSpace") ||
testName.getMethodName().equals(
"testJournalDefaultDirForOneNameSpace")) {
"testJournalDefaultDirForOneNameSpace") ||
testName.getMethodName().equals("testJournalMetricTags")) {
Collection<String> nameServiceIds = DFSUtilClient.getNameServiceIds(conf);
for(String nsId: nameServiceIds) {
journalId = "test-journalid-" + nsId;
Expand Down Expand Up @@ -240,6 +242,23 @@ public void testJournalDefaultDirForOneNameSpace() {
File.separator + jid);
assertEquals(editsDir.toString(), journalStorage.getRoot().toString());
}

@Test(timeout=100000)
public void testJournalMetricTags() {
setupStaticHostResolution(2, "journalnode");
String jid = "test-journalid-ns1";
Journal nsJournal = jn.getJournal(jid);
MetricsRecordBuilder metrics = MetricsAsserts.getMetrics(
nsJournal.getMetrics().getName());
MetricsAsserts.assertTag("JournalId", jid, metrics);

jid = "test-journalid-ns2";
nsJournal = jn.getJournal(jid);
metrics = MetricsAsserts.getMetrics(
nsJournal.getMetrics().getName());
MetricsAsserts.assertTag("JournalId", jid, metrics);
}

@Test(timeout=100000)
public void testJournal() throws Exception {
MetricsRecordBuilder metrics = MetricsAsserts.getMetrics(
Expand Down