Skip to content

Commit f15cec4

Browse files
authored
Merge branch 'master' into cecile/otelmetrics13
2 parents eab6ec2 + 5db793a commit f15cec4

File tree

183 files changed

+2396
-1456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+2396
-1456
lines changed

.gitlab/benchmarks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ check-big-regressions:
7171
needs:
7272
- job: benchmarks-startup
7373
artifacts: true
74-
- job: benchmarks-load
74+
- job: benchmarks-dacapo
7575
artifacts: true
7676
when: on_success
7777
tags: ["arch:amd64"]
@@ -86,7 +86,7 @@ check-big-regressions:
8686
script:
8787
- !reference [ .benchmarks, script ]
8888
- |
89-
for benchmarkType in startup load; do
89+
for benchmarkType in startup dacapo; do
9090
find "$ARTIFACTS_DIR/$benchmarkType" -name "benchmark-baseline.json" -o -name "benchmark-candidate.json" | while read file; do
9191
relpath="${file#$ARTIFACTS_DIR/$benchmarkType/}"
9292
prefix="${relpath%/benchmark-*}" # Remove the trailing /benchmark-(baseline|candidate).json

buildSrc/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ apply {
4949
from("$rootDir/../gradle/repositories.gradle")
5050
}
5151

52+
repositories {
53+
gradlePluginPortal()
54+
}
55+
5256
dependencies {
5357
implementation(gradleApi())
5458
implementation(localGroovy())
@@ -69,6 +73,8 @@ dependencies {
6973
implementation("com.fasterxml.jackson.core:jackson-databind")
7074
implementation("com.fasterxml.jackson.core:jackson-annotations")
7175
implementation("com.fasterxml.jackson.core:jackson-core")
76+
77+
compileOnly(libs.develocity)
7278
}
7379

7480
tasks.compileKotlin {

buildSrc/src/main/kotlin/datadog.ci-jobs.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import datadog.gradle.plugin.ci.findAffectedTaskPath
8+
import org.gradle.api.tasks.testing.Test
89
import java.io.File
910
import kotlin.math.abs
1011

@@ -20,6 +21,15 @@ allprojects {
2021
val currentTaskPartition = abs(project.path.hashCode() % taskPartitionCount.toInt())
2122
extra.set("activePartition", currentTaskPartition == taskPartition.toInt())
2223
}
24+
25+
// Disable test tasks if not in active partition
26+
val activePartitionProvider = providers.provider {
27+
project.extra.properties["activePartition"] as? Boolean ?: true
28+
}
29+
30+
tasks.withType<Test>().configureEach {
31+
enabled = activePartitionProvider.get()
32+
}
2333
}
2434

2535
fun relativeToGitRoot(f: File): File {
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import org.gradle.api.tasks.testing.Test
2+
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions
3+
import org.gradle.api.services.BuildService
4+
import org.gradle.api.services.BuildServiceParameters
5+
import org.gradle.testing.base.TestingExtension
6+
import org.gradle.api.plugins.jvm.JvmTestSuite
7+
import java.time.Duration
8+
import java.time.temporal.ChronoUnit
9+
10+
val isTestingInstrumentation = providers.provider {
11+
project.findProperty("testingInstrumentation") as? Boolean ?: false
12+
}
13+
14+
// Need concrete implementation of BuildService in Kotlin
15+
abstract class ForkedTestLimit : BuildService<BuildServiceParameters.None>
16+
// Forked tests will fail with OOM if the memory is set too high. Gitlab allows at least a limit of 3.
17+
val forkedTestsMemoryLimit = 3
18+
19+
val forkedTestLimit = gradle.sharedServices.registerIfAbsent("forkedTestLimit", ForkedTestLimit::class.java) {
20+
maxParallelUsages.set(forkedTestsMemoryLimit)
21+
}
22+
23+
extensions.findByType<TestingExtension>()?.apply {
24+
suites.withType<JvmTestSuite>().configureEach {
25+
// Use JUnit 5 to run tests
26+
useJUnitJupiter()
27+
}
28+
}
29+
30+
// Use lazy providers to avoid evaluating the property until it is needed
31+
val skipTestsProvider = rootProject.providers.gradleProperty("skipTests")
32+
val skipForkedTestsProvider = rootProject.providers.gradleProperty("skipForkedTests")
33+
val skipFlakyTestsProvider = rootProject.providers.gradleProperty("skipFlakyTests")
34+
val runFlakyTestsProvider = rootProject.providers.gradleProperty("runFlakyTests")
35+
36+
// Go through the Test tasks and configure them
37+
tasks.withType<Test>().configureEach {
38+
// Disable all tests if skipTests property was specified
39+
onlyIf("skipTests are undefined or false") { !skipTestsProvider.isPresent }
40+
41+
// Enable force rerun of tests with -Prerun.tests.${project.name}
42+
outputs.upToDateWhen {
43+
!rootProject.providers.gradleProperty("rerun.tests.${project.name}").isPresent
44+
}
45+
46+
// Avoid executing classes used to test testing frameworks instrumentation
47+
if (isTestingInstrumentation.get()) {
48+
exclude("**/TestAssumption*", "**/TestSuiteSetUpAssumption*")
49+
exclude("**/TestDisableTestTrace*")
50+
exclude("**/TestError*")
51+
exclude("**/TestFactory*")
52+
exclude("**/TestFailed*")
53+
exclude("**/TestFailedWithSuccessPercentage*")
54+
exclude("**/TestInheritance*", "**/BaseTestInheritance*")
55+
exclude("**/TestParameterized*")
56+
exclude("**/TestRepeated*")
57+
exclude("**/TestSkipped*")
58+
exclude("**/TestSkippedClass*")
59+
exclude("**/TestSucceed*")
60+
exclude("**/TestTemplate*")
61+
exclude("**/TestUnskippable*")
62+
exclude("**/TestWithSetup*")
63+
}
64+
65+
// Split up tests that want to run forked in their own separate JVM for generated tasks
66+
if (name.startsWith("forkedTest") || name.endsWith("ForkedTest")) {
67+
setExcludes(emptyList())
68+
setIncludes(listOf("**/*ForkedTest*"))
69+
forkEvery = 1
70+
// Limit the number of concurrent forked tests
71+
usesService(forkedTestLimit)
72+
onlyIf("skipForkedTests are undefined or false") { !skipForkedTestsProvider.isPresent }
73+
} else {
74+
exclude("**/*ForkedTest*")
75+
}
76+
77+
// Set test timeout for 20 minutes. Default job timeout is 1h (configured on CI level).
78+
timeout.set(Duration.of(20, ChronoUnit.MINUTES))
79+
}
80+
81+
// Register a task "allTests" that depends on all non-latest and non-traceAgentTest Test tasks.
82+
// This is used when we only want to run the 'main' test sets.
83+
tasks.register("allTests") {
84+
dependsOn(tasks.withType<Test>().matching { testTask ->
85+
!testTask.name.contains("latest", ignoreCase = true) && testTask.name != "traceAgentTest"
86+
})
87+
}
88+
89+
// Register a task "allLatestDepTests" that depends on all Test tasks whose names include 'latest'.
90+
// This is used when we want to run tests against the latest dependency versions.
91+
tasks.register("allLatestDepTests") {
92+
dependsOn(tasks.withType<Test>().matching { testTask ->
93+
!testTask.name.contains("latest", ignoreCase = true)
94+
})
95+
}
96+
97+
// Make the 'check' task depend on all Test tasks in the project.
98+
// This means that when running the 'check' task, all Test tasks will run as well.
99+
tasks.named("check") {
100+
dependsOn(tasks.withType<Test>())
101+
}
102+
103+
tasks.withType<Test>().configureEach {
104+
// Flaky tests management for JUnit 5
105+
(options as? JUnitPlatformOptions)?.apply {
106+
if (skipFlakyTestsProvider.isPresent) {
107+
excludeTags("flaky")
108+
} else if (runFlakyTestsProvider.isPresent) {
109+
includeTags("flaky")
110+
}
111+
}
112+
113+
// Set system property flag that is checked from tests to determine if they should be skipped or run
114+
if (skipFlakyTestsProvider.isPresent) {
115+
jvmArgs("-Drun.flaky.tests=false")
116+
} else if (runFlakyTestsProvider.isPresent) {
117+
jvmArgs("-Drun.flaky.tests=true")
118+
}
119+
}
120+
121+
tasks.withType<Test>().configureEach {
122+
// https://docs.gradle.com/develocity/flaky-test-detection/
123+
// https://docs.gradle.com/develocity/gradle-plugin/current/#test_retry
124+
develocity.testRetry {
125+
if (providers.environmentVariable("CI").isPresent()) {
126+
maxRetries = 3
127+
}
128+
}
129+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import datadog.gradle.plugin.testJvmConstraints.ProvideJvmArgsOnJvmLauncherVersion
2+
import datadog.gradle.plugin.testJvmConstraints.TestJvmConstraintsExtension
3+
import datadog.gradle.plugin.testJvmConstraints.TestJvmConstraintsExtension.Companion.TEST_JVM_CONSTRAINTS
4+
import datadog.gradle.plugin.testJvmConstraints.TestJvmSpec
5+
import datadog.gradle.plugin.testJvmConstraints.isJavaVersionAllowed
6+
import datadog.gradle.plugin.testJvmConstraints.isTestJvmAllowed
7+
8+
plugins {
9+
java
10+
}
11+
12+
val projectExtension = extensions.create<TestJvmConstraintsExtension>(TEST_JVM_CONSTRAINTS)
13+
14+
val testJvmSpec = TestJvmSpec(project)
15+
16+
tasks.withType<Test>().configureEach {
17+
if (extensions.findByName(TEST_JVM_CONSTRAINTS) != null) {
18+
return@configureEach
19+
}
20+
21+
inputs.property("testJvm", testJvmSpec.testJvmProperty).optional(true)
22+
23+
val taskExtension = project.objects.newInstance<TestJvmConstraintsExtension>().also {
24+
configureConventions(it, projectExtension)
25+
}
26+
27+
inputs.property("$TEST_JVM_CONSTRAINTS.allowReflectiveAccessToJdk", taskExtension.allowReflectiveAccessToJdk).optional(true)
28+
inputs.property("$TEST_JVM_CONSTRAINTS.excludeJdk", taskExtension.excludeJdk)
29+
inputs.property("$TEST_JVM_CONSTRAINTS.includeJdk", taskExtension.includeJdk)
30+
inputs.property("$TEST_JVM_CONSTRAINTS.forceJdk", taskExtension.forceJdk)
31+
inputs.property("$TEST_JVM_CONSTRAINTS.minJavaVersion", taskExtension.minJavaVersion).optional(true)
32+
inputs.property("$TEST_JVM_CONSTRAINTS.maxJavaVersion", taskExtension.maxJavaVersion).optional(true)
33+
34+
extensions.add(TEST_JVM_CONSTRAINTS, taskExtension)
35+
36+
configureTestJvm(taskExtension)
37+
}
38+
39+
/**
40+
* Provide arguments if condition is met.
41+
*/
42+
fun Test.conditionalJvmArgs(
43+
applyFromVersion: JavaVersion,
44+
jvmArgsToApply: List<String>,
45+
additionalCondition: Provider<Boolean> = project.providers.provider { true }
46+
) {
47+
jvmArgumentProviders.add(
48+
ProvideJvmArgsOnJvmLauncherVersion(
49+
this,
50+
applyFromVersion,
51+
jvmArgsToApply,
52+
additionalCondition
53+
)
54+
)
55+
}
56+
57+
/**
58+
* Configure the jvm launcher of the test task and ensure the test task
59+
* can be run with the test task launcher.
60+
*/
61+
private fun Test.configureTestJvm(extension: TestJvmConstraintsExtension) {
62+
if (testJvmSpec.javaTestLauncher.isPresent) {
63+
javaLauncher = testJvmSpec.javaTestLauncher
64+
onlyIf("Allowed or forced JDK") {
65+
extension.isTestJvmAllowed(testJvmSpec)
66+
}
67+
} else {
68+
onlyIf("Is current Daemon JVM allowed") {
69+
extension.isJavaVersionAllowed(JavaVersion.current())
70+
}
71+
}
72+
73+
// temporary workaround when using Java16+: some tests require reflective access to java.lang/java.util
74+
conditionalJvmArgs(
75+
JavaVersion.VERSION_16,
76+
listOf(
77+
"--add-opens=java.base/java.lang=ALL-UNNAMED",
78+
"--add-opens=java.base/java.util=ALL-UNNAMED"
79+
),
80+
extension.allowReflectiveAccessToJdk
81+
)
82+
}
83+
84+
// Jacoco plugin is not applied on every project
85+
pluginManager.withPlugin("org.gradle.jacoco") {
86+
tasks.withType<Test>().configureEach {
87+
// Disable jacoco for additional 'testJvm' tests to speed things up a bit
88+
if (testJvmSpec.javaTestLauncher.isPresent) {
89+
extensions.configure<JacocoTaskExtension> {
90+
isEnabled = false
91+
}
92+
}
93+
}
94+
}
95+
96+
/**
97+
* Configures the convention, this tells Gradle where to look for values.
98+
*
99+
* Currently, the extension is still configured to look at project's _extra_ properties.
100+
*/
101+
private fun Test.configureConventions(
102+
taskExtension: TestJvmConstraintsExtension,
103+
projectExtension: TestJvmConstraintsExtension
104+
) {
105+
taskExtension.minJavaVersion.convention(projectExtension.minJavaVersion
106+
.orElse(providers.provider { project.findProperty("${name}MinJavaVersionForTests") as? JavaVersion })
107+
.orElse(providers.provider { project.findProperty("minJavaVersion") as? JavaVersion })
108+
)
109+
taskExtension.maxJavaVersion.convention(projectExtension.maxJavaVersion
110+
.orElse(providers.provider { project.findProperty("${name}MaxJavaVersionForTests") as? JavaVersion })
111+
.orElse(providers.provider { project.findProperty("maxJavaVersion") as? JavaVersion })
112+
)
113+
taskExtension.forceJdk.convention(projectExtension.forceJdk
114+
.orElse(providers.provider {
115+
@Suppress("UNCHECKED_CAST")
116+
project.findProperty("forceJdk") as? List<String> ?: emptyList()
117+
})
118+
)
119+
taskExtension.excludeJdk.convention(projectExtension.excludeJdk
120+
.orElse(providers.provider {
121+
@Suppress("UNCHECKED_CAST")
122+
project.findProperty("excludeJdk") as? List<String> ?: emptyList()
123+
})
124+
)
125+
taskExtension.allowReflectiveAccessToJdk.convention(projectExtension.allowReflectiveAccessToJdk
126+
.orElse(providers.provider { project.findProperty("allowReflectiveAccessToJdk") as? Boolean })
127+
)
128+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package datadog.gradle.plugin.testJvmConstraints
2+
3+
import org.gradle.api.JavaVersion
4+
import org.gradle.api.provider.Provider
5+
import org.gradle.api.tasks.Input
6+
import org.gradle.api.tasks.Internal
7+
import org.gradle.api.tasks.Optional
8+
import org.gradle.api.tasks.testing.Test
9+
import org.gradle.process.CommandLineArgumentProvider
10+
11+
class ProvideJvmArgsOnJvmLauncherVersion(
12+
@get:Internal
13+
val test: Test,
14+
15+
@get:Input
16+
val applyFromVersion: JavaVersion,
17+
18+
@get:Input
19+
val jvmArgsToApply: List<String>,
20+
21+
@get:Input
22+
@get:Optional
23+
val additionalCondition: Provider<Boolean>
24+
) : CommandLineArgumentProvider {
25+
26+
override fun asArguments(): Iterable<String> {
27+
val launcherVersion = test.javaLauncher
28+
.map { JavaVersion.toVersion(it.metadata.languageVersion.asInt()) }
29+
.orElse(JavaVersion.current())
30+
.get()
31+
32+
return if (launcherVersion.isCompatibleWith(applyFromVersion) && additionalCondition.getOrElse(true)) {
33+
jvmArgsToApply
34+
} else {
35+
emptyList()
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)