Skip to content

Commit

Permalink
Adds env vars to enable subscription globally for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
scottopell committed Jul 5, 2023
1 parent d1bd7b8 commit 79ce047
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;

import javax.management.InstanceNotFoundException;
Expand Down Expand Up @@ -270,10 +271,18 @@ public Instance(
this.enableBeanSubscription = enableBeanSubscription != null && enableBeanSubscription;

// Global override for enabling bean subscription on all instances
String enableSubscriptionOverride = System.getenv("DD_JMXFETCH_ENABLE_BEAN_SUBSCRIPTION");
if (enableSubscriptionOverride != null && enableSubscriptionOverride.equalsIgnoreCase("true")) {
String enableSubscriptionOverride = System.getenv("DD_JMXFETCH_SUBSCRIPTION_ENABLED");
if (enableSubscriptionOverride != null
&& enableSubscriptionOverride.equalsIgnoreCase("true")) {
this.enableBeanSubscription = true;
}
String subscriptionCoinFlip = System.getenv("DD_JMXFETCH_SUBSCRIPTION_FLIPCOIN");
if (subscriptionCoinFlip != null && subscriptionCoinFlip.equalsIgnoreCase("true")) {
Random rd = new Random();
boolean enabled = rd.nextBoolean();
this.enableBeanSubscription = enabled;
}
log.info("JMXFetch Subscription mode enabled={}", this.enableBeanSubscription);
this.beanSubscriptionActive = false;
}

Expand Down Expand Up @@ -518,13 +527,16 @@ public synchronized List<Metric> getMetrics() throws IOException {
}

long duration = System.currentTimeMillis() - this.lastCollectionTime;
log.info("Collection of {} matching attributes finished in {}ms",
matchingAttributes.size(), duration);
log.info("Collection finished in {}ms. MatchingAttributes={} CollectedMetrics={}",
duration, matchingAttributes.size(), metrics.size());
return metrics;
}

/** Returns whather or not the given period has elapsed since reference time. */
public boolean isPeriodDue(long refTime, Integer refPeriod) {
if (this.beanSubscriptionActive) {
return false;
}
if ((System.currentTimeMillis() - refTime) / 1000 < refPeriod) {
return false;
} else {
Expand Down

0 comments on commit 79ce047

Please sign in to comment.