Merge pull request #684 from DataDog/tyler/jboss-jmxfetch

Replace jboss classpath check with ENV check for jmxfetch delay
This commit is contained in:
Tyler Benson 2019-01-31 11:42:38 -08:00 committed by GitHub
commit b58ec1b4fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 15 deletions

View File

@ -46,7 +46,7 @@ public class TracingAgent {
throws Exception { throws Exception {
startDatadogAgent(agentArgs, inst); startDatadogAgent(agentArgs, inst);
if (isAppUsingCustomLogManager()) { if (isAppUsingCustomLogManager()) {
System.out.println("Custom logger found. Delaying JMXFetch initialization."); System.out.println("Custom logger detected. Delaying JMXFetch initialization.");
/* /*
* java.util.logging.LogManager maintains a final static LogManager, which is created during class initialization. * java.util.logging.LogManager maintains a final static LogManager, which is created during class initialization.
* *
@ -112,7 +112,6 @@ public class TracingAgent {
} }
public static synchronized void startJmxFetch() throws Exception { public static synchronized void startJmxFetch() throws Exception {
System.out.println("Starting JMXFetch.");
initializeJars(); initializeJars();
if (JMXFETCH_CLASSLOADER == null) { if (JMXFETCH_CLASSLOADER == null) {
final ClassLoader jmxFetchClassLoader = createDatadogClassLoader(bootstrapJar, jmxFetchJar); final ClassLoader jmxFetchClassLoader = createDatadogClassLoader(bootstrapJar, jmxFetchJar);
@ -245,25 +244,31 @@ public class TracingAgent {
*/ */
private static boolean isAppUsingCustomLogManager() { private static boolean isAppUsingCustomLogManager() {
final String tracerCustomLogManSysprop = "dd.app.customlogmanager"; final String tracerCustomLogManSysprop = "dd.app.customlogmanager";
final String customLogManagerProp = System.getProperty(tracerCustomLogManSysprop);
final String customLogManagerEnv =
System.getenv(tracerCustomLogManSysprop.replace('.', '_').toUpperCase());
if ("debug" if ("debug"
.equalsIgnoreCase(System.getProperty("datadog.slf4j.simpleLogger.defaultLogLevel"))) { .equalsIgnoreCase(System.getProperty("datadog.slf4j.simpleLogger.defaultLogLevel"))) {
System.out.println( System.out.println(
"Prop - logging.manager: " + System.getProperty("java.util.logging.manager")); "Prop - logging.manager: " + System.getProperty("java.util.logging.manager"));
System.out.println( System.out.println("Prop - customlogmanager: " + customLogManagerProp);
"Prop - customlogmanager: " + System.getProperty(tracerCustomLogManSysprop)); System.out.println("Env - customlogmanager: " + customLogManagerEnv);
System.out.println( System.out.println("ENV - jboss: " + System.getenv("JBOSS_HOME"));
"Env - customlogmanager: "
+ System.getenv(tracerCustomLogManSysprop.replace('.', '_').toUpperCase()));
System.out.println(
"Classpath - jboss: " + ClassLoader.getSystemResource("org/jboss/modules/Main.class")
!= null);
} }
return System.getProperty("java.util.logging.manager") != null return System.getProperty("java.util.logging.manager") != null
|| Boolean.parseBoolean(System.getProperty(tracerCustomLogManSysprop)) || Boolean.parseBoolean(customLogManagerProp)
|| Boolean.parseBoolean( || Boolean.parseBoolean(customLogManagerEnv)
System.getenv(tracerCustomLogManSysprop.replace('.', '_').toUpperCase())) // Allow setting to skip these automatic checks:
// Classes known to set a custom log mananger || ((customLogManagerProp == null && customLogManagerEnv == null)
|| ClassLoader.getSystemResource("org/jboss/modules/Main.class") != null; && (
// JBoss/Wildfly is known to set a custom log manager
// Originally we were checking for the presence of a jboss class,
// but it turns out other non-jboss applications have jboss classes on the classpath.
// This would cause jmxfetch initialization to be delayed indefinitely.
// Checking for an environment variable required by jboss instead.
System.getenv("JBOSS_HOME") != null));
} }
/** /**