Skip to content

Commit

Permalink
Will this break?
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosroman committed May 31, 2024
1 parent fc57775 commit 26d264d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/main/java/org/datadog/jmxfetch/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ public App(final AppConfig appConfig) {
}
this.configs = getConfigs(this.appConfig);

this.initTelemetryBean();
if (this.appConfig.getJmxfetchTelemetry()) {
log.info("Enabling JMX Fetch Telemetry");
this.initTelemetryBean();
}
}

private ObjectName getAppTelemetryBeanName() {
Expand Down Expand Up @@ -168,14 +171,19 @@ private void initTelemetryBean() {
| MBeanRegistrationException
| NotCompliantMBeanException e) {
log.warn("Could not register bean named '{}' for instance: ",
appTelemetryBeanName.toString(), e);
appTelemetryBeanName, e);
}

this.appTelemetry = bean;
return;
}

private void teardownTelemetry() {
if (!this.appConfig.getJmxfetchTelemetry()) {
log.debug("Skipping teardown telemetry as not enabled");
return;
}

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName appTelemetryBeanName = getAppTelemetryBeanName();
if (appTelemetryBeanName == null) {
Expand All @@ -187,7 +195,7 @@ private void teardownTelemetry() {
log.debug("Succesfully unregistered app telemetry bean");
} catch (MBeanRegistrationException | InstanceNotFoundException e) {
log.warn("Could not unregister bean named '{}' for instance: ",
appTelemetryBeanName.toString(), e);
appTelemetryBeanName, e);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ public Instance(
log.info("collect_default_jvm_metrics is false - not collecting default JVM metrics");
}

instanceTelemetryBean = createInstanceTelemetryBean();
if (this.appConfig.getJmxfetchTelemetry()) {
this.instanceTelemetryBean = createInstanceTelemetryBean();
}
}

private ObjectName getObjName(String domain,String instance)
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 26d264d

Please sign in to comment.