diff --git a/CHANGELOG.md b/CHANGELOG.md index abfe0559..a9eba045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Changelog ========= # 0.49.2-SNAPSHOT / TBC +* [BUGFIX] Telemetry is no longer initialized when telemetry is disabled [#522][] # 0.49.1 / 2024-04-09 * [FEATURE] Add ZGC Major and Minor Cycles and ZGC Major and Minor Pauses beans support out of the box (Generational ZGC support) [#509][] @@ -767,6 +768,7 @@ Changelog [#477]: https://github.com/DataDog/jmxfetch/issues/477 [#509]: https://github.com/DataDog/jmxfetch/issues/509 [#512]: https://github.com/DataDog/jmxfetch/pull/512 +[#522]: https://github.com/DataDog/jmxfetch/pull/522 [@alz]: https://github.com/alz [@aoking]: https://github.com/aoking [@arrawatia]: https://github.com/arrawatia diff --git a/src/main/java/org/datadog/jmxfetch/App.java b/src/main/java/org/datadog/jmxfetch/App.java index 8c78e8ac..6ae7934a 100644 --- a/src/main/java/org/datadog/jmxfetch/App.java +++ b/src/main/java/org/datadog/jmxfetch/App.java @@ -133,14 +133,14 @@ public App(final AppConfig appConfig) { } this.configs = getConfigs(this.appConfig); - this.initTelemetryBean(); + if (this.appConfig.getJmxfetchTelemetry()) { + this.initTelemetryBean(); + } } private ObjectName getAppTelemetryBeanName() { - ObjectName appTelemetryBeanName; - try { - appTelemetryBeanName = new ObjectName( + return new ObjectName( appConfig.getJmxfetchTelemetryDomain() + ":name=jmxfetch_app"); } catch (MalformedObjectNameException e) { log.warn( @@ -149,8 +149,6 @@ private ObjectName getAppTelemetryBeanName() { appConfig.getJmxfetchTelemetryDomain()); return null; } - - return appTelemetryBeanName; } private void initTelemetryBean() { @@ -163,16 +161,15 @@ private void initTelemetryBean() { try { mbs.registerMBean(bean, appTelemetryBeanName); - log.debug("Succesfully registered app telemetry bean"); + log.debug("Successfully registered app telemetry bean"); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) { log.warn("Could not register bean named '{}' for instance: ", - appTelemetryBeanName.toString(), e); + appTelemetryBeanName, e); } this.appTelemetry = bean; - return; } private void teardownTelemetry() { diff --git a/src/main/java/org/datadog/jmxfetch/AppConfig.java b/src/main/java/org/datadog/jmxfetch/AppConfig.java index a01ff561..042d2647 100644 --- a/src/main/java/org/datadog/jmxfetch/AppConfig.java +++ b/src/main/java/org/datadog/jmxfetch/AppConfig.java @@ -128,7 +128,8 @@ public class AppConfig { @Parameter( names = {"--jmxfetch_telemetry", "-jt"}, description = "Enable additional jmxfetch telemetry reporting", - required = false) + required = false) /* Do not default to true as this affects embedded mode where + customers can have custom MBean managers */ private boolean jmxfetchTelemetry; @Parameter( diff --git a/src/test/java/org/datadog/jmxfetch/TestApp.java b/src/test/java/org/datadog/jmxfetch/TestApp.java index 5fec8d25..a46b0c26 100644 --- a/src/test/java/org/datadog/jmxfetch/TestApp.java +++ b/src/test/java/org/datadog/jmxfetch/TestApp.java @@ -22,6 +22,9 @@ public class TestApp extends TestCommon { /** Tag metrics with MBean parameters based on user supplied regex */ @Test public void testBeanRegexTags() throws Exception { + // When we enable JMXFetch telemetry + when(appConfig.getJmxfetchTelemetry()).thenReturn(true); + // We expose a few metrics through JMX registerMBean( new SimpleTestJavaApp(), @@ -53,6 +56,9 @@ public void testBeanRegexTags() throws Exception { /** Tag metrics with MBeans parameters. */ @Test public void testBeanTags() throws Exception { + // When we enable JMXFetch telemetry + when(appConfig.getJmxfetchTelemetry()).thenReturn(true); + // We expose a few metrics through JMX registerMBean( new SimpleTestJavaApp(), diff --git a/src/test/java/org/datadog/jmxfetch/TestCommon.java b/src/test/java/org/datadog/jmxfetch/TestCommon.java index ff0bf445..42a5080d 100644 --- a/src/test/java/org/datadog/jmxfetch/TestCommon.java +++ b/src/test/java/org/datadog/jmxfetch/TestCommon.java @@ -73,7 +73,7 @@ public static void init() throws Exception { if (level == null) { level = "ALL"; } - CustomLogger.setup(LogLevel.ALL, "/tmp/jmxfetch_test.log", false); + CustomLogger.setup(LogLevel.fromString(level), "/tmp/jmxfetch_test.log", false); } /** @@ -152,6 +152,7 @@ protected void initApplication(String yamlFileName, String autoDiscoveryPipeFile params.add(5, "/foo"); // could be anything we're stubbing it out params.add(6, "--sd_enabled"); } + new JCommander(appConfig, params.toArray(new String[params.size()])); if (sdEnabled) {