Skip to content

Commit d33af37

Browse files
Merge branch 'master' into alexeyk/support-span-events-for-v1
2 parents c31977c + 693988c commit d33af37

88 files changed

Lines changed: 5003 additions & 1143 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.

‎.github/workflows/add-release-to-cloudfoundry.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
git add --all
5050
git commit -m "chore: Add version ${{ steps.get-release-version.outputs.VERSION }} to Cloud Foundry"
5151
- name: Push changes
52-
uses: DataDog/commit-headless@567f7eedac58750aa573f48fd60cfe478abc65bd # action/v3.3.0
52+
uses: DataDog/commit-headless@2801f6e08acb3a69b6c4d7b0d5deef27c1a15bc7 # action/v3.3.1
5353
with:
5454
branch: cloudfoundry
5555
command: push

‎.github/workflows/analyze-changes.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
${{ runner.os }}-gradle-
3131
3232
- name: Initialize CodeQL
33-
uses: github/codeql-action/init@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
33+
uses: github/codeql-action/init@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
3434
with:
3535
languages: 'java'
3636
build-mode: 'manual'
@@ -43,7 +43,7 @@ jobs:
4343
./gradlew clean :dd-java-agent:shadowJar --build-cache --parallel --stacktrace --no-daemon --max-workers=4
4444
4545
- name: Perform CodeQL Analysis and upload results to GitHub Security tab
46-
uses: github/codeql-action/analyze@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
46+
uses: github/codeql-action/analyze@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
4747

4848
trivy:
4949
name: Analyze changes with Trivy
@@ -102,7 +102,7 @@ jobs:
102102
TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db
103103

104104
- name: Upload Trivy scan results to GitHub Security tab
105-
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
105+
uses: github/codeql-action/upload-sarif@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
106106
if: always()
107107
with:
108108
sarif_file: 'trivy-results.sarif'

‎.github/workflows/create-release-branch.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
git commit -m "chore: Pin system-tests for release branch" .github/workflows/run-system-tests.yaml .gitlab-ci.yml
129129
130130
- name: Push changes
131-
uses: DataDog/commit-headless@567f7eedac58750aa573f48fd60cfe478abc65bd # action/v3.3.0
131+
uses: DataDog/commit-headless@2801f6e08acb3a69b6c4d7b0d5deef27c1a15bc7 # action/v3.3.1
132132
with:
133133
token: "${{ steps.octo-sts.outputs.token }}"
134134
branch: "${{ steps.define-pin-branch.outputs.branch }}"

‎.github/workflows/update-gradle-dependencies.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ jobs:
104104
105105
- name: Push core changes
106106
if: steps.check-core-changes.outputs.commit_changes == 'true'
107-
uses: DataDog/commit-headless@567f7eedac58750aa573f48fd60cfe478abc65bd # action/v3.3.0
107+
uses: DataDog/commit-headless@2801f6e08acb3a69b6c4d7b0d5deef27c1a15bc7 # action/v3.3.1
108108
with:
109109
token: "${{ steps.octo-sts.outputs.token }}"
110110
branch: "${{ steps.define-branches.outputs.core_branch }}"
@@ -164,7 +164,7 @@ jobs:
164164
165165
- name: Push instrumentation changes
166166
if: steps.check-instrumentation-changes.outputs.commit_changes == 'true'
167-
uses: DataDog/commit-headless@567f7eedac58750aa573f48fd60cfe478abc65bd # action/v3.3.0
167+
uses: DataDog/commit-headless@2801f6e08acb3a69b6c4d7b0d5deef27c1a15bc7 # action/v3.3.1
168168
with:
169169
token: "${{ steps.octo-sts.outputs.token }}"
170170
branch: "${{ steps.define-branches.outputs.instrumentation_branch }}"

‎.github/workflows/update-jmxfetch-submodule.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
4646
git commit -m "feat(ci): Update agent-jmxfetch submodule" dd-java-agent/agent-jmxfetch/integrations-core
4747
- name: Push changes
48-
uses: DataDog/commit-headless@567f7eedac58750aa573f48fd60cfe478abc65bd # action/v3.3.0
48+
uses: DataDog/commit-headless@2801f6e08acb3a69b6c4d7b0d5deef27c1a15bc7 # action/v3.3.1
4949
if: steps.check-changes.outputs.commit_changes == 'true'
5050
with:
5151
token: "${{ steps.octo-sts.outputs.token }}"

‎.github/workflows/update-smoke-test-latest-versions.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
150150
- name: Push changes
151151
if: steps.check-changes.outputs.has_changes == 'true'
152-
uses: DataDog/commit-headless@567f7eedac58750aa573f48fd60cfe478abc65bd # action/v3.3.0
152+
uses: DataDog/commit-headless@2801f6e08acb3a69b6c4d7b0d5deef27c1a15bc7 # action/v3.3.1
153153
with:
154154
token: "${{ steps.octo-sts.outputs.token }}"
155155
branch: "${{ steps.define-branch.outputs.branch }}"

‎buildSrc/build.gradle.kts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ dependencies {
109109
implementation("com.fasterxml.jackson.core:jackson-core")
110110

111111
compileOnly(libs.develocity)
112+
113+
testImplementation("me.champeau.jmh:jmh-gradle-plugin:0.7.3")
112114
}
113115

114116
tasks.compileKotlin {

‎buildSrc/src/main/kotlin/datadog/gradle/plugin/testJvmConstraints/TestJvmConstraintsPlugin.kt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
1313

1414
class TestJvmConstraintsPlugin : Plugin<Project> {
1515
override fun apply(project: Project) {
16+
if (project.extensions.findByName(TEST_JVM_CONSTRAINTS) != null) {
17+
return
18+
}
19+
1620
project.pluginManager.apply(JavaPlugin::class.java)
1721

1822
val projectExtension = project.extensions.create<TestJvmConstraintsExtension>(TEST_JVM_CONSTRAINTS)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import datadog.gradle.plugin.testJvmConstraints.TestJvmSpec
2+
import org.gradle.api.provider.ListProperty
3+
import org.gradle.api.provider.Property
4+
5+
/*
6+
* Applies JMH with defaults from `-PtestJvm` and `-Pjmh.*`. Modules can override them in their
7+
* `jmh {}` block.
8+
*/
9+
// This plugin is produced by the same buildSrc build, so it cannot be resolved from this
10+
// precompiled script's `plugins {}` block. Apply it by ID once both plugins are available at runtime.
11+
pluginManager.apply("dd-trace-java.test-jvm-constraints")
12+
13+
// JMH is versioned in the root build with `apply false`, not added to buildSrc's implementation
14+
// classpath. Applying it by ID here reuses the consuming build's plugin classpath.
15+
pluginManager.apply("me.champeau.jmh")
16+
17+
val testJvmSpec = TestJvmSpec(project)
18+
val jmh = extensions.getByName("jmh")
19+
20+
21+
jmhProperty<String>("getJvm").convention(testJvmSpec.javaTestLauncher.map { it.executablePath.asFile.absolutePath })
22+
providers.gradleProperty("jmh.includes").map(::commaSeparated).let {
23+
if (it.isPresent) {
24+
jmhListProperty("getIncludes").convention(it.map { includes -> listOf(includes.joinToString("|")) })
25+
}
26+
}
27+
providers.gradleProperty("jmh.profilers").map(::commaSeparated).let {
28+
if (it.isPresent) {
29+
jmhListProperty("getProfilers").convention(it)
30+
}
31+
}
32+
providers.gradleProperty("jmh.forks").map(String::toInt).let {
33+
if (it.isPresent) {
34+
jmhProperty<Int>("getFork").convention(it)
35+
}
36+
}
37+
providers.gradleProperty("jmh.threads").map(String::toInt).let {
38+
if (it.isPresent) {
39+
jmhProperty<Int>("getThreads").convention(it)
40+
}
41+
}
42+
43+
// JMH types are not on buildSrc's compile classpath, so access its extension through Gradle's public
44+
// property types.
45+
@Suppress("UNCHECKED_CAST")
46+
fun <T : Any> jmhProperty(getterName: String): Property<T> =
47+
jmh.javaClass.getMethod(getterName).invoke(jmh) as Property<T>
48+
49+
@Suppress("UNCHECKED_CAST")
50+
fun jmhListProperty(getterName: String): ListProperty<String> =
51+
jmh.javaClass.getMethod(getterName).invoke(jmh) as ListProperty<String>
52+
53+
fun commaSeparated(value: String): List<String> =
54+
value.split(",").map(String::trim).filter(String::isNotEmpty)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package datadog.gradle.plugin.jmh
2+
3+
import datadog.gradle.plugin.testJvmConstraints.TestJvmConstraintsExtension.Companion.TEST_JVM_CONSTRAINTS
4+
import datadog.gradle.plugin.testJvmConstraints.TestJvmSpec
5+
import me.champeau.jmh.JmhParameters
6+
import org.assertj.core.api.Assertions.assertThat
7+
import org.gradle.api.JavaVersion
8+
import org.gradle.testfixtures.ProjectBuilder
9+
import org.junit.jupiter.api.Test
10+
11+
class JmhConventionsPluginTest {
12+
@Test
13+
fun `plugin applies jmh and test-jvm-constraints`() {
14+
val project = ProjectBuilder.builder().build()
15+
16+
project.pluginManager.apply("dd-trace-java.jmh-conventions")
17+
18+
assertThat(project.plugins.hasPlugin("me.champeau.jmh")).isTrue()
19+
assertThat(project.extensions.findByName(TEST_JVM_CONSTRAINTS)).isNotNull()
20+
}
21+
22+
@Test
23+
fun `plugin provides the test jvm as an overridable default`() {
24+
val propertyName = "org.gradle.project.${TestJvmSpec.TEST_JVM}"
25+
val previousValue = System.setProperty(propertyName, JavaVersion.current().majorVersion)
26+
27+
try {
28+
val project = ProjectBuilder.builder().build()
29+
30+
project.pluginManager.apply("dd-trace-java.jmh-conventions")
31+
32+
val jmh = project.extensions.getByType(JmhParameters::class.java)
33+
val expectedExecutable = TestJvmSpec(project).javaTestLauncher.get().executablePath.asFile.absolutePath
34+
assertThat(jmh.jvm.get()).isEqualTo(expectedExecutable)
35+
36+
jmh.jvm.set("module-jvm")
37+
assertThat(jmh.jvm.get()).isEqualTo("module-jvm")
38+
} finally {
39+
if (previousValue == null) {
40+
System.clearProperty(propertyName)
41+
} else {
42+
System.setProperty(propertyName, previousValue)
43+
}
44+
}
45+
}
46+
47+
@Test
48+
fun `plugin provides jmh project properties as defaults`() {
49+
withGradleProperties(
50+
"jmh.includes" to "FooBenchmark, BarBenchmark",
51+
"jmh.profilers" to "stack, gc",
52+
"jmh.forks" to "1",
53+
"jmh.threads" to "1",
54+
) {
55+
val project = ProjectBuilder.builder().build()
56+
57+
project.pluginManager.apply("dd-trace-java.jmh-conventions")
58+
59+
val jmh = project.extensions.getByType(JmhParameters::class.java)
60+
assertThat(jmh.includes.get()).containsExactly("FooBenchmark|BarBenchmark")
61+
assertThat(jmh.profilers.get()).containsExactly("stack", "gc")
62+
assertThat(jmh.fork.get()).isEqualTo(1)
63+
assertThat(jmh.threads.get()).isEqualTo(1)
64+
}
65+
}
66+
67+
@Test
68+
fun `jmh properties are absent when the project properties are not set`() {
69+
val project = ProjectBuilder.builder().build()
70+
71+
project.pluginManager.apply("dd-trace-java.jmh-conventions")
72+
73+
val jmh = project.extensions.getByType(JmhParameters::class.java)
74+
assertThat(jmh.includes.get()).isEmpty()
75+
assertThat(jmh.profilers.get()).isEmpty()
76+
assertThat(jmh.fork.isPresent).isFalse()
77+
assertThat(jmh.threads.isPresent).isFalse()
78+
}
79+
80+
@Test
81+
fun `module jmh settings override project property defaults`() {
82+
withGradleProperties(
83+
"jmh.profilers" to "async",
84+
"jmh.forks" to "1",
85+
) {
86+
val project = ProjectBuilder.builder().build()
87+
88+
project.pluginManager.apply("dd-trace-java.jmh-conventions")
89+
90+
val jmh = project.extensions.getByType(JmhParameters::class.java)
91+
jmh.profilers.set(listOf("gc"))
92+
jmh.fork.set(4)
93+
94+
assertThat(jmh.profilers.get()).containsExactly("gc")
95+
assertThat(jmh.fork.get()).isEqualTo(4)
96+
}
97+
}
98+
99+
@Test
100+
fun `applying test-jvm-constraints before jmh-conventions is idempotent`() {
101+
val project = ProjectBuilder.builder().build()
102+
103+
project.pluginManager.apply("dd-trace-java.test-jvm-constraints")
104+
project.pluginManager.apply("dd-trace-java.jmh-conventions")
105+
106+
assertThat(project.extensions.findByName(TEST_JVM_CONSTRAINTS)).isNotNull()
107+
}
108+
109+
private fun withGradleProperties(vararg properties: Pair<String, String>, assertions: () -> Unit) {
110+
val systemProperties = properties.associate { (name, value) -> "org.gradle.project.$name" to value }
111+
val previousValues = systemProperties.keys.associateWith(System::getProperty)
112+
113+
try {
114+
systemProperties.forEach(System::setProperty)
115+
assertions()
116+
} finally {
117+
previousValues.forEach { (name, value) ->
118+
if (value == null) {
119+
System.clearProperty(name)
120+
} else {
121+
System.setProperty(name, value)
122+
}
123+
}
124+
}
125+
}
126+
}

0 commit comments

Comments
 (0)