From 29c203585ee74a92dd0e3fa7fa486e0656cf01da Mon Sep 17 00:00:00 2001 From: cnauroth Date: Fri, 3 Oct 2014 21:01:28 -0700 Subject: [PATCH] HADOOP-11163. MetricsSystemImpl may miss a registered source. Contributed by Chuan Liu. (cherry picked from commit 69c9af91031f345d9511618877646b8756b17863) (cherry picked from commit a828ef15b0e2c63dac6854910bc9ae3b5f5ef755) --- .../hadoop-common/CHANGES.txt | 2 ++ .../metrics2/impl/MetricsSystemImpl.java | 2 +- .../metrics2/impl/TestMetricsSystemImpl.java | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 38f44e761ed..6d1326045a3 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -577,6 +577,8 @@ Release 2.6.0 - UNRELEASED HADOOP-11117 UGI HadoopLoginModule doesn't catch & wrap all kerberos-related exceptions (stevel) + HADOOP-11163 MetricsSystemImpl may miss a registered source. (cnauroth) + Release 2.5.1 - 2014-09-05 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java index 5e6c9aecafb..4507e357957 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsSystemImpl.java @@ -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 // metrics system restarts. - register(name, new AbstractCallback() { + register(finalName, new AbstractCallback() { @Override public void postStart() { registerSource(finalName, finalDesc, s); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java index 0122045d383..d59e80b5820 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestMetricsSystemImpl.java @@ -397,6 +397,24 @@ public class TestMetricsSystemImpl { 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 recs) { LOG.debug(recs); 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() { return "file:metrics2-test-plugin.jar"; }