Skip to content

Commit

Permalink
Merge branch '76-dev-branch'
Browse files Browse the repository at this point in the history
  • Loading branch information
Phaneendra Kumar Divi committed Dec 7, 2020
2 parents f977928 + d30c12c commit 0cb7b48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void testGlobalUUIDTag() throws Exception {
ConfigService configService = new ConfigService(p);
Map<String, String> globalTags = configService.getGlobalTags();
assertEquals(globalTags.size(), 1);
assertEquals(globalTags.get("jvmid").length(), 36);
assertEquals(36, globalTags.get("jvmid").length());
}

@Test
Expand All @@ -236,8 +236,8 @@ public void testGlobalProcessIDTag() throws Exception {
p.setProperty("global_tags", "pid:${PID}");
ConfigService configService = new ConfigService(p);
Map<String, String> globalTags = configService.getGlobalTags();
assertEquals(globalTags.size(), 1);
assertEquals(globalTags.get("pid"), getThisJVMProcessID() + "");
assertEquals(1, globalTags.size());
assertEquals(getThisJVMProcessID() + "", globalTags.get("pid"));
}

@Test
Expand Down

0 comments on commit 0cb7b48

Please sign in to comment.