Configure jmxfetch host and port separately
MODIFY
dd-java-agent/agent-jmxfetch/src/main/java/datadog/trace/agent/jmxfetch/JMXFetch.java
dd-java-agent/agent-jmxfetch/src/main/java/datadog/trace/agent/jmxfetch/JMXFetch.java
@@ -10,7 +10,6 @@ import org.datadog.jmxfetch.AppConfig;
@Slf4j
public class JMXFetch {
- public static final int DEFAULT_STATSD_PORT = 8125;
public static final ImmutableList<String> DEFAULT_CONFIGS =
ImmutableList.of("jmxfetch-config.yaml");
@@ -76,11 +75,17 @@ public class JMXFetch {
}
private static String getReporter() {
- String reporter = Config.get().getJmxFetchReporter();
- if (reporter == null) {
- reporter = "statsd:" + Config.get().getAgentHost() + ":" + DEFAULT_STATSD_PORT;
+ final Config config = Config.get();
+ if (Config.LOGGING_WRITER_TYPE.equals(config.getWriterType())) {
+ // If logging writer is enabled then also enable console reporter in JMXFetch
+ return "console";
}
- return reporter;
+
+ final String host =
+ config.getJmxFetchStatsdHost() == null
+ ? config.getAgentHost()
+ : config.getJmxFetchStatsdHost();
+ return "statsd:" + host + ":" + config.getJmxFetchStatsdPort();
}
private static String getLogLocation() {

MODIFY
dd-trace-api/src/main/java/datadog/trace/api/Config.java
dd-trace-api/src/main/java/datadog/trace/api/Config.java
@@ -40,7 +40,8 @@ public class Config {
public static final String JMX_FETCH_METRICS_CONFIGS = "jmxfetch.metrics-configs";
public static final String JMX_FETCH_CHECK_PERIOD = "jmxfetch.check-period";
public static final String JMX_FETCH_REFRESH_BEANS_PERIOD = "jmxfetch.refresh-beans-period";
- public static final String JMX_FETCH_REPORTER = "jmxfetch.reporter";
+ public static final String JMX_FETCH_STATSD_HOST = "jmxfetch.statsd.host";
+ public static final String JMX_FETCH_STATSD_PORT = "jmxfetch.statsd.port";
public static final String DEFAULT_SERVICE_NAME = "unnamed-java-app";
@@ -55,6 +56,8 @@ public class Config {
private static final boolean DEFAULT_TRACE_RESOLVER_ENABLED = true;
private static final boolean DEFAULT_JMX_FETCH_ENABLED = false;
+ public static final int DEFAULT_JMX_FETCH_STATSD_PORT = 8125;
+
@Getter private final String serviceName;
@Getter private final String writerType;
@Getter private final String agentHost;
@@ -68,7 +71,8 @@ public class Config {
@Getter private final List<String> jmxFetchMetricsConfigs;
@Getter private final Integer jmxFetchCheckPeriod;
@Getter private final Integer jmxFetchRefreshBeansPeriod;
- @Getter private final String jmxFetchReporter;
+ @Getter private final String jmxFetchStatsdHost;
+ @Getter private final Integer jmxFetchStatsdPort;
// Read order: System Properties -> Env Variables, [-> default value]
// Visible for testing
@@ -90,7 +94,9 @@ public class Config {
jmxFetchCheckPeriod = getIntegerSettingFromEnvironment(JMX_FETCH_CHECK_PERIOD, null);
jmxFetchRefreshBeansPeriod =
getIntegerSettingFromEnvironment(JMX_FETCH_REFRESH_BEANS_PERIOD, null);
- jmxFetchReporter = getSettingFromEnvironment(JMX_FETCH_REPORTER, null);
+ jmxFetchStatsdHost = getSettingFromEnvironment(JMX_FETCH_STATSD_HOST, null);
+ jmxFetchStatsdPort =
+ getIntegerSettingFromEnvironment(JMX_FETCH_STATSD_PORT, DEFAULT_JMX_FETCH_STATSD_PORT);
}
// Read order: Properties -> Parent
@@ -115,7 +121,9 @@ public class Config {
jmxFetchRefreshBeansPeriod =
getPropertyIntegerValue(
properties, JMX_FETCH_REFRESH_BEANS_PERIOD, parent.jmxFetchRefreshBeansPeriod);
- jmxFetchReporter = properties.getProperty(JMX_FETCH_REPORTER, parent.jmxFetchReporter);
+ jmxFetchStatsdHost = properties.getProperty(JMX_FETCH_STATSD_HOST, parent.jmxFetchStatsdHost);
+ jmxFetchStatsdPort =
+ getPropertyIntegerValue(properties, JMX_FETCH_STATSD_PORT, parent.jmxFetchStatsdPort);
}
private static String getSettingFromEnvironment(final String name, final String defaultValue) {

MODIFY
dd-trace-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy
dd-trace-api/src/test/groovy/datadog/trace/api/ConfigTest.groovy
@@ -13,11 +13,13 @@ import static Config.SERVICE_MAPPING
import static Config.SERVICE_NAME
import static Config.SPAN_TAGS
import static Config.WRITER_TYPE
+import static datadog.trace.api.Config.DEFAULT_JMX_FETCH_STATSD_PORT
import static datadog.trace.api.Config.JMX_FETCH_CHECK_PERIOD
import static datadog.trace.api.Config.JMX_FETCH_ENABLED
import static datadog.trace.api.Config.JMX_FETCH_METRICS_CONFIGS
import static datadog.trace.api.Config.JMX_FETCH_REFRESH_BEANS_PERIOD
-import static datadog.trace.api.Config.JMX_FETCH_REPORTER
+import static datadog.trace.api.Config.JMX_FETCH_STATSD_HOST
+import static datadog.trace.api.Config.JMX_FETCH_STATSD_PORT
import static datadog.trace.api.Config.PRIORITY_SAMPLING
import static datadog.trace.api.Config.TRACE_RESOLVER_ENABLED
@@ -51,7 +53,8 @@ class ConfigTest extends Specification {
config.jmxFetchMetricsConfigs == []
config.jmxFetchCheckPeriod == null
config.jmxFetchRefreshBeansPeriod == null
- config.jmxFetchReporter == null
+ config.jmxFetchStatsdHost == null
+ config.jmxFetchStatsdPort == DEFAULT_JMX_FETCH_STATSD_PORT
config.toString().contains("unnamed-java-app")
}
@@ -70,7 +73,8 @@ class ConfigTest extends Specification {
System.setProperty(PREFIX + JMX_FETCH_METRICS_CONFIGS, "/foo.yaml,/bar.yaml")
System.setProperty(PREFIX + JMX_FETCH_CHECK_PERIOD, "100")
System.setProperty(PREFIX + JMX_FETCH_REFRESH_BEANS_PERIOD, "200")
- System.setProperty(PREFIX + JMX_FETCH_REPORTER, "reporter")
+ System.setProperty(PREFIX + JMX_FETCH_STATSD_HOST, "statsd host")
+ System.setProperty(PREFIX + JMX_FETCH_STATSD_PORT, "321")
when:
def config = new Config()
@@ -89,7 +93,8 @@ class ConfigTest extends Specification {
config.jmxFetchMetricsConfigs == ["/foo.yaml", "/bar.yaml"]
config.jmxFetchCheckPeriod == 100
config.jmxFetchRefreshBeansPeriod == 200
- config.jmxFetchReporter == "reporter"
+ config.jmxFetchStatsdHost == "statsd host"
+ config.jmxFetchStatsdPort == 321
}
def "specify overrides via env vars"() {
@@ -140,7 +145,8 @@ class ConfigTest extends Specification {
properties.setProperty(JMX_FETCH_METRICS_CONFIGS, "/foo.yaml,/bar.yaml")
properties.setProperty(JMX_FETCH_CHECK_PERIOD, "100")
properties.setProperty(JMX_FETCH_REFRESH_BEANS_PERIOD, "200")
- properties.setProperty(JMX_FETCH_REPORTER, "reporter")
+ properties.setProperty(JMX_FETCH_STATSD_HOST, "statsd host")
+ properties.setProperty(JMX_FETCH_STATSD_PORT, "321")
when:
def config = Config.get(properties)
@@ -158,7 +164,8 @@ class ConfigTest extends Specification {
config.jmxFetchMetricsConfigs == ["/foo.yaml", "/bar.yaml"]
config.jmxFetchCheckPeriod == 100
config.jmxFetchRefreshBeansPeriod == 200
- config.jmxFetchReporter == "reporter"
+ config.jmxFetchStatsdHost == "statsd host"
+ config.jmxFetchStatsdPort == 321
}
def "override null properties"() {

Configure jmxfetch host and port separately