Commit 5181a21
test: replace WithConfigExtension's retransform agent with a premain agent
The JUnit 5 WithConfigExtension used ByteBuddy retransformation at
@BeforeAll to make Config and InstrumenterConfig INSTANCE fields
public/volatile/non-final. Retransformation is not guaranteed when the
class has been loaded before the extension runs (e.g. through
CoreTracer), which caused intermittent failures on at least HotSpot 1.8,
IBM J9, and OpenJ9 Semeru jobs.
This commit switches to a load-time javaagent that rewrites the INSTANCE
fields upon class cload.
It introduces in particular `dd-trace-java.modifiable-config` convention
plugin whose role is to configure the test jvm with the java agent to
every Test task. This convention plugin is applied automatically via
dd-trace-java.configure-tests which is itself applied via
java_no_deps.gradle.
`WithConfigExtension` no longer installs a ByteBuddy agent
programmatically; instead it just verifies the fields are already
modifiable.
refactor: simplify WithConfigExtension now that load-time agent guarantees writable Config fields
With modifiable-config-agent attached to every test JVM, the `INSTANCE`
fields of `Config` and `InstrumenterConfig` are always
`public`/`volatile`/non-`final`
by the time `WithConfigExtension` is loaded. The runtime state
machine that previously guarded the ByteBuddy retransform is therefore
dead code.
Collapse it:
- Move reflective lookups of the INSTANCE fields and default constructors
into a static {} block that first calls
ensureConfigInstrumentationHasBeenApplied() and then caches the
handles as static finals. Failure throws ExceptionInInitializerError,
which surfaces as a clear test-class load failure pointing at the
Gradle convention plugin.
- Remove the isConfigInstanceModifiable / configModificationFailed /
configTransformerInstalled flags and every guard they fed.
- Drop makeConfigInstanceModifiable(), checkConfigTransformation(),
and checkWritable() — all redundant with the static-init check.
- Drop the corresponding JUnit assert* static imports.
- beforeAll/beforeEach/afterEach/afterAll now call rebuildConfig()
unconditionally.
- Update the class Javadoc to reflect the new mechanism.
Co-Authored-By: Claude <noreply@anthropic.com>
ci: trigger non-default JVM tests
[ci: NON_DEFAULT_JVMS]
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
revert: Mark PendingTraceBufferTest tests flaky (#11383)
chore: make spotless happy
[ci: NON_DEFAULT_JVMS]
fix(build): skip modifiable-config agent when Test JVM already has -javaagent
The `dd-trace-java.modifiable-config` convention plugin unconditionally
attached a second `-javaagent:modifiable-config-agent.jar` to every Test
JVM. That breaks the few modules whose tests already launch with the real
dd-java-agent attached (currently only `:dd-java-agent`'s integration
tests, via the `doFirst` at `dd-java-agent/build.gradle:454-457`):
* `AgentBootstrap.installAgentJar` tries the class' CodeSource first,
then `getAgentFileFromJavaagentArg`, then a ClassLoader-resource
lookup. On the failing matrix the CodeSource is null for the
bootstrap class, so it falls through to the `-javaagent:` arg.
* `getAgentFileFromJavaagentArg` refuses to pick when more than one
`-javaagent:` is present ("multiple javaagents specified") and
returns null.
* The ClassLoader fallback then throws `IllegalArgumentException: URI
is not absolute` for the bootstrap class URL.
Net effect: the tracing agent never installs and suites like
`OpenTracingTest` / `ShadowPackageRenamingTest` fail across non-default
JVMs (ibm8, semeru11/17, zulu11, tip).
Alternatives considered and rejected:
* Manifest scan in `getAgentFileFromJavaagentArg` to pick the entry
whose `Main-Class` is `AgentBootstrap`: meaningful bootstrap-
performance cost (open every `-javaagent:` jar, read MANIFEST.MF)
on a hot path that runs on every JVM startup.
* `-Ddd.agent.jar.path` / `DD_AGENT_JAR_PATH`: no equivalent knob
exists today, adds an attacker-controllable file path, and only
helps when the CLI is already ambiguous — not worth the surface.
Skipping is safe for `:dd-java-agent`'s tests: nothing under
`dd-java-agent/src/test` (Java or Groovy) references
`Config` / `InstrumenterConfig` `INSTANCE`, and nothing uses
`WithConfigExtension`. The tests rely on the real agent's startup to
populate `Config.INSTANCE`, not on swapping the singleton mid-test.
Implementation: defer the attach to a `doFirst` that inspects
`allJvmArgs` for an existing non-modifiable-config `-javaagent:` entry.
Gradle prepends each new `doFirst`, so the plugin's check runs after
the project's own agent-attach `doFirst` and sees the real arg before
the JVM forks. When skipping, emit an `INFO`-level log so the decision
is visible under `--info`.
[ci: NON_DEFAULT_JVMS]
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Increase timeout to pass for ibm8
filling the delaying buffer for test bufferFullYieldsImmediateWrite
takes more than 5 seconds on ibm8 and CI
[ci: NON_DEFAULT_JVMS]
Merge branch 'master' into bdu/moves-with-config-extension-agent-to-commandline-via-convention-plugin
Co-authored-by: jpbempel <jean-philippe.bempel@datadoghq.com>
Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent c2e8fe0 commit 5181a21
9 files changed
Lines changed: 211 additions & 144 deletions
File tree
- buildSrc
- modifiable-config-agent
- src/main/java/datadog/trace/agent/test/config
- src/main/kotlin
- dd-trace-core/src/test/java/datadog/trace/core
- utils/junit-utils
- src/main/java/datadog/trace/junit/utils/config
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
Lines changed: 80 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
| |||
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
Lines changed: 1 addition & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
| |||
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | | - | |
| 59 | + | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
| |||
196 | 195 | | |
197 | 196 | | |
198 | 197 | | |
199 | | - | |
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
| |||
221 | 219 | | |
222 | 220 | | |
223 | 221 | | |
224 | | - | |
225 | 222 | | |
226 | 223 | | |
227 | 224 | | |
| |||
381 | 378 | | |
382 | 379 | | |
383 | 380 | | |
384 | | - | |
385 | 381 | | |
386 | 382 | | |
387 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
0 commit comments