Skip to content

Commit ffea541

Browse files
committed
chore: simpler UX to mention a slot
1 parent 41b6202 commit ffea541

File tree

3 files changed

+51
-32
lines changed

3 files changed

+51
-32
lines changed

.gitlab-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ test_published_artifacts:
420420
script:
421421
- *gitlab_base_ref_params
422422
- ./gradlew --version
423-
- ./gradlew $GRADLE_TARGET $GRADLE_PARAMS -PskipTests -PrunBuildSrcTests -PskipSpotless -PtaskPartitionCount=$NORMALIZED_NODE_TOTAL -PtaskPartition=$NORMALIZED_NODE_INDEX $GRADLE_ARGS
423+
- ./gradlew $GRADLE_TARGET $GRADLE_PARAMS -PskipTests -PrunBuildSrcTests -PskipSpotless -Pslot=$NORMALIZED_NODE_INDEX/$NORMALIZED_NODE_TOTAL $GRADLE_ARGS
424424
after_script:
425425
- *cgroup_info
426426
- source .gitlab/gitlab-utils.sh
@@ -488,7 +488,7 @@ muzzle:
488488
script:
489489
- export SKIP_BUILDSCAN="true"
490490
- ./gradlew --version
491-
- ./gradlew :runMuzzle -PtaskPartitionCount=$NORMALIZED_NODE_TOTAL -PtaskPartition=$NORMALIZED_NODE_INDEX $GRADLE_ARGS
491+
- ./gradlew :runMuzzle -Pslot=$NORMALIZED_NODE_INDEX/$NORMALIZED_NODE_TOTAL $GRADLE_ARGS
492492
after_script:
493493
- *cgroup_info
494494
- source .gitlab/gitlab-utils.sh
@@ -570,7 +570,7 @@ muzzle-dep-report:
570570
- *prepare_test_env
571571
- export GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xms$GRADLE_MEM -Xmx$GRADLE_MEM $PROFILER_COMMAND -XX:ErrorFile=/tmp/hs_err_pid%p.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp' -Ddatadog.forkedMaxHeapSize=1024M -Ddatadog.forkedMinHeapSize=128M"
572572
- ./gradlew --version
573-
- ./gradlew $GRADLE_TARGET $GRADLE_PARAMS -PtestJvm=$testJvm -PtaskPartitionCount=$NORMALIZED_NODE_TOTAL -PtaskPartition=$NORMALIZED_NODE_INDEX $GRADLE_ARGS --continue || $CONTINUE_ON_FAILURE
573+
- ./gradlew $GRADLE_TARGET $GRADLE_PARAMS -PtestJvm=$testJvm -Pslot=$NORMALIZED_NODE_INDEX/$NORMALIZED_NODE_TOTAL $GRADLE_ARGS --continue || $CONTINUE_ON_FAILURE
574574
after_script:
575575
- *restore_pretest_env
576576
- *set_datadog_api_keys

buildSrc/src/main/kotlin/datadog/gradle/plugin/ci/CIJobsExtensions.kt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,41 @@ package datadog.gradle.plugin.ci
22

33
import org.gradle.api.Project
44
import org.gradle.api.Task
5+
import org.gradle.api.provider.Provider
56
import org.gradle.kotlin.dsl.extra
7+
import kotlin.math.abs
8+
9+
/**
10+
* Determines if the current project is in the selected slot.
11+
*
12+
* The "slot" property should be provided in the format "X/Y", where X is the selected slot (1-based)
13+
* and Y is the total number of slots.
14+
*
15+
* If the "slot" property is not provided, all projects are considered to be in the selected slot.
16+
*/
17+
val Project.isInSelectedSlot: Provider<Boolean>
18+
get() = rootProject.providers.gradleProperty("slot").map { slot ->
19+
val parts = slot.split("/")
20+
if (parts.size != 2) {
21+
project.logger.warn("Invalid slot format '{}', expected 'X/Y'. Treating all projects as selected.", slot)
22+
return@map true
23+
}
24+
25+
val selectedSlot = parts[0]
26+
val totalSlots = parts[1]
27+
28+
val currentTaskPartition = abs(project.path.hashCode() % totalSlots.toInt())
29+
30+
project.logger.info(
31+
"Project {} assigned to slot {}/{}, active slot is {}",
32+
project.path,
33+
currentTaskPartition,
34+
totalSlots,
35+
selectedSlot,
36+
)
37+
38+
currentTaskPartition == selectedSlot.toInt()
39+
}.orElse(true)
640

741
/**
842
* Returns the task's path, given affected projects, if this task or its dependencies are affected by git changes.
@@ -46,9 +80,8 @@ private fun Project.createRootTask(
4680
val coverage = forceCoverage || rootProject.providers.gradleProperty("checkCoverage").isPresent
4781
tasks.register(rootTaskName) {
4882
subprojects.forEach { subproject ->
49-
val activePartition = subproject.extra.get("activePartition") as Boolean
5083
if (
51-
activePartition &&
84+
isInSelectedSlot.get() &&
5285
includePrefixes.any { subproject.path.startsWith(it) } &&
5386
!excludePrefixes.any { subproject.path.startsWith(it) }
5487
) {

buildSrc/src/main/kotlin/dd-trace-java.ci-jobs.gradle.kts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
/*
2-
* This plugin defines a set of tasks to be used in CI. These aggregate tasks support partitioning (to parallelize
3-
* jobs) with -PtaskPartitionCount and -PtaskPartition, and limiting tasks to those affected by git changes
4-
* with -PgitBaseRef.
5-
*/
6-
1+
import datadog.gradle.plugin.ci.isInSelectedSlot
72
import org.gradle.api.tasks.testing.Test
83
import java.io.File
9-
import kotlin.math.abs
104

11-
// Set up activePartition property on all projects
5+
/*
6+
* This plugin defines a set of tasks to be used in CI.
7+
*
8+
* These aggregate tasks support partitioning (to parallelize jobs) with
9+
* `-Pslot=x/y`, and limiting tasks to those affected by git changes with
10+
* `-PgitBaseRef`.
11+
*/
1212
allprojects {
13-
extra.set("activePartition", true)
14-
15-
val taskPartitionCountProvider = rootProject.providers.gradleProperty("taskPartitionCount")
16-
val taskPartitionProvider = rootProject.providers.gradleProperty("taskPartition")
17-
if (taskPartitionCountProvider.isPresent && taskPartitionProvider.isPresent) {
18-
val taskPartitionCount = taskPartitionCountProvider.get()
19-
val taskPartition = taskPartitionProvider.get()
20-
val currentTaskPartition = abs(project.path.hashCode() % taskPartitionCount.toInt())
21-
extra.set("activePartition", currentTaskPartition == taskPartition.toInt())
22-
}
23-
24-
// Disable test tasks if not in active partition
25-
val activePartitionProvider = providers.provider {
26-
project.extra.properties["activePartition"] as? Boolean ?: true
27-
}
28-
13+
// Enable tests only on the selected slot (if -Pslot=n/t is provided)
2914
tasks.withType<Test>().configureEach {
30-
enabled = activePartitionProvider.get()
15+
enabled = project.isInSelectedSlot.get()
3116
}
3217
}
3318

@@ -132,8 +117,9 @@ if (gitBaseRefProvider.isPresent) {
132117

133118
tasks.register("runMuzzle") {
134119
val muzzleSubprojects = subprojects.filter { p ->
135-
val activePartition = p.extra.get("activePartition") as Boolean
136-
activePartition && p.plugins.hasPlugin("java") && p.plugins.hasPlugin("dd-trace-java.muzzle")
120+
p.isInSelectedSlot.get()
121+
&& p.plugins.hasPlugin("java")
122+
&& p.plugins.hasPlugin("dd-trace-java.muzzle")
137123
}
138124
dependsOn(muzzleSubprojects.map { p -> "${p.path}:muzzle" })
139125
}

0 commit comments

Comments
 (0)