Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ test_debugger_arm64:
- !reference [.test_job_arm64, script]

test_smoke:
extends: .test_job
extends: .test_job_with_test_agent

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the session token when checking agent failures

After moving smoke jobs onto the test-agent template, validation still runs .gitlab/check_test_agent_results.sh, whose /test/trace_check/summary and /test/trace_check/failures calls do not pass DD_TEST_AGENT_SESSION_TOKEN. In the shared-agent scenario this feature is meant to support, those endpoints report all sessions when no token is supplied, so an unrelated session's trace-check failure can still fail this job despite the writer tagging its trace requests.

Useful? React with 👍 / 👎.

# needs:parallel:matrix limits this job to a specific build_tests combination.
# Keep matrix vars exact and in build_tests declaration order:
# https://docs.gitlab.com/ci/yaml/#needsparallelmatrix
Expand All @@ -1135,7 +1135,7 @@ test_smoke:
matrix: *test_matrix_8

test_smoke_arm64:
extends: .test_job_arm64
extends: .test_job_arm64_with_test_agent
variables:
<<: *tier_l_variables
GRADLE_TARGET: "stageMainDist :smokeTest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
public class SharedCommunicationObjects {
private static final Logger log = LoggerFactory.getLogger(SharedCommunicationObjects.class);

private static final String X_DATADOG_TEST_SESSION_TOKEN = "X-Datadog-Test-Session-Token";

private final List<Runnable> pausedComponents = new ArrayList<>();
private volatile boolean paused;

Expand Down Expand Up @@ -90,9 +92,27 @@ public void createRemaining(Config config) {
agentHttpClient =
OkHttpUtils.buildHttpClient(
OkHttpUtils.isPlainHttp(agentUrl), unixDomainSocket, namedPipe, httpClientTimeout);
String testSessionToken = config.getTestAgentSessionToken();
if (testSessionToken != null) {
agentHttpClient = injectTestAgentSessionHeaderInterceptor(testSessionToken);
}
}
}

private OkHttpClient injectTestAgentSessionHeaderInterceptor(String testSessionToken) {
return agentHttpClient
.newBuilder()
.addInterceptor(
chain ->
chain.proceed(
chain
.request()
.newBuilder()
.header(X_DATADOG_TEST_SESSION_TOKEN, testSessionToken)
.build()))
.build();
}

/** Registers a callback to be called when remote communications resume. */
public void whenReady(Runnable callback) {
if (paused) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public final class TracerConfig {
public static final String PROXY_NO_PROXY = "proxy.no_proxy";
public static final String TRACE_AGENT_PATH = "trace.agent.path";
public static final String TRACE_AGENT_ARGS = "trace.agent.args";
public static final String TEST_AGENT_SESSION_TOKEN = "test.agent.session.token";
public static final String PRIORITY_SAMPLING = "priority.sampling";
public static final String PRIORITY_SAMPLING_FORCE = "priority.sampling.force";
@Deprecated public static final String TRACE_RESOLVER_ENABLED = "trace.resolver.enabled";
Expand Down
7 changes: 7 additions & 0 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@
import static datadog.trace.api.config.TracerConfig.SPAN_SAMPLING_RULES_FILE;
import static datadog.trace.api.config.TracerConfig.SPAN_TAGS;
import static datadog.trace.api.config.TracerConfig.SPLIT_BY_TAGS;
import static datadog.trace.api.config.TracerConfig.TEST_AGENT_SESSION_TOKEN;
import static datadog.trace.api.config.TracerConfig.TRACE_128_BIT_TRACEID_GENERATION_ENABLED;
import static datadog.trace.api.config.TracerConfig.TRACE_AGENT_ARGS;
import static datadog.trace.api.config.TracerConfig.TRACE_AGENT_PATH;
Expand Down Expand Up @@ -1365,6 +1366,7 @@ public static String getHostName() {
private final boolean azureFunctions;
private final boolean awsServerless;
private final String traceAgentPath;
private final String testAgentSessionToken;
private final List<String> traceAgentArgs;
private final String dogStatsDPath;
private final List<String> dogStatsDArgs;
Expand Down Expand Up @@ -3105,6 +3107,7 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())

azureAppServices = configProvider.getBoolean(AZURE_APP_SERVICES, false);
traceAgentPath = configProvider.getString(TRACE_AGENT_PATH);
testAgentSessionToken = configProvider.getString(TEST_AGENT_SESSION_TOKEN);
Comment thread
PerfectSlayer marked this conversation as resolved.
String traceAgentArgsString = configProvider.getString(TRACE_AGENT_ARGS);
if (traceAgentArgsString == null) {
traceAgentArgs = Collections.emptyList();
Expand Down Expand Up @@ -5028,6 +5031,10 @@ public String getTraceAgentPath() {
return traceAgentPath;
}

public String getTestAgentSessionToken() {
return testAgentSessionToken;
}

public List<String> getTraceAgentArgs() {
return traceAgentArgs;
}
Expand Down
8 changes: 8 additions & 0 deletions metadata/supported-configurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -4065,6 +4065,14 @@
"aliases": []
}
],
"DD_TEST_AGENT_SESSION_TOKEN": [
{
"version": "A",
"type": "string",
"default": null,
"aliases": []
}
],
"DD_TEST_FAILED_TEST_REPLAY_ENABLED": [
{
"version": "A",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public final class ConfigSetting {

private static final Set<String> CONFIG_FILTER_LIST =
new HashSet<>(
Arrays.asList("DD_API_KEY", "dd.api-key", "dd.profiling.api-key", "dd.profiling.apikey"));
Arrays.asList(
"DD_API_KEY",
"dd.api-key",
"dd.profiling.api-key",
"dd.profiling.apikey",
"test.agent.session.token",
"DD_TEST_AGENT_SESSION_TOKEN"));

public static ConfigSetting of(String key, Object value, ConfigOrigin origin) {
return new ConfigSetting(key, value, origin, ABSENT_SEQ_ID, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ void supportsEqualityCheck(
}

@TableTest({
"scenario | key | value | filteredValue",
"DD_API_KEY | DD_API_KEY | somevalue | <hidden> ",
"dd.api-key | dd.api-key | somevalue | <hidden> ",
"dd.profiling.api-key | dd.profiling.api-key | somevalue | <hidden> ",
"dd.profiling.apikey | dd.profiling.apikey | somevalue | <hidden> ",
"some.other.key | some.other.key | somevalue | somevalue "
"scenario | key | value | filteredValue",
"DD_API_KEY | DD_API_KEY | somevalue | <hidden> ",
"dd.api-key | dd.api-key | somevalue | <hidden> ",
"dd.profiling.api-key | dd.profiling.api-key | somevalue | <hidden> ",
"dd.profiling.apikey | dd.profiling.apikey | somevalue | <hidden> ",
"session token prop | test.agent.session.token | somevalue | <hidden> ",
"session token env | DD_TEST_AGENT_SESSION_TOKEN | somevalue | <hidden> ",
"some.other.key | some.other.key | somevalue | somevalue "
})
void filtersKeyValues(String key, String value, String filteredValue) {
assertEquals(filteredValue, ConfigSetting.of(key, value, ConfigOrigin.DEFAULT).stringValue());
Expand Down