Skip to content

Commit 78ad76f

Browse files
committed
feat(agent): Avoid DJM to use Config on main thread
1 parent d9c278f commit 78ad76f

File tree

2 files changed

+88
-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

+88
-80
lines changed

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

Lines changed: 88 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import static datadog.environment.JavaVirtualMachine.isJavaVersionAtLeast;
44
import static datadog.environment.JavaVirtualMachine.isOracleJDK8;
55
import static datadog.trace.api.ConfigDefaults.DEFAULT_STARTUP_LOGS_ENABLED;
6+
import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_COMMAND_PATTERN;
7+
import static datadog.trace.api.config.GeneralConfig.DATA_JOBS_ENABLED;
68
import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY;
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,43 @@ 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 =
415+
ddGetProperty(propertyNameToSystemPropertyName(DATA_JOBS_COMMAND_PATTERN));
416+
if (!isDataJobsSupported(javaCommand, dataJobsCommandPattern)) {
417+
log.warn(
418+
"Data Jobs Monitoring is not compatible with non-spark command {} based on command pattern {}. dd-trace-java will not be installed",
419+
javaCommand,
420+
dataJobsCommandPattern);
421+
return false;
422+
}
423+
}
424+
return true;
425+
}
426+
449427
private static void injectAgentArgsConfig(String agentArgs) {
450428
try {
451429
final Class<?> agentArgsInjectorClass =
@@ -458,6 +436,45 @@ private static void injectAgentArgsConfig(String agentArgs) {
458436
}
459437
}
460438

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

14131430
if (feature.isEnabledByDefault()) {
@@ -1431,13 +1448,13 @@ private static boolean isFullyDisabled(final AgentFeature feature) {
14311448
final String featureSystemProp = feature.getSystemProp();
14321449
String settingValue = getNullIfEmpty(SystemProperties.get(featureSystemProp));
14331450
if (settingValue == null) {
1434-
settingValue = getNullIfEmpty(getStableConfig(StableConfigSource.FLEET, featureConfigKey));
1451+
settingValue = getNullIfEmpty(getStableConfig(FLEET, featureConfigKey));
14351452
}
14361453
if (settingValue == null) {
14371454
settingValue = getNullIfEmpty(ddGetEnv(featureSystemProp));
14381455
}
14391456
if (settingValue == null) {
1440-
settingValue = getNullIfEmpty(getStableConfig(StableConfigSource.LOCAL, featureConfigKey));
1457+
settingValue = getNullIfEmpty(getStableConfig(LOCAL, featureConfigKey));
14411458
}
14421459

14431460
// 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)