Skip to content

Commit 5ba0e37

Browse files
authored
Merge branch 'master' into smola/remove-old-api-sec-sampling-rc
2 parents 119d269 + 7787c9d commit 5ba0e37

File tree

124 files changed

+3044
-884
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3044
-884
lines changed

.circleci/config.continue.yml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ instrumentation_modules: &instrumentation_modules "dd-java-agent/instrumentation
3636
debugger_modules: &debugger_modules "dd-java-agent/agent-debugger|dd-java-agent/agent-bootstrap|dd-java-agent/agent-builder|internal-api|communication|dd-trace-core"
3737
profiling_modules: &profiling_modules "dd-java-agent/agent-profiling"
3838

39-
default_system_tests_commit: &default_system_tests_commit 6980534f333b3f7a35d83df2230f00f4e26642f5
39+
default_system_tests_commit: &default_system_tests_commit ffc1cfbe944dcf466606a84b4a442b990f675979
4040

4141
parameters:
4242
nightly:

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ private enum AgentFeature {
9696
CIVISIBILITY_AGENTLESS(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED, false),
9797
USM(UsmConfig.USM_ENABLED, false),
9898
TELEMETRY(GeneralConfig.TELEMETRY_ENABLED, true),
99-
DYNAMIC_INSTRUMENTATION(DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED, false),
100-
EXCEPTION_REPLAY(DebuggerConfig.EXCEPTION_REPLAY_ENABLED, false),
101-
CODE_ORIGIN(TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED, false),
99+
DEBUGGER(DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED, false),
100+
EXCEPTION_DEBUGGING(DebuggerConfig.EXCEPTION_REPLAY_ENABLED, false),
101+
SPAN_ORIGIN(TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED, false),
102102
DATA_JOBS(GeneralConfig.DATA_JOBS_ENABLED, false),
103103
AGENTLESS_LOG_SUBMISSION(GeneralConfig.AGENTLESS_LOG_SUBMISSION_ENABLED, false);
104104

@@ -149,10 +149,9 @@ public boolean isEnabledByDefault() {
149149
private static boolean ciVisibilityEnabled = false;
150150
private static boolean usmEnabled = false;
151151
private static boolean telemetryEnabled = true;
152-
private static boolean dynamicInstrumentationEnabled = false;
153-
private static boolean exceptionReplayEnabled = false;
154-
private static boolean codeOriginEnabled = false;
155-
private static boolean distributedDebuggerEnabled = false;
152+
private static boolean debuggerEnabled = false;
153+
private static boolean exceptionDebuggingEnabled = false;
154+
private static boolean spanOriginEnabled = false;
156155
private static boolean agentlessLogSubmissionEnabled = false;
157156

158157
/**
@@ -262,9 +261,9 @@ public static void start(
262261
|| isFeatureEnabled(AgentFeature.DEPRECATED_REMOTE_CONFIG);
263262
cwsEnabled = isFeatureEnabled(AgentFeature.CWS);
264263
telemetryEnabled = isFeatureEnabled(AgentFeature.TELEMETRY);
265-
dynamicInstrumentationEnabled = isFeatureEnabled(AgentFeature.DYNAMIC_INSTRUMENTATION);
266-
exceptionReplayEnabled = isFeatureEnabled(AgentFeature.EXCEPTION_REPLAY);
267-
codeOriginEnabled = isFeatureEnabled(AgentFeature.CODE_ORIGIN);
264+
debuggerEnabled = isFeatureEnabled(AgentFeature.DEBUGGER);
265+
exceptionDebuggingEnabled = isFeatureEnabled(AgentFeature.EXCEPTION_DEBUGGING);
266+
spanOriginEnabled = isFeatureEnabled(AgentFeature.SPAN_ORIGIN);
268267
agentlessLogSubmissionEnabled = isFeatureEnabled(AgentFeature.AGENTLESS_LOG_SUBMISSION);
269268

270269
if (profilingEnabled) {
@@ -1115,10 +1114,7 @@ private static void shutdownProfilingAgent(final boolean sync) {
11151114
}
11161115

11171116
private static void maybeStartDebugger(Instrumentation inst, Class<?> scoClass, Object sco) {
1118-
if (isExplicitlyDisabled(DebuggerConfig.DYNAMIC_INSTRUMENTATION_ENABLED)
1119-
&& isExplicitlyDisabled(DebuggerConfig.EXCEPTION_REPLAY_ENABLED)
1120-
&& isExplicitlyDisabled(TraceInstrumentationConfig.CODE_ORIGIN_FOR_SPANS_ENABLED)
1121-
&& isExplicitlyDisabled(DebuggerConfig.DISTRIBUTED_DEBUGGER_ENABLED)) {
1117+
if (!debuggerEnabled && !exceptionDebuggingEnabled && !spanOriginEnabled) {
11221118
return;
11231119
}
11241120
if (!remoteConfigEnabled) {
@@ -1128,11 +1124,6 @@ && isExplicitlyDisabled(DebuggerConfig.DISTRIBUTED_DEBUGGER_ENABLED)) {
11281124
startDebuggerAgent(inst, scoClass, sco);
11291125
}
11301126

1131-
private static boolean isExplicitlyDisabled(String booleanKey) {
1132-
return Config.get().configProvider().isSet(booleanKey)
1133-
&& !Config.get().configProvider().getBoolean(booleanKey);
1134-
}
1135-
11361127
private static synchronized void startDebuggerAgent(
11371128
Instrumentation inst, Class<?> scoClass, Object sco) {
11381129
StaticEventLogger.begin("Debugger");

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/TestFrameworkModule.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datadog.trace.api.civisibility.execution.TestExecutionPolicy;
66
import datadog.trace.api.civisibility.telemetry.tag.SkipReason;
77
import datadog.trace.api.civisibility.telemetry.tag.TestFrameworkInstrumentation;
8+
import java.util.Collection;
89
import javax.annotation.Nonnull;
910
import javax.annotation.Nullable;
1011

@@ -29,7 +30,7 @@ TestSuiteImpl testSuiteStart(
2930

3031
boolean isFlaky(@Nonnull TestIdentifier test);
3132

32-
boolean isModified(TestSourceData testSourceData);
33+
boolean isModified(@Nonnull TestSourceData testSourceData);
3334

3435
boolean isQuarantined(TestIdentifier test);
3536

@@ -47,7 +48,14 @@ TestSuiteImpl testSuiteStart(
4748
SkipReason skipReason(TestIdentifier test);
4849

4950
@Nonnull
50-
TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData testSource);
51+
TestExecutionPolicy executionPolicy(
52+
TestIdentifier test, TestSourceData testSource, Collection<String> testTags);
53+
54+
/**
55+
* Returns the priority of the test execution that can be used for ordering tests. The higher the
56+
* value, the higher the priority, meaning that the test should be executed earlier.
57+
*/
58+
int executionPriority(@Nullable TestIdentifier test, @Nonnull TestSourceData testSource);
5159

5260
void end(Long startTime);
5361
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/ProxyTestModule.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public boolean isFlaky(@Nonnull TestIdentifier test) {
100100
}
101101

102102
@Override
103-
public boolean isModified(TestSourceData testSourceData) {
103+
public boolean isModified(@Nonnull TestSourceData testSourceData) {
104104
return executionStrategy.isModified(testSourceData);
105105
}
106106

@@ -127,8 +127,14 @@ public SkipReason skipReason(TestIdentifier test) {
127127

128128
@Override
129129
@Nonnull
130-
public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData testSource) {
131-
return executionStrategy.executionPolicy(test, testSource);
130+
public TestExecutionPolicy executionPolicy(
131+
TestIdentifier test, TestSourceData testSource, Collection<String> testTags) {
132+
return executionStrategy.executionPolicy(test, testSource, testTags);
133+
}
134+
135+
@Override
136+
public int executionPriority(@Nullable TestIdentifier test, @Nonnull TestSourceData testSource) {
137+
return executionStrategy.executionPriority(test, testSource);
132138
}
133139

134140
@Override

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestModule.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import datadog.trace.civisibility.test.ExecutionResults;
2828
import datadog.trace.civisibility.test.ExecutionStrategy;
2929
import datadog.trace.civisibility.utils.SpanUtils;
30+
import java.util.Collection;
3031
import java.util.function.Consumer;
3132
import javax.annotation.Nonnull;
3233
import javax.annotation.Nullable;
@@ -85,7 +86,7 @@ public boolean isFlaky(@Nonnull TestIdentifier test) {
8586
}
8687

8788
@Override
88-
public boolean isModified(TestSourceData testSourceData) {
89+
public boolean isModified(@Nonnull TestSourceData testSourceData) {
8990
return executionStrategy.isModified(testSourceData);
9091
}
9192

@@ -112,8 +113,14 @@ public SkipReason skipReason(TestIdentifier test) {
112113

113114
@Override
114115
@Nonnull
115-
public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData testSource) {
116-
return executionStrategy.executionPolicy(test, testSource);
116+
public TestExecutionPolicy executionPolicy(
117+
TestIdentifier test, TestSourceData testSource, Collection<String> testTags) {
118+
return executionStrategy.executionPolicy(test, testSource, testTags);
119+
}
120+
121+
@Override
122+
public int executionPriority(@Nullable TestIdentifier test, @Nonnull TestSourceData testSource) {
123+
return executionStrategy.executionPriority(test, testSource);
117124
}
118125

119126
@Override

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/events/NoOpTestEventsHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public SkipReason skipReason(TestIdentifier test) {
100100

101101
@NotNull
102102
@Override
103-
public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData source) {
103+
public TestExecutionPolicy executionPolicy(
104+
TestIdentifier test, TestSourceData source, Collection<String> testTags) {
104105
return Regular.INSTANCE;
105106
}
106107

@@ -114,6 +115,12 @@ public boolean isFlaky(@Nonnull TestIdentifier test) {
114115
return false;
115116
}
116117

118+
@Override
119+
public int executionPriority(
120+
@Nullable TestIdentifier test, @Nonnull TestSourceData testSourceData) {
121+
return 0;
122+
}
123+
117124
@Override
118125
public void close() {
119126
// do nothing

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/events/TestEventsHandlerImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import datadog.json.JsonWriter;
44
import datadog.trace.api.DisableTestTrace;
5+
import datadog.trace.api.civisibility.CIConstants;
56
import datadog.trace.api.civisibility.DDTest;
67
import datadog.trace.api.civisibility.DDTestSuite;
7-
import datadog.trace.api.civisibility.InstrumentationBridge;
88
import datadog.trace.api.civisibility.config.TestIdentifier;
99
import datadog.trace.api.civisibility.config.TestSourceData;
1010
import datadog.trace.api.civisibility.events.TestEventsHandler;
@@ -206,7 +206,7 @@ public void onTestStart(
206206
test.setTag(Tags.TEST_TRAITS, getTestTraits(categories));
207207

208208
for (String category : categories) {
209-
if (category.endsWith(InstrumentationBridge.ITR_UNSKIPPABLE_TAG)) {
209+
if (category.endsWith(CIConstants.Tags.ITR_UNSKIPPABLE_TAG)) {
210210
test.setTag(Tags.TEST_ITR_UNSKIPPABLE, true);
211211
metricCollector.add(CiVisibilityCountMetric.ITR_UNSKIPPABLE, 1, EventType.TEST);
212212

@@ -295,8 +295,14 @@ public void onTestIgnore(
295295

296296
@Override
297297
@Nonnull
298-
public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData testSource) {
299-
return testModule.executionPolicy(test, testSource);
298+
public TestExecutionPolicy executionPolicy(
299+
TestIdentifier test, TestSourceData testSource, Collection<String> testTags) {
300+
return testModule.executionPolicy(test, testSource, testTags);
301+
}
302+
303+
@Override
304+
public int executionPriority(@Nullable TestIdentifier test, @Nonnull TestSourceData testSource) {
305+
return testModule.executionPriority(test, testSource);
300306
}
301307

302308
@Override

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/test/ExecutionStrategy.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.civisibility.test;
22

33
import datadog.trace.api.Config;
4+
import datadog.trace.api.civisibility.CIConstants;
45
import datadog.trace.api.civisibility.config.TestIdentifier;
56
import datadog.trace.api.civisibility.config.TestMetadata;
67
import datadog.trace.api.civisibility.config.TestSourceData;
@@ -18,6 +19,7 @@
1819
import datadog.trace.civisibility.source.LinesResolver;
1920
import datadog.trace.civisibility.source.SourcePathResolver;
2021
import java.lang.reflect.Method;
22+
import java.util.Collection;
2123
import java.util.Map;
2224
import java.util.concurrent.atomic.AtomicInteger;
2325
import javax.annotation.Nonnull;
@@ -117,7 +119,8 @@ public SkipReason skipReason(TestIdentifier test) {
117119
}
118120

119121
@Nonnull
120-
public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData testSource) {
122+
public TestExecutionPolicy executionPolicy(
123+
TestIdentifier test, TestSourceData testSource, Collection<String> testTags) {
121124
if (test == null) {
122125
return Regular.INSTANCE;
123126
}
@@ -129,7 +132,7 @@ public TestExecutionPolicy executionPolicy(TestIdentifier test, TestSourceData t
129132
RetryReason.attemptToFix);
130133
}
131134

132-
if (isEFDApplicable(test, testSource)) {
135+
if (isEFDApplicable(test, testSource, testTags)) {
133136
// check-then-act with "earlyFlakeDetectionsUsed" is not atomic here,
134137
// but we don't care if we go "a bit" over the limit, it does not have to be precise
135138
earlyFlakeDetectionsUsed.incrementAndGet();
@@ -163,11 +166,14 @@ private boolean isAutoRetryApplicable(TestIdentifier test) {
163166
&& autoRetriesUsed.get() < config.getCiVisibilityTotalFlakyRetryCount();
164167
}
165168

166-
private boolean isEFDApplicable(@Nonnull TestIdentifier test, TestSourceData testSource) {
169+
private boolean isEFDApplicable(
170+
@Nonnull TestIdentifier test, TestSourceData testSource, Collection<String> testTags) {
167171
EarlyFlakeDetectionSettings efdSettings = executionSettings.getEarlyFlakeDetectionSettings();
168172
return efdSettings.isEnabled()
169173
&& !isEFDLimitReached()
170-
&& (isNew(test) || isModified(testSource));
174+
&& (isNew(test) || isModified(testSource))
175+
// endsWith matching is needed for JUnit4-based frameworks, where tags are classes
176+
&& testTags.stream().noneMatch(t -> t.endsWith(CIConstants.Tags.EFD_DISABLE_TAG));
171177
}
172178

173179
public boolean isEFDLimitReached() {
@@ -187,7 +193,7 @@ public boolean isEFDLimitReached() {
187193
return detectionsUsed > threshold;
188194
}
189195

190-
public boolean isModified(TestSourceData testSourceData) {
196+
public boolean isModified(@Nonnull TestSourceData testSourceData) {
191197
Class<?> testClass = testSourceData.getTestClass();
192198
if (testClass == null) {
193199
return false;
@@ -219,4 +225,28 @@ private LinesResolver.Lines getLines(Method testMethod) {
219225
return linesResolver.getMethodLines(testMethod);
220226
}
221227
}
228+
229+
/**
230+
* Returns the priority of the test execution that can be used for ordering tests. The higher the
231+
* value, the higher the priority, meaning that the test should be executed earlier.
232+
*/
233+
public int executionPriority(@Nullable TestIdentifier test, @Nonnull TestSourceData testSource) {
234+
if (test == null) {
235+
return 0;
236+
}
237+
if (isNew(test)) {
238+
// execute new tests first
239+
return 300;
240+
}
241+
if (isModified(testSource)) {
242+
// then modified tests
243+
return 200;
244+
}
245+
if (isFlaky(test)) {
246+
// then tests known to be flaky
247+
return 100;
248+
}
249+
// then the rest
250+
return 0;
251+
}
222252
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/buildsystem/ProxyTestModuleTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ class ProxyTestModuleTest extends DDSpecification {
5555
)
5656

5757
when:
58-
def retryPolicy1 = proxyTestModule.executionPolicy(new TestIdentifier("suite", "test-1", null), TestSourceData.UNKNOWN)
58+
def retryPolicy1 = proxyTestModule.executionPolicy(new TestIdentifier("suite", "test-1", null), TestSourceData.UNKNOWN, [])
5959

6060
then:
6161
retryPolicy1.retry(false, 1L) // 2nd test execution, 1st retry globally
6262
!retryPolicy1.retry(false, 1L) // asking for 3rd test execution - local limit reached
6363

6464
when:
65-
def retryPolicy2 = proxyTestModule.executionPolicy(new TestIdentifier("suite", "test-2", null), TestSourceData.UNKNOWN)
65+
def retryPolicy2 = proxyTestModule.executionPolicy(new TestIdentifier("suite", "test-2", null), TestSourceData.UNKNOWN, [])
6666

6767
then:
6868
retryPolicy2.retry(false, 1L) // 2nd test execution, 2nd retry globally (since previous test was retried too)
6969
!retryPolicy2.retry(false, 1L) // asking for 3rd test execution - local limit reached
7070

7171
when:
72-
def retryPolicy3 = proxyTestModule.executionPolicy(new TestIdentifier("suite", "test-3", null), TestSourceData.UNKNOWN)
72+
def retryPolicy3 = proxyTestModule.executionPolicy(new TestIdentifier("suite", "test-3", null), TestSourceData.UNKNOWN, [])
7373

7474
then:
7575
!retryPolicy3.retry(false, 1L) // asking for 3rd retry globally - global limit reached

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/headless/HeadlessTestModuleTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ class HeadlessTestModuleTest extends SpanWriterTest {
2121
def headlessTestModule = givenAHeadlessTestModule()
2222

2323
when:
24-
def retryPolicy1 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-1", null), TestSourceData.UNKNOWN)
24+
def retryPolicy1 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-1", null), TestSourceData.UNKNOWN, [])
2525

2626
then:
2727
retryPolicy1.retry(false, 1L) // 2nd test execution, 1st retry globally
2828
!retryPolicy1.retry(false, 1L) // asking for 3rd test execution - local limit reached
2929

3030
when:
31-
def retryPolicy2 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-2", null), TestSourceData.UNKNOWN)
31+
def retryPolicy2 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-2", null), TestSourceData.UNKNOWN, [])
3232

3333
then:
3434
retryPolicy2.retry(false, 1L) // 2nd test execution, 2nd retry globally (since previous test was retried too)
3535
!retryPolicy2.retry(false, 1L) // asking for 3rd test execution - local limit reached
3636

3737
when:
38-
def retryPolicy3 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-3", null), TestSourceData.UNKNOWN)
38+
def retryPolicy3 = headlessTestModule.executionPolicy(new TestIdentifier("suite", "test-3", null), TestSourceData.UNKNOWN, [])
3939

4040
then:
4141
!retryPolicy3.retry(false, 1L) // asking for 3rd retry globally - global limit reached

0 commit comments

Comments
 (0)