diff --git a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java index 7277356..64a9d89 100644 --- a/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java +++ b/src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java @@ -291,12 +291,12 @@ private void loadGlobalTags(Properties config) throws ConfigurationException { if (tagAndValue.length == 2) { String tag = tagAndValue[0].trim(); String value = tagAndValue[1].trim(); + if (value.equalsIgnoreCase(UUID_TEMPLATE_VARIABLE)) { + value = UUID.randomUUID().toString(); + } else if (value.equalsIgnoreCase(PID_TEMPLATE_VARIABLE)) { + value = getThisJVMProcessID() + ""; + } if (tag.length() > 0 && value.length() > 0) { - if (value.equalsIgnoreCase(UUID_TEMPLATE_VARIABLE)) { - value = UUID.randomUUID().toString(); - } else if (value.equalsIgnoreCase(PID_TEMPLATE_VARIABLE)) { - value = getThisJVMProcessID() + ""; - } loadedGlobalTags.put(tag, value); continue; } @@ -317,11 +317,11 @@ static int getThisJVMProcessID() throws ConfigurationException { jvm.setAccessible(true); sun.management.VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime); - java.lang.reflect.Method pid_method = + java.lang.reflect.Method pidMethod = mgmt.getClass().getDeclaredMethod("getProcessId"); - pid_method.setAccessible(true); + pidMethod.setAccessible(true); - return (Integer) pid_method.invoke(mgmt); + return (Integer) pidMethod.invoke(mgmt); } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new ConfigurationException("Error fetching " + PID_TEMPLATE_VARIABLE + " of JVM", e); } diff --git a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java index 5c92e6e..741ed21 100644 --- a/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java +++ b/src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java @@ -227,7 +227,7 @@ public void testGlobalUUIDTag() throws Exception { ConfigService configService = new ConfigService(p); Map globalTags = configService.getGlobalTags(); assertEquals(globalTags.size(), 1); - assertEquals(globalTags.get("jvmid").length(), 36); + assertEquals(36, globalTags.get("jvmid").length()); } @Test @@ -236,8 +236,8 @@ public void testGlobalProcessIDTag() throws Exception { p.setProperty("global_tags", "pid:${PID}"); ConfigService configService = new ConfigService(p); Map globalTags = configService.getGlobalTags(); - assertEquals(globalTags.size(), 1); - assertEquals(globalTags.get("pid"), getThisJVMProcessID() + ""); + assertEquals(1, globalTags.size()); + assertEquals(getThisJVMProcessID() + "", globalTags.get("pid")); } @Test