HADOOP-11163. MetricsSystemImpl may miss a registered source. Contributed by Chuan Liu.

(cherry picked from commit 69c9af9103)
This commit is contained in:
cnauroth 2014-10-03 21:01:28 -07:00
parent b335df9a9b
commit a828ef15b0
3 changed files with 35 additions and 1 deletions

View File

@ -589,6 +589,8 @@ Release 2.6.0 - UNRELEASED
HADOOP-11117 UGI HadoopLoginModule doesn't catch & wrap all HADOOP-11117 UGI HadoopLoginModule doesn't catch & wrap all
kerberos-related exceptions (stevel) kerberos-related exceptions (stevel)
HADOOP-11163 MetricsSystemImpl may miss a registered source. (cnauroth)
Release 2.5.1 - 2014-09-05 Release 2.5.1 - 2014-09-05
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -234,7 +234,7 @@ public class MetricsSystemImpl extends MetricsSystem implements MetricsSource {
} }
// We want to re-register the source to pick up new config when the // We want to re-register the source to pick up new config when the
// metrics system restarts. // metrics system restarts.
register(name, new AbstractCallback() { register(finalName, new AbstractCallback() {
@Override public void postStart() { @Override public void postStart() {
registerSource(finalName, finalDesc, s); registerSource(finalName, finalDesc, s);
} }

View File

@ -397,6 +397,24 @@ public class TestMetricsSystemImpl {
ms.shutdown(); ms.shutdown();
} }
@Test public void testRegisterSourceWithoutName() {
MetricsSystem ms = new MetricsSystemImpl();
TestSource ts = new TestSource("ts");
TestSource2 ts2 = new TestSource2("ts2");
ms.register(ts);
ms.register(ts2);
ms.init("TestMetricsSystem");
// if metrics source is registered without name,
// the class name will be used as the name
MetricsSourceAdapter sa = ((MetricsSystemImpl) ms)
.getSourceAdapter("TestSource");
assertNotNull(sa);
MetricsSourceAdapter sa2 = ((MetricsSystemImpl) ms)
.getSourceAdapter("TestSource2");
assertNotNull(sa2);
ms.shutdown();
}
private void checkMetricsRecords(List<MetricsRecord> recs) { private void checkMetricsRecords(List<MetricsRecord> recs) {
LOG.debug(recs); LOG.debug(recs);
MetricsRecord r = recs.get(0); MetricsRecord r = recs.get(0);
@ -430,6 +448,20 @@ public class TestMetricsSystemImpl {
} }
} }
@Metrics(context="test")
private static class TestSource2 {
@Metric("C1 desc") MutableCounterLong c1;
@Metric("XXX desc") MutableCounterLong xxx;
@Metric("G1 desc") MutableGaugeLong g1;
@Metric("YYY desc") MutableGaugeLong yyy;
@Metric MutableRate s1;
final MetricsRegistry registry;
TestSource2(String recName) {
registry = new MetricsRegistry(recName);
}
}
private static String getPluginUrlsAsString() { private static String getPluginUrlsAsString() {
return "file:metrics2-test-plugin.jar"; return "file:metrics2-test-plugin.jar";
} }