Skip to content

Commit c0b33de

Browse files
committed
feat(agent): Avoid DJM to use Config on main thread
1 parent 84fde3e commit c0b33de

File tree

2 files changed

+87
-80
lines changed
  • dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap
  • internal-api/src/main/java/datadog/trace/api

2 files changed

+87
-80
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java

Lines changed: 87 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import static datadog.environment.JavaVirtualMachine.isOracleJDK8;
55
import static datadog.trace.api.ConfigDefaults.DEFAULT_STARTUP_LOGS_ENABLED;
66
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
7+
import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_COMMAND_PATTERN;
8+
import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_ENABLED;
79
import static datadog.trace.bootstrap.Library.WILDFLY;
810
import static datadog.trace.bootstrap.Library.detectLibraries;
11+
import static datadog.trace.bootstrap.config.provider.StableConfigSource.FLEET;
12+
import static datadog.trace.bootstrap.config.provider.StableConfigSource.LOCAL;
913
import static datadog.trace.util.AgentThreadFactory.AgentThread.JMX_STARTUP;
1014
import static datadog.trace.util.AgentThreadFactory.AgentThread.PROFILER_STARTUP;
1115
import static datadog.trace.util.AgentThreadFactory.AgentThread.TRACE_STARTUP;
@@ -212,74 +216,11 @@ public static void start(
212216
injectAgentArgsConfig(agentArgs);
213217
}
214218

215-
// Retro-compatibility for the old way to configure CI Visibility
216-
if ("true".equals(ddGetProperty("dd.integration.junit.enabled"))
217-
|| "true".equals(ddGetProperty("dd.integration.testng.enabled"))) {
218-
setSystemPropertyDefault(AgentFeature.CIVISIBILITY.getSystemProp(), "true");
219-
}
220-
221-
ciVisibilityEnabled = isFeatureEnabled(AgentFeature.CIVISIBILITY);
222-
if (ciVisibilityEnabled) {
223-
// if CI Visibility is enabled, all the other features are disabled by default
224-
// unless the user had explicitly enabled them.
225-
setSystemPropertyDefault(AgentFeature.JMXFETCH.getSystemProp(), "false");
226-
setSystemPropertyDefault(AgentFeature.PROFILING.getSystemProp(), "false");
227-
setSystemPropertyDefault(AgentFeature.APPSEC.getSystemProp(), "false");
228-
setSystemPropertyDefault(AgentFeature.IAST.getSystemProp(), "false");
229-
setSystemPropertyDefault(AgentFeature.REMOTE_CONFIG.getSystemProp(), "false");
230-
setSystemPropertyDefault(AgentFeature.CWS.getSystemProp(), "false");
231-
232-
/*if CI Visibility is enabled, the PrioritizationType should be {@code Prioritization.ENSURE_TRACE} */
233-
setSystemPropertyDefault(
234-
propertyNameToSystemPropertyName(TracerConfig.PRIORITIZATION_TYPE), "ENSURE_TRACE");
235-
236-
try {
237-
setSystemPropertyDefault(
238-
propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENT_JAR_URI),
239-
agentJarURL.toURI().toString());
240-
} catch (URISyntaxException e) {
241-
throw new IllegalArgumentException(
242-
"Could not create URI from agent JAR URL: " + agentJarURL, e);
243-
}
244-
}
245-
246-
// Enable automatic fetching of git tags from datadog_git.properties only if CI Visibility is
247-
// not enabled
248-
if (!ciVisibilityEnabled) {
249-
GitInfoProvider.INSTANCE.registerGitInfoBuilder(new EmbeddedGitInfoBuilder());
250-
}
251-
252-
boolean dataJobsEnabled = isFeatureEnabled(AgentFeature.DATA_JOBS);
253-
if (dataJobsEnabled) {
254-
log.info("Data Jobs Monitoring enabled, enabling spark integrations");
255-
256-
setSystemPropertyDefault(
257-
propertyNameToSystemPropertyName(TracerConfig.TRACE_LONG_RUNNING_ENABLED), "true");
258-
setSystemPropertyDefault(
259-
propertyNameToSystemPropertyName("integration.spark.enabled"), "true");
260-
setSystemPropertyDefault(
261-
propertyNameToSystemPropertyName("integration.spark-executor.enabled"), "true");
262-
// needed for e2e pipeline
263-
setSystemPropertyDefault(propertyNameToSystemPropertyName("data.streams.enabled"), "true");
264-
setSystemPropertyDefault(
265-
propertyNameToSystemPropertyName("integration.aws-sdk.enabled"), "true");
266-
setSystemPropertyDefault(
267-
propertyNameToSystemPropertyName("integration.kafka.enabled"), "true");
219+
configureCiVisibility(agentJarURL);
268220

269-
if (Config.get().isDataJobsOpenLineageEnabled()) {
270-
setSystemPropertyDefault(
271-
propertyNameToSystemPropertyName("integration.spark-openlineage.enabled"), "true");
272-
}
273-
274-
String javaCommand = String.join(" ", JavaVirtualMachine.getCommandArguments());
275-
String dataJobsCommandPattern = Config.get().getDataJobsCommandPattern();
276-
if (!isDataJobsSupported(javaCommand, dataJobsCommandPattern)) {
277-
log.warn(
278-
"Data Jobs Monitoring is not compatible with non-spark command {} based on command pattern {}. dd-trace-java will not be installed",
279-
javaCommand,
280-
dataJobsCommandPattern);
281-
return;
282-
}
221+
// Halt agent start if DJM is enabled and is not successfully configure
222+
if (!configureDataJobsMonitoring()) {
223+
return;
283224
}
284225

285226
if (!isSupportedAppSecArch()) {
@@ -446,6 +387,42 @@ public static void start(
446387
StaticEventLogger.end("Agent.start");
447388
}
448389

390+
private static boolean configureDataJobsMonitoring() {
391+
boolean dataJobsEnabled = isFeatureEnabled(AgentFeature.DATA_JOBS);
392+
if (dataJobsEnabled) {
393+
log.info("Data Jobs Monitoring enabled, enabling spark integrations");
394+
395+
setSystemPropertyDefault(
396+
propertyNameToSystemPropertyName(TracerConfig.TRACE_LONG_RUNNING_ENABLED), "true");
397+
setSystemPropertyDefault(
398+
propertyNameToSystemPropertyName("integration.spark.enabled"), "true");
399+
setSystemPropertyDefault(
400+
propertyNameToSystemPropertyName("integration.spark-executor.enabled"), "true");
401+
// needed for e2e pipeline
402+
setSystemPropertyDefault(propertyNameToSystemPropertyName("data.streams.enabled"), "true");
403+
setSystemPropertyDefault(
404+
propertyNameToSystemPropertyName("integration.aws-sdk.enabled"), "true");
405+
setSystemPropertyDefault(
406+
propertyNameToSystemPropertyName("integration.kafka.enabled"), "true");
407+
408+
if ("true".equals(ddGetProperty(propertyNameToSystemPropertyName(DATA_JOBS_ENABLED)))) {
409+
setSystemPropertyDefault(
410+
propertyNameToSystemPropertyName("integration.spark-openlineage.enabled"), "true");
411+
}
412+
413+
String javaCommand = String.join(" ", JavaVirtualMachine.getCommandArguments());
414+
String dataJobsCommandPattern = ddGetProperty(propertyNameToSystemPropertyName(DATA_JOBS_COMMAND_PATTERN));
415+
if (!isDataJobsSupported(javaCommand, dataJobsCommandPattern)) {
416+
log.warn(
417+
"Data Jobs Monitoring is not compatible with non-spark command {} based on command pattern {}. dd-trace-java will not be installed",
418+
javaCommand,
419+
dataJobsCommandPattern);
420+
return false;
421+
}
422+
}
423+
return true;
424+
}
425+
449426
private static void injectAgentArgsConfig(String agentArgs) {
450427
try {
451428
final Class<?> agentArgsInjectorClass =
@@ -458,6 +435,45 @@ private static void injectAgentArgsConfig(String agentArgs) {
458435
}
459436
}
460437

438+
private static void configureCiVisibility(URL agentJarURL) {
439+
// Retro-compatibility for the old way to configure CI Visibility
440+
if ("true".equals(ddGetProperty("dd.integration.junit.enabled"))
441+
|| "true".equals(ddGetProperty("dd.integration.testng.enabled"))) {
442+
setSystemPropertyDefault(AgentFeature.CIVISIBILITY.getSystemProp(), "true");
443+
}
444+
445+
ciVisibilityEnabled = isFeatureEnabled(AgentFeature.CIVISIBILITY);
446+
if (ciVisibilityEnabled) {
447+
// if CI Visibility is enabled, all the other features are disabled by default
448+
// unless the user had explicitly enabled them.
449+
setSystemPropertyDefault(AgentFeature.JMXFETCH.getSystemProp(), "false");
450+
setSystemPropertyDefault(AgentFeature.PROFILING.getSystemProp(), "false");
451+
setSystemPropertyDefault(AgentFeature.APPSEC.getSystemProp(), "false");
452+
setSystemPropertyDefault(AgentFeature.IAST.getSystemProp(), "false");
453+
setSystemPropertyDefault(AgentFeature.REMOTE_CONFIG.getSystemProp(), "false");
454+
setSystemPropertyDefault(AgentFeature.CWS.getSystemProp(), "false");
455+
456+
/*if CI Visibility is enabled, the PrioritizationType should be {@code Prioritization.ENSURE_TRACE} */
457+
setSystemPropertyDefault(
458+
propertyNameToSystemPropertyName(TracerConfig.PRIORITIZATION_TYPE), "ENSURE_TRACE");
459+
460+
try {
461+
setSystemPropertyDefault(
462+
propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENT_JAR_URI),
463+
agentJarURL.toURI().toString());
464+
} catch (URISyntaxException e) {
465+
throw new IllegalArgumentException(
466+
"Could not create URI from agent JAR URL: " + agentJarURL, e);
467+
}
468+
}
469+
470+
// Enable automatic fetching of git tags from datadog_git.properties only if CI Visibility is
471+
// not enabled
472+
if (!ciVisibilityEnabled) {
473+
GitInfoProvider.INSTANCE.registerGitInfoBuilder(new EmbeddedGitInfoBuilder());
474+
}
475+
}
476+
461477
public static void shutdown(final boolean sync) {
462478
StaticEventLogger.end("Agent");
463479
StaticEventLogger.stop();
@@ -1401,13 +1417,13 @@ private static boolean isFeatureEnabled(AgentFeature feature) {
14011417
final String featureSystemProp = feature.getSystemProp();
14021418
String featureEnabled = SystemProperties.get(featureSystemProp);
14031419
if (featureEnabled == null) {
1404-
featureEnabled = getStableConfig(StableConfigSource.FLEET, featureConfigKey);
1420+
featureEnabled = getStableConfig(FLEET, featureConfigKey);
14051421
}
14061422
if (featureEnabled == null) {
14071423
featureEnabled = ddGetEnv(featureSystemProp);
14081424
}
14091425
if (featureEnabled == null) {
1410-
featureEnabled = getStableConfig(StableConfigSource.LOCAL, featureConfigKey);
1426+
featureEnabled = getStableConfig(LOCAL, featureConfigKey);
14111427
}
14121428

14131429
if (feature.isEnabledByDefault()) {
@@ -1431,13 +1447,13 @@ private static boolean isFullyDisabled(final AgentFeature feature) {
14311447
final String featureSystemProp = feature.getSystemProp();
14321448
String settingValue = getNullIfEmpty(SystemProperties.get(featureSystemProp));
14331449
if (settingValue == null) {
1434-
settingValue = getNullIfEmpty(getStableConfig(StableConfigSource.FLEET, featureConfigKey));
1450+
settingValue = getNullIfEmpty(getStableConfig(FLEET, featureConfigKey));
14351451
}
14361452
if (settingValue == null) {
14371453
settingValue = getNullIfEmpty(ddGetEnv(featureSystemProp));
14381454
}
14391455
if (settingValue == null) {
1440-
settingValue = getNullIfEmpty(getStableConfig(StableConfigSource.LOCAL, featureConfigKey));
1456+
settingValue = getNullIfEmpty(getStableConfig(LOCAL, featureConfigKey));
14411457
}
14421458

14431459
// defaults to inactive

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@
323323
import static datadog.trace.api.config.GeneralConfig.APPLICATION_KEY;
324324
import static datadog.trace.api.config.GeneralConfig.APPLICATION_KEY_FILE;
325325
import static datadog.trace.api.config.GeneralConfig.AZURE_APP_SERVICES;
326-
import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_COMMAND_PATTERN;
327326
import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_ENABLED;
328327
import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_OPENLINEAGE_ENABLED;
329328
import static datadog.trace.api.config.GeneralConfig.DATA_STREAMS_BUCKET_DURATION_SECONDS;
@@ -1142,7 +1141,6 @@ public static String getHostName() {
11421141
private final int cwsTlsRefresh;
11431142

11441143
private final boolean dataJobsEnabled;
1145-
private final String dataJobsCommandPattern;
11461144
private final boolean dataJobsOpenLineageEnabled;
11471145

11481146
private final boolean dataStreamsEnabled;
@@ -2532,7 +2530,6 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
25322530
dataJobsOpenLineageEnabled =
25332531
configProvider.getBoolean(
25342532
DATA_JOBS_OPENLINEAGE_ENABLED, DEFAULT_DATA_JOBS_OPENLINEAGE_ENABLED);
2535-
dataJobsCommandPattern = configProvider.getString(DATA_JOBS_COMMAND_PATTERN);
25362533

25372534
dataStreamsEnabled =
25382535
configProvider.getBoolean(DATA_STREAMS_ENABLED, DEFAULT_DATA_STREAMS_ENABLED);
@@ -4382,10 +4379,6 @@ public boolean isDataJobsOpenLineageEnabled() {
43824379
return dataJobsOpenLineageEnabled;
43834380
}
43844381

4385-
public String getDataJobsCommandPattern() {
4386-
return dataJobsCommandPattern;
4387-
}
4388-
43894382
public boolean isApmTracingEnabled() {
43904383
return apmTracingEnabled;
43914384
}
@@ -5684,8 +5677,6 @@ public String toString() {
56845677
+ appSecRaspEnabled
56855678
+ ", dataJobsEnabled="
56865679
+ dataJobsEnabled
5687-
+ ", dataJobsCommandPattern="
5688-
+ dataJobsCommandPattern
56895680
+ ", apmTracingEnabled="
56905681
+ apmTracingEnabled
56915682
+ ", jdkSocketEnabled="

0 commit comments

Comments
 (0)