From fb590008381bed54415d141d3551feb384a009f9 Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Thu, 19 Nov 2026 04:50:46 -0600 Subject: [PATCH] test(emr): move the cluster shrink scenario to nightly checks (#8903) * test(emr): move the cluster shrink scenario to nightly checks --- .github/ci/prefetch-images.sh | 7 +- .github/workflows/nightly-checks.yml | 38 +++-- ...mrClusterShrinkNightlyIntegrationTest.java | 158 ++++++++++++++++++ .../EmrDockerRunnerDockerIntegrationTest.java | 50 ------ 4 files changed, 184 insertions(+), 69 deletions(-) create mode 100644 src/test/java/io/floci/aws/services/emr/EmrClusterShrinkNightlyIntegrationTest.java diff --git a/.github/ci/prefetch-images.sh b/.github/ci/prefetch-images.sh index ee055d4836..ee689475e6 100755 --- a/.github/ci/prefetch-images.sh +++ b/.github/ci/prefetch-images.sh @@ -116,10 +116,11 @@ starts ElbV2LambdaTargetDataPlaneIntegrationTest && ecr public.ecr.aws/lambda/py # Of the nightly checks, EmrHiveStepsNightlyIntegrationTest runs a cluster's other steps in it, # EmrServerlessCustomImageNightlyIntegrationTest builds its custom image on it, # EmrFlociContainerNightlyIntegrationTest runs a cluster's steps in it from Floci in a container, -# EmrPigStepsNightlyIntegrationTest a cluster's Pig steps, and EmrAppUiNightlyIntegrationTest a cluster's MapReduce one. +# EmrPigStepsNightlyIntegrationTest a cluster's Pig steps, EmrAppUiNightlyIntegrationTest a MapReduce step, +# and EmrClusterShrinkNightlyIntegrationTest a cluster shrink. starts EmrDockerRunnerDockerIntegrationTest EmrHiveStepsNightlyIntegrationTest EmrServerlessCustomImageNightlyIntegrationTest \ EmrFlociContainerNightlyIntegrationTest EmrPigStepsNightlyIntegrationTest EmrNotebookExecutionNightlyIntegrationTest \ - EmrAppUiNightlyIntegrationTest \ + EmrAppUiNightlyIntegrationTest EmrClusterShrinkNightlyIntegrationTest \ && ecr public.ecr.aws/emr-serverless/spark/emr-7.5.0:latest # EmrServerlessHiveDockerIntegrationTest runs EMR Serverless Hive job runs, and EmrHiveStepsNightlyIntegrationTest EMR # Hive steps, in the emr-7.5.0 Hive image the runner's default Hive template names, 2.7 GB; every EMR cluster runs its @@ -128,7 +129,7 @@ starts EmrDockerRunnerDockerIntegrationTest EmrHiveStepsNightlyIntegrationTest E # Hadoop comes from it too). starts EmrServerlessHiveDockerIntegrationTest EmrHiveStepsNightlyIntegrationTest EmrDockerRunnerDockerIntegrationTest \ EmrFlociContainerNightlyIntegrationTest EmrPigStepsNightlyIntegrationTest EmrSessionServerNightlyIntegrationTest \ - EmrNotebookExecutionNightlyIntegrationTest EmrAppUiNightlyIntegrationTest \ + EmrNotebookExecutionNightlyIntegrationTest EmrAppUiNightlyIntegrationTest EmrClusterShrinkNightlyIntegrationTest \ && ecr public.ecr.aws/emr-serverless/hive/emr-7.5.0:latest # The nightly EmrServerlessSparkConnectNightlyIntegrationTest runs a session's Spark Connect server, and its client, in # the emr-7.13.0 image, 3.7 GB, the first release with sessions, and EmrServerlessDashboardNightlyIntegrationTest a job diff --git a/.github/workflows/nightly-checks.yml b/.github/workflows/nightly-checks.yml index 86e93e9438..786fa2909d 100644 --- a/.github/workflows/nightly-checks.yml +++ b/.github/workflows/nightly-checks.yml @@ -26,19 +26,20 @@ concurrency: jobs: checks: - name: Nightly checks + name: Nightly checks (${{ matrix.group }}) runs-on: ubuntu-latest - # The checks run one after another, each within its own @Timeout bounds, so the job allows their sum, and about - # twenty minutes for the build, the image and the prefetch: EmrPigStepsNightlyIntegrationTest's 30, - # EmrFlociContainerNightlyIntegrationTest's 20 and 4 for its setup, - # EmrServerlessCustomImageNightlyIntegrationTest's 85 and 21 for its setup, - # EmrServerlessSparkConnectNightlyIntegrationTest's 30, EmrSessionServerNightlyIntegrationTest's 40, - # EmrHiveStepsNightlyIntegrationTest's five two-minute tests, one five-minute test and six-minute setup, - # EmrNotebookExecutionNightlyIntegrationTest's 40, EmrAppUiNightlyIntegrationTest's 30, and - # EmrServerlessDashboardNightlyIntegrationTest's 15, 336 in all. A check added, or a bound raised, raises this with - # it, so a slow check fails with its own message rather than the job being cancelled with none; a hosted runner - # ends any job at 360 minutes, which this stays under. - timeout-minutes: 356 + # The existing checks keep their 336-minute total plus twenty minutes for setup. The shrink check runs + # separately: its sixteen-minute method and two-minute setup plus twenty minutes for compilation/prefetch. + # Combining them would exceed the hosted runner's 360-minute job limit. + strategy: + fail-fast: false + matrix: + include: + - group: standard + timeout: 356 + - group: cluster-shrink + timeout: 38 + timeout-minutes: ${{ matrix.timeout }} # A fork's schedule would spend its owner's minutes on checks it never asked for; a draft waits until it is # ready for review, as the CI shards do. if: >- @@ -53,8 +54,13 @@ jobs: run: | cd src/test/java find . -name '*NightlyIntegrationTest.java' | sed 's|^\./||; s|\.java$||' | LC_ALL=C sort \ - > "$GITHUB_WORKSPACE/nightly.txt" + > "$GITHUB_WORKSPACE/all-nightly.txt" cd "$GITHUB_WORKSPACE" + if [ "${{ matrix.group }}" = "cluster-shrink" ]; then + grep '/EmrClusterShrinkNightlyIntegrationTest$' all-nightly.txt > nightly.txt + else + grep -v '/EmrClusterShrinkNightlyIntegrationTest$' all-nightly.txt > nightly.txt + fi count=$(wc -l < nightly.txt | tr -d ' ') echo "count=$count" >> "$GITHUB_OUTPUT" echo "$count nightly checks" @@ -100,7 +106,7 @@ jobs: # A check that runs Floci in a container, as a user's Docker setup does, runs this image: this commit's own # build, made from the compiled application as docker/Dockerfile.jvm-package describes. - name: Build the Floci image - if: steps.list.outputs.count != '0' + if: steps.list.outputs.count != '0' && matrix.group == 'standard' run: | ./mvnw package -B -q -DskipTests docker build -q -f docker/Dockerfile.jvm-package -t floci/floci:nightly-check . @@ -111,7 +117,7 @@ jobs: run: > ./mvnw surefire:test -B -Dsurefire.includesFile="$GITHUB_WORKSPACE/nightly.txt" - -Dsurefire.failIfNoTests=true + -DfailIfNoTests=true -Dnightly.checks.enabled=true -Dnightly.checks.floci-image=floci/floci:nightly-check @@ -126,7 +132,7 @@ jobs: if: always() && steps.list.outputs.count != '0' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: nightly-checks + name: nightly-checks-${{ matrix.group }} path: | nightly.txt prefetch-images.log diff --git a/src/test/java/io/floci/aws/services/emr/EmrClusterShrinkNightlyIntegrationTest.java b/src/test/java/io/floci/aws/services/emr/EmrClusterShrinkNightlyIntegrationTest.java new file mode 100644 index 0000000000..4c7e58b427 --- /dev/null +++ b/src/test/java/io/floci/aws/services/emr/EmrClusterShrinkNightlyIntegrationTest.java @@ -0,0 +1,158 @@ +package io.floci.aws.services.emr; + +import com.github.dockerjava.api.exception.NotFoundException; +import io.floci.aws.config.EmulatorConfig; +import io.floci.aws.core.common.docker.ContainerLifecycleManager; +import io.floci.aws.core.common.docker.ContainerStorageHelper; +import io.floci.aws.testing.AwsTestClients; +import io.floci.aws.testing.CloudFormationSettingsProfile; +import io.floci.aws.testing.DockerAvailability; +import io.floci.aws.testing.EmrRequests; +import io.floci.aws.testing.PartitionCleanup; +import io.floci.aws.testing.RestAssuredJsonUtils; +import io.floci.aws.testing.S3TestClients; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import jakarta.inject.Inject; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; +import org.junit.jupiter.api.extension.RegisterExtension; +import software.amazon.awssdk.core.sync.RequestBody; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.s3.S3Client; + +import java.time.Duration; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static io.floci.aws.testing.EmrRequests.awaitStep; +import static io.floci.aws.testing.EmrRequests.emr; +import static io.floci.aws.testing.EmrRequests.terminateClusterAndAwaitCleanup; +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +/** Executor placement and HDFS data preservation while a four-node EMR cluster shrinks. */ +@QuarkusTest +@TestProfile(CloudFormationSettingsProfile.class) +@EnabledIfSystemProperty(named = "nightly.checks.enabled", matches = "true") +class EmrClusterShrinkNightlyIntegrationTest { + + @RegisterExtension + final PartitionCleanup cleanup = new PartitionCleanup(); + + @Inject + ContainerLifecycleManager lifecycle; + + @Inject + EmulatorConfig config; + + @Inject + EmrService emrService; + + private S3Client s3; + private String bucket; + private String clusterId; + + @BeforeAll + static void configure() { + RestAssuredJsonUtils.configureAwsContentTypes(); + } + + @BeforeEach + @Timeout(value = 2, unit = TimeUnit.MINUTES) + void prepareBucket() throws InterruptedException { + assumeTrue(DockerAvailability.isAvailable(), "Docker daemon must be available for EMR's shrink check"); + s3 = AwsTestClients.create(S3Client.builder().forcePathStyle(true), "000000000000", Region.US_EAST_1); + cleanup.register(s3::close); + bucket = "emr-shrink-" + UUID.randomUUID().toString().substring(0, 8); + s3.createBucket(request -> request.bucket(bucket)); + cleanup.register(() -> S3TestClients.deleteBucket(s3, bucket)); + } + + @Test + // Two five-minute step waits + five-minute decommission + one minute for API calls and assertions. + @Timeout(value = 16, unit = TimeUnit.MINUTES) + void aClustersCoreAndTaskNodesRunItsExecutorsAndAShrinkKeepsItsHdfsData() { + put("side/nodes.py", """ + import socket + import sys + from pyspark.sql import SparkSession + spark = SparkSession.builder.getOrCreate() + lines = spark.sparkContext.parallelize(range(8), 8) \\ + .map(lambda i: (socket.gethostname(), "line " + str(i))).cache() + lines.map(lambda line: line[1]).saveAsTextFile("hdfs:///kept") + hosts = " ".join(sorted(set(lines.map(lambda line: line[0]).collect()))) + spark.createDataFrame([(hosts,)], ["value"]).coalesce(1).write.text(sys.argv[1]) + """); + startCluster("[]", null, ",{\"Name\":\"core\",\"InstanceRole\":\"CORE\",\"InstanceType\":\"m5.xlarge\"," + + "\"InstanceCount\":2},{\"Name\":\"task\",\"InstanceRole\":\"TASK\",\"InstanceType\":\"m5.xlarge\"," + + "\"InstanceCount\":1}"); + + // Its executors run on its core and task nodes, each named as ListInstances names it, not on its primary node. + assertEquals("COMPLETED", runStep("command-runner.jar", "spark-submit", s3Uri("side/nodes.py"), + s3Uri("hosts/"))); + List instances = emr("ListInstances", "{\"ClusterId\":\"" + clusterId + "\"}").jsonPath() + .getList("Instances.PrivateDnsName"); + for (String host : partFiles("hosts/").trim().split(" ")) { + assertTrue(instances.subList(1, instances.size()).contains(host), host + " among " + instances); + } + + // A core node goes, once HDFS has moved its blocks to the one that stays, and every line is still there. + String core = emr("ListInstanceGroups", "{\"ClusterId\":\"" + clusterId + "\"}").jsonPath() + .getString("InstanceGroups.find { it.InstanceGroupType == 'CORE' }.Id"); + emr("ModifyInstanceGroups", "{\"ClusterId\":\"" + clusterId + "\",\"InstanceGroups\":[{\"InstanceGroupId\":\"" + + core + "\",\"InstanceCount\":1}]}").then().statusCode(200); + String leaving = ContainerStorageHelper.dockerName(config, "emr-" + clusterId + "-node-1-2"); + await("core node " + leaving + " to go").atMost(Duration.ofMinutes(5)).pollInterval(Duration.ofSeconds(1)) + .until(() -> gone(leaving)); + assertEquals("COMPLETED", runStep("command-runner.jar", "s3-dist-cp", "--src", "hdfs:///kept/", + "--dest", s3Uri("kept/"))); + assertEquals("line 0\nline 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\n", partFiles("kept/")); + } + + /** A primary node followed by {@code moreGroups}, each led by a comma, on the cached release. */ + private void startCluster(String configurations, String logUri, String moreGroups) { + clusterId = emr("RunJobFlow", "{\"Name\":\"docker-runner\",\"ReleaseLabel\":\"emr-7.5.0\"," + + (logUri == null ? "" : "\"LogUri\":\"" + logUri + "\",") + + "\"Applications\":[{\"Name\":\"Hadoop\"},{\"Name\":\"Spark\"}]," + + "\"Configurations\":" + configurations + "," + + "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,\"InstanceGroups\":[{\"Name\":\"primary\"," + + "\"InstanceRole\":\"MASTER\",\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}" + moreGroups + "]}}") + .then().statusCode(200).extract().jsonPath().getString("JobFlowId"); + cleanup.register(() -> terminateClusterAndAwaitCleanup(clusterId, emrService)); + } + + /** Whether Docker no longer has the container named so. */ + private boolean gone(String name) { + try { + lifecycle.getDockerClient().inspectContainerCmd(name).exec(); + return false; + } catch (NotFoundException e) { + return true; + } + } + + /** Adds one step to the cluster and returns the state it ended in. */ + private String runStep(String jar, String... args) { + String stepId = EmrRequests.addStep(clusterId, jar, jar, args); + return awaitStep(clusterId, stepId).jsonPath().getString("Step.Status.State"); + } + + private void put(String key, String text) { + s3.putObject(request -> request.bucket(bucket).key(key), RequestBody.fromString(text)); + } + + private String s3Uri(String key) { + return "s3://" + bucket + "/" + key; + } + + private String partFiles(String prefix) { + return S3TestClients.partFiles(s3, bucket, prefix); + } +} diff --git a/src/test/java/io/floci/aws/services/emr/EmrDockerRunnerDockerIntegrationTest.java b/src/test/java/io/floci/aws/services/emr/EmrDockerRunnerDockerIntegrationTest.java index 5f031141ae..d38f633741 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrDockerRunnerDockerIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrDockerRunnerDockerIntegrationTest.java @@ -2,7 +2,6 @@ package io.floci.aws.services.emr; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.github.dockerjava.api.exception.NotFoundException; import io.floci.aws.config.EmulatorConfig; import io.floci.aws.core.common.docker.ContainerExec; import io.floci.aws.core.common.docker.ContainerLifecycleManager; @@ -245,45 +244,6 @@ class EmrDockerRunnerDockerIntegrationTest { driverLogs.get(0)); } - @Test - void aClustersCoreAndTaskNodesRunItsExecutorsAndAShrinkKeepsItsHdfsData() { - put("side/nodes.py", """ - import socket - import sys - from pyspark.sql import SparkSession - spark = SparkSession.builder.getOrCreate() - lines = spark.sparkContext.parallelize(range(8), 8) \\ - .map(lambda i: (socket.gethostname(), "line " + str(i))).cache() - lines.map(lambda line: line[1]).saveAsTextFile("hdfs:///kept") - hosts = " ".join(sorted(set(lines.map(lambda line: line[0]).collect()))) - spark.createDataFrame([(hosts,)], ["value"]).coalesce(1).write.text(sys.argv[1]) - """); - startCluster("[]", null, ",{\"Name\":\"core\",\"InstanceRole\":\"CORE\",\"InstanceType\":\"m5.xlarge\"," - + "\"InstanceCount\":2},{\"Name\":\"task\",\"InstanceRole\":\"TASK\",\"InstanceType\":\"m5.xlarge\"," - + "\"InstanceCount\":1}"); - - // Its executors run on its core and task nodes, each named as ListInstances names it, not on its primary node. - assertEquals("COMPLETED", runStep("command-runner.jar", "spark-submit", s3Uri("side/nodes.py"), - s3Uri("hosts/"))); - List instances = emr("ListInstances", "{\"ClusterId\":\"" + clusterId + "\"}").jsonPath() - .getList("Instances.PrivateDnsName"); - for (String host : partFiles("hosts/").trim().split(" ")) { - assertTrue(instances.subList(1, instances.size()).contains(host), host + " among " + instances); - } - - // A core node goes, once HDFS has moved its blocks to the one that stays, and every line is still there. - String core = emr("ListInstanceGroups", "{\"ClusterId\":\"" + clusterId + "\"}").jsonPath() - .getString("InstanceGroups.find { it.InstanceGroupType == 'CORE' }.Id"); - emr("ModifyInstanceGroups", "{\"ClusterId\":\"" + clusterId + "\",\"InstanceGroups\":[{\"InstanceGroupId\":\"" - + core + "\",\"InstanceCount\":1}]}").then().statusCode(200); - String leaving = ContainerStorageHelper.dockerName(config, "emr-" + clusterId + "-node-1-2"); - await("core node " + leaving + " to go").atMost(Duration.ofMinutes(5)).pollInterval(Duration.ofSeconds(1)) - .until(() -> gone(leaving)); - assertEquals("COMPLETED", runStep("command-runner.jar", "s3-dist-cp", "--src", "hdfs:///kept/", - "--dest", s3Uri("kept/"))); - assertEquals("line 0\nline 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\n", partFiles("kept/")); - } - @Test void aClustersHdfsWhoseDataNodeExitsStartsAgainOnItsDataForTheNextStep() { startCluster("[]"); @@ -465,16 +425,6 @@ class EmrDockerRunnerDockerIntegrationTest { cleanup.register(() -> terminateClusterAndAwaitCleanup(clusterId, emrService)); } - /** Whether Docker no longer has the container named so. */ - private boolean gone(String name) { - try { - lifecycle.getDockerClient().inspectContainerCmd(name).exec(); - return false; - } catch (NotFoundException e) { - return true; - } - } - /** Runs a tiny streaming fixture with one mapper and one reducer. */ private String runSingleTaskStreamingStep(String jar, String... args) { List streamingArgs = new ArrayList<>();