HBASE-16471 Region Server metrics context will be wrong when machine hostname contain "master" word (Pankaj Kumar)

This commit is contained in:
Ashish Singhi 2016-08-24 18:59:44 +05:30
parent 1ca849269d
commit 31f16d6aec
2 changed files with 31 additions and 2 deletions

View File

@ -47,9 +47,9 @@ public abstract class MetricsHBaseServerSourceFactory {
* @return The Camel Cased context name.
*/
protected static String createContextName(String serverName) {
if (serverName.contains("HMaster") || serverName.contains("master")) {
if (serverName.startsWith("HMaster") || serverName.startsWith("master")) {
return "Master";
} else if (serverName.contains("HRegion") || serverName.contains("regionserver")) {
} else if (serverName.startsWith("HRegion") || serverName.startsWith("regionserver")) {
return "RegionServer";
}
return "IPC";

View File

@ -138,5 +138,34 @@ public class TestRpcMetrics {
HELPER.assertCounter("exceptions", 5, serverSource);
}
@Test
public void testServerContextNameWithHostName() {
String[] masterServerNames = { "master/node-xyz/10.19.250.253:16020",
"master/node-regionserver-xyz/10.19.250.253:16020", "HMaster/node-xyz/10.19.250.253:16020",
"HMaster/node-regionserver-xyz/10.19.250.253:16020" };
String[] regionServerNames = { "regionserver/node-xyz/10.19.250.253:16020",
"regionserver/node-master1-xyz/10.19.250.253:16020",
"HRegionserver/node-xyz/10.19.250.253:16020",
"HRegionserver/node-master1-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("Master", 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("RegionServer", rsSource.getMetricsName());
}
}
}