Skip to content

Commit 5f1ccbf

Browse files
authored
Merge branch 'master' into andrea.marziali/ffm-instrument
2 parents afdd257 + fd65c0a commit 5f1ccbf

221 files changed

Lines changed: 5714 additions & 2695 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,64 @@
11
---
22
name: migrate-groovy-to-java
3-
description: migrate test groovy files to java
3+
description: >
4+
Converts Spock/Groovy test files in a Gradle module to equivalent JUnit 5 Java tests.
5+
Use when asked to "migrate groovy", "convert groovy to java", "g2j", or when a module
6+
has .groovy test files that need to be replaced with .java equivalents.
47
---
58

69
Migrate test Groovy files to Java using JUnit 5
710

8-
1. List all groovy files of the current gradle module
9-
2. convert groovy files to Java using Junit 5
10-
3. make sure the tests are still passing after migration
11-
4. remove groovy files
11+
1. List all Groovy files of the current Gradle module
12+
2. Convert Groovy files to Java using JUnit 5
13+
3. Make sure the tests are still passing after migration and that the test count has not changed
14+
4. Remove Groovy files
15+
5. Add the migrated module path(s) to `.github/g2j-migrated-modules.txt`
1216

13-
When converting groovy code to java code make sure that:
14-
- the Java code generated is compatible with JDK 8
15-
- when translating Spock test, favor using `@CsvSource` with `|` delimiters
16-
- when using a `@MethodSource`, use the test method name, and suffix it with `_arguments`
17-
- when converting tuples, create light dedicated structure instead to keep the typing system
17+
When converting Groovy code to Java code, make sure that:
18+
- The Java code generated is compatible with JDK 8
19+
- When translating Spock tests, prefer `@TableTest` for data rows that are naturally tabular. See detailed guidance in the "TableTest usage" section.
20+
- `@TableTest` and `@MethodSource` may be combined on the same `@ParameterizedTest` when most cases are tabular but a few cases require programmatic setup.
21+
- In combined mode, keep table-friendly cases in `@TableTest`, and put only non-tabular/complex cases in `@MethodSource`.
22+
- If `@TableTest` is not viable for the test at all, use `@MethodSource` only.
23+
- For `@MethodSource`, name the arguments method `<testMethodName>Arguments` (camelCase, e.g. `testMethodArguments`) and return `Stream<Arguments>` using `Stream.of(...)` and `arguments(...)` with static import.
24+
- Ensure parameterized test names are human-readable (i.e. no hashcodes); instead add a description string as the first `Arguments.arguments(...)` value or index the test case
25+
- When converting tuples, create a light dedicated structure instead to keep the typing system
1826
- Instead of checking a state and throwing an exception, use JUnit asserts
19-
- Do not wrap checked exception and throwing a Runtime exception, prefer adding a throws clause at method declaration
27+
- Instead of using `assertTrue(a.equals(b))` or `assertFalse(a.equals(b))`, use `assertEquals(expected, actual)` and `assertNotEquals(unexpected, actual)`
28+
- Import frequently used types rather than using fully-qualified names inline, to improve readability
29+
- Do not wrap checked exceptions and throw a Runtime exception; prefer adding a throws clause at method declaration
2030
- Do not mark local variables `final`
31+
- Ensure variables are human-readable; avoid single-letter names and pre-define variables that are referenced multiple times
32+
- When translating Spock `Mock(...)` usage, use `libs.bundles.mockito` instead of writing manual recording/stub implementations
33+
34+
TableTest usage
35+
Dependency, if missing add:
36+
- Groovy: testImplementation libs.tabletest
37+
- Kotlin: testImplementation(libs.tabletest)
38+
39+
Import: `import org.tabletest.junit.TableTest;`
40+
41+
JDK 8 rules:
42+
- No text blocks.
43+
- @TableTest must use String[] annotation array syntax:
44+
```
45+
@TableTest({
46+
"a | b",
47+
"1 | 2"
48+
})
49+
```
50+
51+
Spock `where:`@TableTest:
52+
- First row = header (column names = method parameters).
53+
- Add `scenario` column as first column (display name, not a method parameter).
54+
- Use `|` delimiter; align columns so pipes line up vertically.
55+
- Prefer single quotes for strings with special chars (e.g., `'a|b'`, `'[]'`).
56+
- Blank cell = null (object types); `''` = empty string.
57+
- Collections: `[a, b]` = List/array, `{a, b}` = Set, `[k: v]` = Map.
58+
59+
Mixed eligibility:
60+
- Prefer combining `@TableTest` + `@MethodSource` on one `@ParameterizedTest` when only some cases are complex.
61+
- Use `@MethodSource` only when tabular representation is not practical for the test.
62+
63+
Do NOT use @TableTest when:
64+
- Majority of rows require complex objects or custom converters.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
name: migrate-junit-source-to-tabletest
3+
description: Convert JUnit 5 @MethodSource/@CsvSource/@ValueSource parameterized tests to @TableTest (JDK8)
4+
---
5+
Goal: Migrate JUnit 5 parameterized tests using @MethodSource/@CsvSource/@ValueSource to @TableTest with minimal churn and passing tests.
6+
7+
Process (do in this order):
8+
1) Locate targets via Grep (no agent subprocess). Search for: "@ParameterizedTest", "@MethodSource", "@CsvSource", "@ValueSource".
9+
2) Read all matching files up front (parallel is OK).
10+
3) Convert eligible tests to @TableTest.
11+
4) Write each modified file once in full using Write (no incremental per-test edits).
12+
5) Run module tests once and verify "BUILD SUCCESSFUL". If failed, inspect JUnit XML report.
13+
14+
Dependency:
15+
- If missing, add:
16+
- Groovy: testImplementation libs.tabletest
17+
- Kotlin: testImplementation(libs.tabletest)
18+
19+
Import: `import org.tabletest.junit.TableTest;`
20+
21+
JDK 8 rules:
22+
- No text blocks.
23+
- @TableTest must use String[] annotation array syntax:
24+
```
25+
@TableTest({
26+
"a | b",
27+
"1 | 2"
28+
})
29+
```
30+
31+
Table formatting rules (mandatory):
32+
- Always include a header row (parameter names).
33+
- Always add a "scenario" column; using common sense for naming; scenario is NOT a method parameter.
34+
- Use '|' as delimiter.
35+
- Align columns with spaces so pipes line up vertically.
36+
- Prefer single quotes for strings requiring quotes (e.g., 'a|b', '[]', '{}', ' ').
37+
38+
Conversions:
39+
A) @CsvSource
40+
- Remove @ParameterizedTest and @CsvSource.
41+
- If delimiter is '|': rows map directly to @TableTest.
42+
- If delimiter is ',' (default): replace ',' with '|' in rows.
43+
44+
B) @ValueSource
45+
- Convert to @TableTest with header from parameter name.
46+
- Each value becomes one row.
47+
- Add "scenario" column using common sense for name.
48+
49+
C) @MethodSource (convert only if values are representable as strings)
50+
- Convert when argument values are primitives, strings, enums, booleans, nulls, and simple collection literals supported by TableTest:
51+
- Array: [a, b, ...]
52+
- List: [a, b, ...]
53+
- Set: {a, b, ...}
54+
- Map: [k: v, ...]
55+
- `@TableTest` and `@MethodSource` may be combined on the same `@ParameterizedTest` when most cases are tabular but a few cases require programmatic setup.
56+
- In combined mode, keep table-friendly cases in `@TableTest`, and put only non-tabular/complex cases in `@MethodSource`.
57+
- If `@TableTest` is not viable for the test at all, use `@MethodSource` only.
58+
- For `@MethodSource`, name the arguments method `<testMethodName>Arguments` (camelCase, e.g. `testMethodArguments`) and return `Stream<Arguments>` using `Stream.of(...)` and `arguments(...)` with static import.
59+
- Blank cell = null (non-primitive).
60+
- '' = empty string.
61+
- For String params that start with '[' or '{', quote to avoid collection parsing (prefer '[]'/'{}').
62+
63+
Scenario handling:
64+
- If MethodSource includes a leading description string OR @ParameterizedTest(name=...) uses {0}, convert that to a scenario column and remove that parameter from method signature.
65+
66+
Cleanup:
67+
- Delete now-unused @MethodSource provider methods and unused imports.
68+
69+
Mixed eligibility:
70+
- Prefer combining `@TableTest` + `@MethodSource` on one `@ParameterizedTest` when only some cases are complex.
71+
72+
Do NOT convert when:
73+
- Most rows require complex builders/mocks.
74+
75+
Test command (exact):
76+
./gradlew :path:to:module:test --rerun-tasks 2>&1 | tail -20
77+
- If BUILD FAILED: cat path/to/module/build/test-results/test/TEST-*.xml

.github/CODEOWNERS

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@
5151
**/InferredProxy*.groovy @DataDog/apm-serverless
5252

5353
# @DataDog/apm-lang-platform-java
54-
/.circleci/ @DataDog/apm-lang-platform-java
5554
/.github/ @DataDog/apm-lang-platform-java
5655
/benchmark/ @DataDog/apm-lang-platform-java
5756
/components/ @DataDog/apm-lang-platform-java
58-
/dd-java-agent/instrumentation/java-*/ @DataDog/apm-lang-platform-java
57+
/dd-java-agent/instrumentation/java/ @DataDog/apm-lang-platform-java
5958
/dd-smoke-tests/concurrent/ @DataDog/apm-lang-platform-java
6059
/dd-smoke-tests/lib-injection/ @DataDog/apm-lang-platform-java
6160
/metadata/ @DataDog/apm-lang-platform-java
@@ -80,7 +79,7 @@
8079
/dd-smoke-tests/iast-propagation/ @DataDog/asm-java
8180
/dd-smoke-tests/iast-util/ @DataDog/asm-java
8281
/dd-smoke-tests/spring-security/ @DataDog/asm-java
83-
/dd-java-agent/instrumentation/commons-fileupload/ @DataDog/asm-java
82+
/dd-java-agent/instrumentation/commons-fileupload-1.5/ @DataDog/asm-java
8483
/dd-java-agent/instrumentation/spring/spring-security/ @DataDog/asm-java
8584
/dd-trace-api/src/main/java/datadog/trace/api/aiguard/ @DataDog/asm-java
8685
/dd-trace-api/src/main/java/datadog/trace/api/EventTracker.java @DataDog/asm-java
@@ -103,12 +102,12 @@
103102
/dd-java-agent/instrumentation/cucumber-5.4/ @DataDog/ci-app-libraries
104103
/dd-java-agent/instrumentation/jacoco-0.8.9/ @DataDog/ci-app-libraries
105104
/dd-java-agent/instrumentation/junit @DataDog/ci-app-libraries
106-
/dd-java-agent/instrumentation/karate/ @DataDog/ci-app-libraries
105+
/dd-java-agent/instrumentation/karate-1.0/ @DataDog/ci-app-libraries
107106
/dd-java-agent/instrumentation/scalatest-3.0.8/ @DataDog/ci-app-libraries
108-
/dd-java-agent/instrumentation/selenium/ @DataDog/ci-app-libraries
107+
/dd-java-agent/instrumentation/selenium-3.13/ @DataDog/ci-app-libraries
109108
/dd-java-agent/instrumentation/testng/ @DataDog/ci-app-libraries
110109
/dd-java-agent/instrumentation/gradle/ @DataDog/ci-app-libraries
111-
/dd-java-agent/instrumentation/gradle-testing/ @DataDog/ci-app-libraries
110+
/dd-java-agent/instrumentation/gradle-testing-5.1/ @DataDog/ci-app-libraries
112111
/dd-java-agent/instrumentation/maven @DataDog/ci-app-libraries
113112
/dd-java-agent/instrumentation/weaver-0.9/ @DataDog/ci-app-libraries
114113
/dd-smoke-tests/gradle/ @DataDog/ci-app-libraries
@@ -130,24 +129,24 @@
130129
/dd-java-agent/instrumentation/spark/ @DataDog/data-jobs-monitoring
131130

132131
# @DataDog/data-streams-monitoring
133-
/dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/datastreams @DataDog/data-streams-monitoring
134-
/dd-trace-core/src/main/java/datadog/trace/core/datastreams @DataDog/data-streams-monitoring
135-
/dd-trace-core/src/test/groovy/datadog/trace/core/datastreams @DataDog/data-streams-monitoring
136-
/internal-api/src/main/java/datadog/trace/api/datastreams @DataDog/data-streams-monitoring
137-
/dd-smoke-tests/datastreams/ @DataDog/data-streams-monitoring
138-
/internal-api/src/test/groovy/datadog/trace/api/datastreams @DataDog/data-streams-monitoring
139-
**/datastreams/ @DataDog/data-streams-monitoring
140-
**/DataStreams* @DataDog/data-streams-monitoring
141-
**/dsmTest/** @DataDog/data-streams-monitoring
132+
/dd-java-agent/instrumentation-testing/src/main/groovy/datadog/trace/agent/test/datastreams @DataDog/data-streams-monitoring
133+
/dd-trace-core/src/main/java/datadog/trace/core/datastreams @DataDog/data-streams-monitoring
134+
/dd-trace-core/src/test/groovy/datadog/trace/core/datastreams @DataDog/data-streams-monitoring
135+
/internal-api/src/main/java/datadog/trace/api/datastreams @DataDog/data-streams-monitoring
136+
/dd-smoke-tests/datastreams/ @DataDog/data-streams-monitoring
137+
/internal-api/src/test/groovy/datadog/trace/api/datastreams @DataDog/data-streams-monitoring
138+
**/datastreams/ @DataDog/data-streams-monitoring
139+
**/DataStreams* @DataDog/data-streams-monitoring
140+
**/dsmTest/** @DataDog/data-streams-monitoring
142141

143142
/dd-java-agent/instrumentation/armeria/armeria-grpc-0.84/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
144-
/dd-java-agent/instrumentation/avro/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
143+
/dd-java-agent/instrumentation/avro-1.11.3/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
145144
/dd-java-agent/instrumentation/aws-java/aws-java-sns-1.0/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
146145
/dd-java-agent/instrumentation/aws-java/aws-java-sns-2.0/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
147146
/dd-java-agent/instrumentation/aws-java/aws-java-sqs-1.0/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
148147
/dd-java-agent/instrumentation/aws-java/aws-java-sqs-2.0/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
149148
/dd-java-agent/instrumentation/confluent-schema-registry/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
150-
/dd-java-agent/instrumentation/google-pubsub/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
149+
/dd-java-agent/instrumentation/google-pubsub-1.116/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
151150
/dd-java-agent/instrumentation/grpc-1.5/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
152151
/dd-java-agent/instrumentation/kafka/kafka-clients-0.11/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
153152
/dd-java-agent/instrumentation/kafka/kafka-clients-3.8/ @DataDog/data-streams-monitoring @DataDog/apm-idm-java
@@ -183,7 +182,8 @@
183182
/dd-trace-core/src/test/groovy/datadog/trace/llmobs/ @DataDog/ml-observability
184183

185184
# @DataDog/database-monitoring
186-
datadog/trace/bootstrap/instrumentation/dbm @DataDog/database-monitoring @DataDog/apm-idm-java
185+
/dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/dbm/ @DataDog/database-monitoring @DataDog/apm-idm-java
186+
/dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/instrumentation/dbm/ @DataDog/database-monitoring @DataDog/apm-idm-java
187187

188188
# @DataDog/rum
189189
/internal-api/src/main/java/datadog/trace/api/rum/ @DataDog/rum
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
issuer: https://token.actions.githubusercontent.com
2+
3+
subject: repo:DataDog/dd-trace-java:ref:refs/heads/master
4+
5+
claim_pattern:
6+
event_name: (schedule|workflow_dispatch)
7+
ref: refs/heads/master
8+
ref_protected: "true"
9+
job_workflow_ref: DataDog/dd-trace-java/\.github/workflows/update-smoke-test-latest-versions\.yaml@refs/heads/master
10+
11+
permissions:
12+
contents: write
13+
pull_requests: write

.github/g2j-migrated-modules.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file lists modules that have been migrated from Groovy to Java / JUnit 5.
2+
# New *.groovy files under any src/<*test*>/groovy/ path
3+
# in these modules will fail the 'enforce-groovy-migration' PR check.
4+
#
5+
# After a module is migrated, add it on a new line here.
6+
# Use the filesystem path prefix as seen below.
7+
8+
buildSrc/call-site-instrumentation-plugin
9+
components/json
10+
dd-trace-api

.github/workflows/README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,6 @@ Close them if no following update within a week.
9191

9292
_Recovery:_ Manually trigger the action again.
9393

94-
### update-docker-build-image [🔗](update-docker-build-image.yaml)
95-
96-
_Trigger:_ Quarterly released, loosely [a day after the new image tag is created](https://github.com/DataDog/dd-trace-java-docker-build/blob/master/.github/workflows/docker-tag.yml).
97-
98-
_Action:_ Update the Docker build image used in GitLab CI with the latest tag.
99-
100-
_Recovery:_ Download artifacts and upload them manually to the related _download release_.
101-
102-
_Notes:_ Manually trigger the action again given the desired image tag as input.
103-
10494
### update-download-releases [🔗](update-download-releases.yaml)
10595

10696
_Trigger:_ When a release is published.
@@ -123,6 +113,19 @@ _Action:_
123113

124114
_Recovery:_ Check at the milestone for the related issues and update them manually.
125115

116+
### enforce-groovy-migration [🔗](enforce-groovy-migration.yaml)
117+
118+
_Trigger:_ When creating or updating a pull request targeting `master`, or when labels are updated.
119+
120+
_Actions:_
121+
122+
* Fail the PR if a new Groovy test file is added to a module listed in [`.github/g2j-migrated-modules.txt`](../g2j-migrated-modules.txt) (hard enforcement),
123+
* Post a warning comment on the PR if a new Groovy test file is added to any other non-exempt module (soft warning). Instrumentation (`dd-java-agent/instrumentation/`) and smoke-test (`dd-smoke-tests/`) modules are exempt from this warning.
124+
125+
_Recovery:_ Re-write the Groovy test files in Java / JUnit 5. To override this check entirely, add the `tag: override-groovy-enforcement` label to the PR. Remove the label to re-enable enforcement.
126+
127+
_Notes:_ The migrated modules list is always read from `master`. Add a new entry to `.github/g2j-migrated-modules.txt` each time a module is migrated to Java / JUnit 5.
128+
126129
## Code Quality and Security
127130

128131
### analyze-changes [🔗](analyze-changes.yaml)
@@ -158,6 +161,14 @@ _Action:_ Create a PR updating the Grade dependencies and their locking files.
158161

159162
_Recovery:_ Manually trigger the action again.
160163

164+
### update-smoke-test-latest-versions [🔗](update-smoke-test-latest-versions.yaml)
165+
166+
_Trigger:_ Every week or manually.
167+
168+
_Action:_ Create a PR updating the pinned "latest" tool versions (Gradle, Maven, Maven Surefire) used by CI Visibility smoke tests.
169+
170+
_Recovery:_ Manually trigger the action again.
171+
161172
### update-jmxfetch-submodule [🔗](update-jmxfetch-submodule.yaml)
162173

163174
_Trigger:_ Monthly or manually

.github/workflows/analyze-changes.yaml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,8 @@ jobs:
3939
env:
4040
ORG_GRADLE_PROJECT_akkaRepositoryToken: ${{ secrets.AKKA_REPO_TOKEN }}
4141
run: |
42-
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx3G -Xms2G'" \
43-
JAVA_HOME=$JAVA_HOME_8_X64 \
44-
JAVA_8_HOME=$JAVA_HOME_8_X64 \
45-
JAVA_11_HOME=$JAVA_HOME_11_X64 \
46-
JAVA_17_HOME=$JAVA_HOME_17_X64 \
47-
JAVA_21_HOME=$JAVA_HOME_21_X64 \
48-
./gradlew clean :dd-java-agent:shadowJar \
49-
--build-cache --parallel --stacktrace --no-daemon --max-workers=4
42+
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xms2G -Xmx3G'" \
43+
./gradlew clean :dd-java-agent:shadowJar --build-cache --parallel --stacktrace --no-daemon --max-workers=4
5044
5145
- name: Perform CodeQL Analysis and upload results to GitHub Security tab
5246
uses: github/codeql-action/analyze@c793b717bc78562f491db7b0e93a3a178b099162 # v4.32.5
@@ -85,14 +79,8 @@ jobs:
8579
env:
8680
ORG_GRADLE_PROJECT_akkaRepositoryToken: ${{ secrets.AKKA_REPO_TOKEN }}
8781
run: |
88-
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx3G -Xms2G'" \
89-
JAVA_HOME=$JAVA_HOME_8_X64 \
90-
JAVA_8_HOME=$JAVA_HOME_8_X64 \
91-
JAVA_11_HOME=$JAVA_HOME_11_X64 \
92-
JAVA_17_HOME=$JAVA_HOME_17_X64 \
93-
JAVA_21_HOME=$JAVA_HOME_21_X64 \
94-
./gradlew clean publishToMavenLocal \
95-
--build-cache --parallel --stacktrace --no-daemon --max-workers=4
82+
GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xms2G -Xmx3G'" \
83+
./gradlew clean publishToMavenLocal --build-cache --parallel --stacktrace --no-daemon --max-workers=4
9684
9785
- name: Copy published artifacts
9886
run: |

0 commit comments

Comments
 (0)