From a7ee7fec1c17d2b840c22d162be32a41108c181a Mon Sep 17 00:00:00 2001 From: Carlos Roman Date: Thu, 30 May 2024 10:37:25 +0100 Subject: [PATCH] Telemetry is no longer initialized when telemetry disabled --- CHANGELOG.md | 2 ++ src/main/java/org/datadog/jmxfetch/App.java | 15 ++++++--------- src/main/java/org/datadog/jmxfetch/AppConfig.java | 3 ++- .../java/org/datadog/jmxfetch/TestCommon.java | 6 +++++- 4 files changed, 15 insertions(+), 11 deletions(-) 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/TestCommon.java b/src/test/java/org/datadog/jmxfetch/TestCommon.java index ff0bf445..291341fd 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,10 @@ protected void initApplication(String yamlFileName, String autoDiscoveryPipeFile params.add(5, "/foo"); // could be anything we're stubbing it out params.add(6, "--sd_enabled"); } + + // Enable JMXFetch telemetry so tests that need it don't fail + params.add("--jmxfetch_telemetry"); + new JCommander(appConfig, params.toArray(new String[params.size()])); if (sdEnabled) {