Repository: hbase Updated Branches: refs/heads/0.98 7ca58503b -> 02badbdf9
HBASE-16471 Region Server metrics context will be wrong when machine hostname contain "master" word (Pankaj Kumar) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/02badbdf Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/02badbdf Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/02badbdf Branch: refs/heads/0.98 Commit: 02badbdf9d069f515d3198c799d5575539bd0459 Parents: 7ca5850 Author: Ashish Singhi <ashishsin...@apache.org> Authored: Wed Aug 24 19:07:47 2016 +0530 Committer: Ashish Singhi <ashishsin...@apache.org> Committed: Wed Aug 24 19:07:47 2016 +0530 ---------------------------------------------------------------------- .../ipc/MetricsHBaseServerSourceFactory.java | 4 +-- .../apache/hadoop/hbase/ipc/TestRpcMetrics.java | 26 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/02badbdf/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceFactory.java ---------------------------------------------------------------------- diff --git a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceFactory.java b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceFactory.java index 4ad9f33..66c477b 100644 --- a/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceFactory.java +++ b/hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/ipc/MetricsHBaseServerSourceFactory.java @@ -47,9 +47,9 @@ public abstract class MetricsHBaseServerSourceFactory { * @return The Camel Cased context name. */ protected static String createContextName(String serverName) { - if (serverName.contains("HMaster")) { + if (serverName.startsWith("HMaster")) { return "Master"; - } else if (serverName.contains("HRegion")) { + } else if (serverName.startsWith("HRegion")) { return "RegionServer"; } return "IPC"; http://git-wip-us.apache.org/repos/asf/hbase/blob/02badbdf/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcMetrics.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcMetrics.java index e81f47a..6f3f732 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestRpcMetrics.java @@ -136,5 +136,31 @@ public class TestRpcMetrics { HELPER.assertCounter("exceptions", 5, serverSource); } + @Test + public void testServerContextNameWithHostName() { + String[] masterServerNames = + { "HMaster/node-xyz/10.19.250.253:16020", "HMaster/node-HRegion-xyz/10.19.250.253:16020" }; + + String[] regionServerNames = { "HRegionserver/node-xyz/10.19.250.253:16020", + "HRegionserver/node-HMaster1-xyz/10.19.250.253:16020" }; + + MetricsHBaseServerSource masterSource = null; + for (String serverName : masterServerNames) { + masterSource = new MetricsHBaseServer(serverName, new MetricsHBaseServerWrapperStub()) + .getMetricsSource(); + assertEquals("master", masterSource.getMetricsContext()); + assertEquals("Master,sub=IPC", masterSource.getMetricsJmxContext()); + assertEquals("IPC", masterSource.getMetricsName()); + } + + MetricsHBaseServerSource rsSource = null; + for (String serverName : regionServerNames) { + rsSource = new MetricsHBaseServer(serverName, new MetricsHBaseServerWrapperStub()) + .getMetricsSource(); + assertEquals("regionserver", rsSource.getMetricsContext()); + assertEquals("RegionServer,sub=IPC", rsSource.getMetricsJmxContext()); + assertEquals("IPC", rsSource.getMetricsName()); + } + } }