-
Notifications
You must be signed in to change notification settings - Fork 362
Make dd-trace-java.muzzle reports additional JVM data in test task inputs
#12631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gh-worker-dd-mergequeue-cf854d
merged 4 commits into
master
from
bdu/muzzle-jvm-cache-inputs
Sep 25, 2026
+239
−8
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
buildSrc/src/test/kotlin/datadog/gradle/plugin/muzzle/MuzzleJvmCacheInputsTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| package datadog.gradle.plugin.muzzle | ||
|
|
||
| import org.assertj.core.api.Assertions.assertThat | ||
| import org.gradle.testkit.runner.TaskOutcome | ||
| import org.gradle.testkit.runner.TaskOutcome.FROM_CACHE | ||
| import org.gradle.testkit.runner.TaskOutcome.SKIPPED | ||
| import org.gradle.testkit.runner.TaskOutcome.SUCCESS | ||
| import org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE | ||
| import org.junit.jupiter.api.Test | ||
| import org.junit.jupiter.params.ParameterizedTest | ||
| import org.junit.jupiter.params.provider.ValueSource | ||
|
|
||
| class MuzzleJvmCacheInputsTest : MuzzlePluginTestFixture() { | ||
| @ParameterizedTest | ||
| @ValueSource(strings = ["coreJdk", "library", "fallback"]) | ||
| fun `only core JDK checks fingerprint the daemon JVM`(check: String) { | ||
| val repo = createMavenRepoFixture() | ||
| repo.publishVersions("com.example.test", "demo-lib", listOf("1.0.0")) | ||
| val directive = when (check) { | ||
| "coreJdk" -> "muzzle { pass { coreJdk() } }" | ||
| "library" -> """ | ||
| muzzle { pass { | ||
| group = "com.example.test" | ||
| module = "demo-lib" | ||
| versions = "[1.0.0,2.0.0)" | ||
| } } | ||
| """ | ||
| else -> "" | ||
| } | ||
| writeProject( | ||
| """ | ||
| plugins { | ||
| id("java") | ||
| id("dd-trace-java.muzzle") | ||
| } | ||
|
|
||
| repositories { maven { url = uri("${repo.repoUrl}") } } | ||
|
|
||
| $directive | ||
|
|
||
| // Simulate a changed daemon runtime without requiring several installed JDKs. | ||
| val changedField = providers.gradleProperty("changedJvmField").orNull | ||
| if (changedField != null) { | ||
| val original = System.getProperty(changedField) | ||
| System.setProperty(changedField, "different-runtime") | ||
| gradle.buildFinished { System.setProperty(changedField, original) } | ||
| } | ||
| """ | ||
| ) | ||
| val taskName = when (check) { | ||
| "coreJdk" -> "muzzle-AssertPass-core-jdk" | ||
| "library" -> "muzzle-AssertPass-com.example.test-demo-lib-1.0.0" | ||
| else -> "muzzle" | ||
| } | ||
| assertCacheTracks( | ||
| listOf("java.vendor", "java.runtime.version", "java.vm.version", "os.name", "os.arch"), | ||
| taskName, | ||
| if (check == "coreJdk") SUCCESS else UP_TO_DATE, | ||
| mapOf("MAVEN_REPOSITORY_PROXY" to repo.repoUrl), | ||
| ) | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = ["coreJdk", "library"]) | ||
| fun `versioned check cache follows the launcher used by the isolated worker`(check: String) { | ||
| val repo = createMavenRepoFixture() | ||
| repo.publishVersions("com.example.test", "demo-lib", listOf("1.0.0")) | ||
| val taskName = if (check == "coreJdk") { | ||
| "muzzle-AssertPass-core-jdk" | ||
| } else { | ||
| "muzzle-AssertPass-com.example.test-demo-lib-1.0.0" | ||
| } | ||
| val directive = if (check == "coreJdk") { | ||
| "coreJdk(JavaVersion.current().majorVersion)" | ||
| } else { | ||
| """ | ||
| group = "com.example.test" | ||
| module = "demo-lib" | ||
| versions = "[1.0.0,2.0.0)" | ||
| javaVersion = JavaVersion.current().majorVersion | ||
| """ | ||
| } | ||
| writeProject( | ||
| """ | ||
| import datadog.gradle.plugin.muzzle.tasks.MuzzleTask | ||
| import org.gradle.jvm.toolchain.JavaInstallationMetadata | ||
| import org.gradle.jvm.toolchain.JavaLauncher | ||
|
|
||
| plugins { | ||
| id("java") | ||
| id("dd-trace-java.muzzle") | ||
| } | ||
|
|
||
| repositories { maven { url = uri("${repo.repoUrl}") } } | ||
|
|
||
| muzzle { pass { $directive } } | ||
|
|
||
| // Keep the executable and major version fixed to isolate each additional input. | ||
| class SelectedLauncher( | ||
| private val delegate: JavaLauncher, | ||
| private val changedField: String, | ||
| ) : JavaLauncher by delegate { | ||
| override fun getMetadata(): JavaInstallationMetadata = | ||
| object : JavaInstallationMetadata by delegate.metadata { | ||
| override fun getVendor() = | ||
| if (changedField == "vendor") "different-vendor" else delegate.metadata.vendor | ||
| override fun getJavaRuntimeVersion() = | ||
| if (changedField == "runtimeVersion") "different-runtime" else delegate.metadata.javaRuntimeVersion | ||
| override fun getJvmVersion() = | ||
| if (changedField == "vmVersion") "different-vm" else delegate.metadata.jvmVersion | ||
| } | ||
| } | ||
|
|
||
| val changedField = providers.gradleProperty("changedJvmField").orNull | ||
| if (changedField?.startsWith("os.") == true) { | ||
| val original = System.getProperty(changedField) | ||
| System.setProperty(changedField, "different-platform") | ||
| gradle.buildFinished { System.setProperty(changedField, original) } | ||
| } | ||
| val launcher = javaToolchains.launcherFor {} | ||
| tasks.withType<MuzzleTask>().configureEach { | ||
| if (name == "$taskName" && changedField != null) { | ||
| javaLauncher.set(launcher.map { SelectedLauncher(it, changedField) }) | ||
| } | ||
| } | ||
| """ | ||
| ) | ||
| assertCacheTracks( | ||
| listOf("vendor", "runtimeVersion", "vmVersion", "os.name", "os.arch"), | ||
| taskName, | ||
| env = mapOf("MAVEN_REPOSITORY_PROXY" to repo.repoUrl), | ||
| ) | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = ["--dry-run", "-PskipMuzzle"]) | ||
| fun `skipped core JDK checks do not resolve the toolchain`(argument: String) { | ||
| writeProject( | ||
| """ | ||
| import datadog.gradle.plugin.muzzle.tasks.MuzzleTask | ||
|
|
||
| plugins { | ||
| id("java") | ||
| id("dd-trace-java.muzzle") | ||
| } | ||
|
|
||
| muzzle { pass { coreJdk("999") } } | ||
|
|
||
| tasks.withType<MuzzleTask>().configureEach { | ||
| onlyIf { !providers.gradleProperty("skipMuzzle").isPresent } | ||
| } | ||
| """ | ||
| ) | ||
| writeFile("gradle.properties", "org.gradle.java.installations.auto-download=false") | ||
| val result = run("muzzle", argument) | ||
| assertThat(result.output).contains("BUILD SUCCESSFUL") | ||
| if (argument == "-PskipMuzzle") { | ||
| assertThat(result.task(":dd-java-agent:instrumentation:demo:muzzle-AssertPass-core-jdk")?.outcome) | ||
| .isEqualTo(SKIPPED) | ||
| } | ||
| } | ||
|
|
||
| private fun assertCacheTracks( | ||
| fields: List<String>, | ||
| taskName: String = "muzzle-AssertPass-core-jdk", | ||
| changedOutcome: TaskOutcome = SUCCESS, | ||
| env: Map<String, String> = emptyMap(), | ||
| ) { | ||
| writeFile("settings.gradle.kts", "buildCache { local { directory = file(\"task-cache\") } }", append = true) | ||
| writeNoopScanPlugin() | ||
| val task = ":dd-java-agent:instrumentation:demo:$taskName" | ||
| val first = run("muzzle", "--build-cache", env = env) | ||
| assertThat(first.task(task)?.outcome).describedAs(first.output).isEqualTo(SUCCESS) | ||
|
|
||
| val unchanged = run("muzzle", "--build-cache", env = env) | ||
| assertThat(unchanged.task(task)?.outcome).describedAs(unchanged.output).isEqualTo(UP_TO_DATE) | ||
|
|
||
| for (field in fields) { | ||
| val restored = run("clean", "muzzle", "--build-cache", env = env) | ||
| assertThat(restored.task(task)?.outcome).describedAs(restored.output).isEqualTo(FROM_CACHE) | ||
|
|
||
| val changed = run("muzzle", "--build-cache", "-PchangedJvmField=$field", env = env) | ||
| assertThat(changed.task(task)?.outcome).describedAs(changed.output).isEqualTo(changedOutcome) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.