Skip to content

Commit 3437189

Browse files
committed
Merge remote-tracking branch 'origin/master' into bdu/processor-context
2 parents 9b3b0aa + 68aa369 commit 3437189

628 files changed

Lines changed: 3419 additions & 982 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.

.gitlab-ci.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,24 @@ maven-central-pre-release-check:
222222
image: ${BUILDER_IMAGE_REPO}:${BUILDER_IMAGE_VERSION_PREFIX}base
223223
stage: .pre
224224
rules:
225+
- if: '$CI_COMMIT_BRANCH == "master"'
226+
when: on_success
227+
allow_failure: false
225228
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
226229
when: on_success
227230
allow_failure: false
228231
script:
229232
- |
230233
MAVEN_CENTRAL_USERNAME=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_username --with-decryption --query "Parameter.Value" --out text)
231234
MAVEN_CENTRAL_PASSWORD=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.central_password --with-decryption --query "Parameter.Value" --out text)
232-
# See https://central.sonatype.org/publish/publish-portal-api/
233-
# 15e0cbbb-deff-421e-9e02-296a24d0cada is deployment, any deployment id listed in central work, the idea is to check whether the token can authenticate
234-
curl --request POST --include --fail https://central.sonatype.com/api/v1/publisher/status?id=15e0cbbb-deff-421e-9e02-296a24d0cada --header "Authorization: Bearer $(printf "$MAVEN_CENTRAL_USERNAME:$MAVEN_CENTRAL_PASSWORD" | base64)"
235-
if [ $? -ne 0 ]; then
236-
echo "Failed to authenticate against central. Check credentials, see https://datadoghq.atlassian.net/wiki/x/Oog5OgE"
235+
# See https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/
236+
# Use the staging API search endpoint to validate the tokens without relying on a specific deployment
237+
AUTHORIZATION_HEADER="Authorization: Bearer $(printf '%s:%s' "$MAVEN_CENTRAL_USERNAME" "$MAVEN_CENTRAL_PASSWORD" | base64)"
238+
if ! curl --silent --show-error --fail \
239+
"https://ossrh-staging-api.central.sonatype.com/manual/search/repositories?ip=any" \
240+
--header "$AUTHORIZATION_HEADER" \
241+
> /dev/null; then
242+
echo "Failed to authenticate tokens against maven central staging API. Check credentials and see https://datadoghq.atlassian.net/wiki/x/Oog5OgE"
237243
exit 1
238244
fi
239245

build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
id("dd-trace-java.config-inversion-linter")
1212
id("dd-trace-java.ci-jobs")
1313

14-
id("com.diffplug.spotless") version "8.2.1"
14+
id("com.diffplug.spotless") version "8.4.0"
1515
id("me.champeau.gradle.japicmp") version "0.4.3"
1616
id("com.github.spotbugs") version "6.4.8"
1717
id("de.thetaphi.forbiddenapis") version "3.10"
@@ -38,7 +38,8 @@ with(extensions["spotlessPredeclare"] as SpotlessExtension) {
3838
java {
3939
removeUnusedImports()
4040

41-
googleJavaFormat("1.34.1")
41+
googleJavaFormat("1.35.0")
42+
tableTestFormatter("1.1.1")
4243
}
4344
groovyGradle {
4445
greclipse()

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
`java-gradle-plugin`
33
`kotlin-dsl`
44
`jvm-test-suite`
5-
id("com.diffplug.spotless") version "8.2.1"
5+
id("com.diffplug.spotless") version "8.4.0"
66
}
77

88
// The buildSrc still needs to target Java 8 as build time instrumentation and muzzle plugin

buildSrc/call-site-instrumentation-plugin/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
java
3-
id("com.diffplug.spotless") version "8.2.1"
3+
id("com.diffplug.spotless") version "8.4.0"
44
id("com.gradleup.shadow") version "8.3.9"
55
}
66

@@ -16,7 +16,7 @@ spotless {
1616
target("src/**/*.java")
1717
// ignore embedded test projects
1818
targetExclude("src/test/resources/**")
19-
googleJavaFormat("1.34.1")
19+
googleJavaFormat("1.35.0")
2020
}
2121
}
2222

buildSrc/src/test/kotlin/datadog/gradle/plugin/GradleFixture.kt

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,111 @@ import org.gradle.testkit.runner.UnexpectedBuildResultException
66
import org.intellij.lang.annotations.Language
77
import org.w3c.dom.Document
88
import java.io.File
9+
import java.nio.file.Files
910
import javax.xml.parsers.DocumentBuilderFactory
1011

1112
/**
1213
* Base fixture for Gradle plugin integration tests.
1314
* Provides common functionality for setting up test projects and running Gradle builds.
1415
*/
1516
internal open class GradleFixture(protected val projectDir: File) {
17+
// Each fixture gets its own testkit dir in the system temp directory (NOT under
18+
// projectDir) so that JUnit's @TempDir cleanup doesn't race with daemon file locks.
19+
// See https://github.com/gradle/gradle/issues/12535
20+
// A fresh daemon is started per test — ensuring withEnvironment() vars (e.g.
21+
// MAVEN_REPOSITORY_PROXY) are correctly set on the daemon JVM and not inherited
22+
// from a previously-started daemon with a different test's environment.
23+
// A JVM shutdown hook removes the directory after all tests have run (and daemons
24+
// have been stopped), so file locks are guaranteed to be released by then.
25+
private val testKitDir: File by lazy {
26+
Files.createTempDirectory("gradle-testkit-").toFile().also { dir ->
27+
Runtime.getRuntime().addShutdownHook(Thread { dir.deleteRecursively() })
28+
}
29+
}
30+
1631
/**
1732
* Runs Gradle with the specified arguments.
1833
*
34+
* After the build completes, any Gradle daemons started by TestKit are killed
35+
* so their file locks on the testkit cache are released before JUnit `@TempDir`
36+
* cleanup. See https://github.com/gradle/gradle/issues/12535
37+
*
1938
* @param args Gradle task names and arguments
2039
* @param expectFailure Whether the build is expected to fail
2140
* @param env Environment variables to set (merged with system environment)
2241
* @return The build result
2342
*/
2443
fun run(vararg args: String, expectFailure: Boolean = false, env: Map<String, String> = emptyMap()): BuildResult {
2544
val runner = GradleRunner.create()
26-
// Use a testkit dir scoped to this fixture's projectDir. The Tooling API always uses a
27-
// daemon and ignores org.gradle.daemon=false. By giving each test its own testkit dir,
28-
// we force a fresh daemon per test — ensuring withEnvironment() vars (e.g.
29-
// MAVEN_REPOSITORY_PROXY) are correctly set on the daemon JVM and not inherited from
30-
// a previously-started daemon with a different test's environment.
31-
.withTestKitDir(file(".testkit"))
45+
.withTestKitDir(testKitDir)
3246
.withPluginClasspath()
3347
.withProjectDir(projectDir)
48+
// Using withDebug prevents starting a daemon, but it doesn't work with withEnvironment
3449
.withEnvironment(System.getenv() + env)
3550
.withArguments(*args)
3651
return try {
3752
if (expectFailure) runner.buildAndFail() else runner.build()
3853
} catch (e: UnexpectedBuildResultException) {
3954
e.buildResult
55+
} finally {
56+
stopDaemons()
4057
}
4158
}
4259

60+
/**
61+
* Kills Gradle daemons started by TestKit for this fixture's testkit dir.
62+
*
63+
* The Gradle Tooling API (used by [GradleRunner]) always spawns a daemon and
64+
* provides no public API to stop it (https://github.com/gradle/gradle/issues/12535).
65+
* We replicate the strategy Gradle uses in its own integration tests
66+
* ([DaemonLogsAnalyzer.killAll()][1]):
67+
*
68+
* 1. Scan `<testkit>/daemon/<version>/` for log files matching
69+
* `DaemonLogConstants.DAEMON_LOG_PREFIX + pid + DaemonLogConstants.DAEMON_LOG_SUFFIX`,
70+
* i.e. `daemon-<pid>.out.log`.
71+
* 2. Extract the PID from the filename and kill the process.
72+
*
73+
* Trade-offs of the PID-from-filename approach:
74+
* - **PID recycling**: between the build finishing and `kill` being sent, the OS
75+
* could theoretically recycle the PID. In practice the window is short
76+
* (the `finally` block runs immediately after the build) so the risk is negligible.
77+
* - **Filename convention is internal**: Gradle's `DaemonLogConstants.DAEMON_LOG_PREFIX`
78+
* (`"daemon-"`) / `DAEMON_LOG_SUFFIX` (`".out.log"`) are not public API; a future
79+
* Gradle version could change them. The `toLongOrNull()` guard safely skips entries
80+
* that don't parse as a PID (including the UUID fallback Gradle uses when the PID
81+
* is unavailable).
82+
* - **Java 8 compatible**: uses `kill`/`taskkill` via [ProcessBuilder] instead of
83+
* `ProcessHandle` (Java 9+) because build logic targets JVM 1.8.
84+
*
85+
* [1]: https://github.com/gradle/gradle/blob/43b381d88/testing/internal-distribution-testing/src/main/groovy/org/gradle/integtests/fixtures/daemon/DaemonLogsAnalyzer.groovy
86+
*/
87+
private fun stopDaemons() {
88+
val daemonDir = File(testKitDir, "daemon")
89+
if (!daemonDir.exists()) return
90+
91+
daemonDir.walkTopDown()
92+
.filter { it.isFile && it.name.endsWith(".out.log") && !it.name.startsWith("hs_err") }
93+
.forEach { logFile ->
94+
val pid = logFile.nameWithoutExtension // daemon-12345.out
95+
.removeSuffix(".out") // daemon-12345
96+
.removePrefix("daemon-") // 12345
97+
.toLongOrNull() ?: return@forEach // skip UUIDs / unparseable names
98+
99+
val isWindows = System.getProperty("os.name").lowercase().contains("win")
100+
val killProcess = if (isWindows) {
101+
ProcessBuilder("taskkill", "/F", "/PID", pid.toString())
102+
} else {
103+
ProcessBuilder("kill", pid.toString())
104+
}
105+
try {
106+
val process = killProcess.redirectErrorStream(true).start()
107+
process.waitFor(5, java.util.concurrent.TimeUnit.SECONDS)
108+
} catch (_: Exception) {
109+
// best effort — daemon may already be stopped
110+
}
111+
}
112+
}
113+
43114
/**
44115
* Adds a subproject to the build.
45116
* Updates settings.gradle and creates the build script for the subproject.

communication/gradle.lockfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,7 @@ org.slf4j:slf4j-simple:2.0.17=spotbugsSlf4j
103103
org.snakeyaml:snakeyaml-engine:2.9=runtimeClasspath,testRuntimeClasspath
104104
org.spockframework:spock-bom:2.4-groovy-3.0=testCompileClasspath,testRuntimeClasspath
105105
org.spockframework:spock-core:2.4-groovy-3.0=testCompileClasspath,testRuntimeClasspath
106+
org.tabletest:tabletest-junit:1.2.1=testCompileClasspath,testRuntimeClasspath
107+
org.tabletest:tabletest-parser:1.2.0=testCompileClasspath,testRuntimeClasspath
106108
org.xmlresolver:xmlresolver:5.3.3=spotbugs
107109
empty=annotationProcessor,spotbugsPlugins,testAnnotationProcessor

dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/Caching.java renamed to communication/src/main/java/datadog/communication/serialization/Caching.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package datadog.trace.common.writer.ddagent;
1+
package datadog.communication.serialization;
22

33
import java.util.Arrays;
44

dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/GenerationalUtf8Cache.java renamed to communication/src/main/java/datadog/communication/serialization/GenerationalUtf8Cache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package datadog.trace.common.writer.ddagent;
1+
package datadog.communication.serialization;
22

3-
import datadog.communication.serialization.EncodingCache;
43
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
54
import java.nio.charset.StandardCharsets;
65

dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/SimpleUtf8Cache.java renamed to communication/src/main/java/datadog/communication/serialization/SimpleUtf8Cache.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package datadog.trace.common.writer.ddagent;
1+
package datadog.communication.serialization;
22

3-
import datadog.communication.serialization.EncodingCache;
43
import java.nio.charset.StandardCharsets;
54

65
/**

dd-trace-core/src/test/java/datadog/trace/common/writer/ddagent/CachingTest.java renamed to communication/src/test/java/datadog/communication/serialization/CachingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package datadog.trace.common.writer.ddagent;
1+
package datadog.communication.serialization;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;

0 commit comments

Comments
 (0)