From 2bcfb19e83b61b68859bf6b15a3cc681d32d8511 Mon Sep 17 00:00:00 2001 From: Tyler Benson Date: Mon, 20 May 2019 09:22:47 -0700 Subject: [PATCH] Improve config name Also fix Instance.toString() --- src/main/java/org/datadog/jmxfetch/App.java | 6 +++--- src/main/java/org/datadog/jmxfetch/AppConfig.java | 10 +++------- src/main/java/org/datadog/jmxfetch/Instance.java | 4 +++- src/test/java/org/datadog/jmxfetch/TestApp.java | 2 +- .../java/org/datadog/jmxfetch/TestServiceChecks.java | 4 ++-- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/datadog/jmxfetch/App.java b/src/main/java/org/datadog/jmxfetch/App.java index e4a0f35d7..20ed234d6 100644 --- a/src/main/java/org/datadog/jmxfetch/App.java +++ b/src/main/java/org/datadog/jmxfetch/App.java @@ -829,10 +829,10 @@ public void init(boolean forceNewConnection) { } for (LinkedHashMap configInstance : configInstances) { - if (appConfig.isAllowDirectInstances() != isDirectInstance(configInstance)) { - log.debug("Skipping instance '{}'. allowDirectInstances={} jvm_direct={}", + if (appConfig.isTargetDirectInstances() != isDirectInstance(configInstance)) { + log.debug("Skipping instance '{}'. targetDirectInstances={} jvm_direct={}", name, - appConfig.isAllowDirectInstances(), + appConfig.isTargetDirectInstances(), isDirectInstance(configInstance)); continue; } diff --git a/src/main/java/org/datadog/jmxfetch/AppConfig.java b/src/main/java/org/datadog/jmxfetch/AppConfig.java index f69f3e6b8..9185fc547 100644 --- a/src/main/java/org/datadog/jmxfetch/AppConfig.java +++ b/src/main/java/org/datadog/jmxfetch/AppConfig.java @@ -1,8 +1,5 @@ package org.datadog.jmxfetch; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; @@ -12,7 +9,6 @@ import org.datadog.jmxfetch.converter.ReporterConverter; import org.datadog.jmxfetch.reporter.ConsoleReporter; import org.datadog.jmxfetch.reporter.Reporter; -import org.datadog.jmxfetch.reporter.ReporterFactory; import org.datadog.jmxfetch.validator.Log4JLevelValidator; import org.datadog.jmxfetch.validator.PositiveIntegerValidator; import org.datadog.jmxfetch.validator.ReporterValidator; @@ -209,7 +205,7 @@ public class AppConfig { * If set to true, other instances will be ignored. */ @Builder.Default - private boolean allowDirectInstances = false; + private boolean targetDirectInstances = false; // This is used by things like APM agent to provide configuration from resources private List instanceConfigResources; @@ -346,8 +342,8 @@ public String getJmxLaunchFile() { return getTmpDirectory() + "/" + AD_LAUNCH_FILE; } - public boolean isAllowDirectInstances() { - return allowDirectInstances; + public boolean isTargetDirectInstances() { + return targetDirectInstances; } public List getInstanceConfigResources() { diff --git a/src/main/java/org/datadog/jmxfetch/Instance.java b/src/main/java/org/datadog/jmxfetch/Instance.java index 679897641..592704df0 100644 --- a/src/main/java/org/datadog/jmxfetch/Instance.java +++ b/src/main/java/org/datadog/jmxfetch/Instance.java @@ -374,7 +374,9 @@ public void init(boolean forceNewConnection) /** Returns a string representation for the instance. */ @Override public String toString() { - if (this.instanceMap.get(PROCESS_NAME_REGEX) != null) { + if (isDirectInstance(instanceMap)) { + return "jvm_direct"; + } else if (this.instanceMap.get(PROCESS_NAME_REGEX) != null) { return "process_regex: `" + this.instanceMap.get(PROCESS_NAME_REGEX) + "`"; } else if (this.instanceMap.get("jmx_url") != null) { return (String) this.instanceMap.get("jmx_url"); diff --git a/src/test/java/org/datadog/jmxfetch/TestApp.java b/src/test/java/org/datadog/jmxfetch/TestApp.java index 438b94f7e..44c7449fb 100644 --- a/src/test/java/org/datadog/jmxfetch/TestApp.java +++ b/src/test/java/org/datadog/jmxfetch/TestApp.java @@ -491,7 +491,7 @@ public void testApp() throws Exception { registerMBean(testApp, "org.datadog.jmxfetch.test:type=SimpleTestJavaApp"); // We do a first collection - when(appConfig.isAllowDirectInstances()).thenReturn(true); + when(appConfig.isTargetDirectInstances()).thenReturn(true); initApplication("jmx.yaml"); run(); diff --git a/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java b/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java index 4838c022d..b33f8e375 100644 --- a/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java +++ b/src/test/java/org/datadog/jmxfetch/TestServiceChecks.java @@ -20,7 +20,7 @@ public void testServiceCheckOK() throws Exception { registerMBean(new SimpleTestJavaApp(), "org.datadog.jmxfetch.test:type=ServiceCheckTest"); // We do a first collection - when(appConfig.isAllowDirectInstances()).thenReturn(true); + when(appConfig.isTargetDirectInstances()).thenReturn(true); initApplication("jmx.yaml"); run(); @@ -155,7 +155,7 @@ public void testServiceCheckCRITICAL() throws Exception { @Test public void testServiceCheckCounter() throws Exception { - when(appConfig.isAllowDirectInstances()).thenReturn(true); + when(appConfig.isTargetDirectInstances()).thenReturn(true); initApplication("jmx.yaml"); Reporter repo = getReporter();