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 b93caeb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/java/org/datadog/jmxfetch/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Random;

import javax.management.InstanceNotFoundException;
import javax.management.MBeanAttributeInfo;
Expand Down Expand Up @@ -270,10 +271,17 @@ 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");
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 +526,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 b93caeb

Please sign in to comment.