Skip to content

Commit

Permalink
Telemetry is no longer initialized when telemetry disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosroman committed May 30, 2024
1 parent 1969237 commit a7ee7fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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][]
Expand Down Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -149,8 +149,6 @@ private ObjectName getAppTelemetryBeanName() {
appConfig.getJmxfetchTelemetryDomain());
return null;
}

return appTelemetryBeanName;
}

private void initTelemetryBean() {
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/datadog/jmxfetch/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/org/datadog/jmxfetch/TestCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a7ee7fe

Please sign in to comment.