feat(emr-serverless): report the image digest each job run attempt resolved (#8307)

GetJobRun now carries the job run's imageConfiguration and
workerTypeSpecifications. Each attempt copies its application's image
configurations as they stand when the attempt is made. The configuration
the driver takes its image from, its worker type's or else the
application's, gets the resolvedImageDigest of the image the attempt
pulled for the driver: the manifest digest the Docker runner's pull
already returned. The executors' configuration gets theirs, or keeps the
driver's where the two share one. "To identify which image version each
job is running, the GetJobRun API response returns the resolvedImageDigest
for that specific job."

A retried attempt resolves its images again ("New job attempts will pick
new images") and keeps its own digests; earlier attempts keep theirs. A
configuration no worker type ran gets no digest, even one naming the same
image, nor does an image built locally under that URI, nor any outside
the docker runner mode. The application's own resolvedImageDigest, which
AWS fixes at its start for 7.13 and earlier, is not part of this change.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-14 10:59:40 -04:00
1 parent c407c82f8f
commit ddc844b48e
9 files changed
+375 -12

No files matched your search

@@ -18,6 +18,7 @@ import java.math.BigDecimal;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.hamcrest.Matchers.*;
@@ -123,7 +124,27 @@ class EmrServerlessJobRunIntegrationTest {
.body("jobRun.attempt", equalTo(1))
.body("jobRun.attemptCreatedAt", instanceOf(Number.class))
.body("jobRun.attemptUpdatedAt", instanceOf(Number.class))
.body("jobRun", not(hasKey("hive")));
.body("jobRun", not(hasKey("hive")))
.body("jobRun", not(hasKey("imageConfiguration")))
.body("jobRun", not(hasKey("workerTypeSpecifications")));
}
@Test
void getJobRunReportsTheImageConfigurationsTheRunApplies() {
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
String driverImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/driver:7.5.0";
String applicationId = createApplication("""
, "imageConfiguration": {"imageUri": "%s", "applicationLevelDigestResolution": false},
"workerTypeSpecifications": {"Driver": {"imageConfiguration": {"imageUri": "%s"}}}"""
.formatted(applicationImage, driverImage));
String jobRunId = startedRunId(applicationId, sparkRun(UUID.randomUUID().toString(), ""));
// Without the docker runner mode no image is pulled, so neither has a digest.
givenReq().when().get("/applications/" + applicationId + "/jobruns/" + jobRunId)
.then().statusCode(200)
.body("jobRun.imageConfiguration", equalTo(Map.of("imageUri", applicationImage)))
.body("jobRun.workerTypeSpecifications",
equalTo(Map.of("Driver", Map.of("imageConfiguration", Map.of("imageUri", driverImage)))));
}
@Test
@@ -9,6 +9,7 @@ import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.emrserverless.model.Application;
import io.floci.aws.services.emrserverless.model.CreateApplicationRequest;
import io.floci.aws.services.emrserverless.model.ImageConfiguration;
import io.floci.aws.services.emrserverless.model.JobDriver;
import io.floci.aws.services.emrserverless.model.JobRun;
import io.floci.aws.services.emrserverless.model.JobRunAttemptSummary;
@@ -26,12 +27,14 @@ import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -52,6 +55,8 @@ class EmrServerlessJobRunServiceTest {
private static final String REGION = "us-east-1";
private static final String ACCOUNT_ID = "000000000000";
private static final String ROLE = "arn:aws:iam::000000000000:role/emr-serverless-job";
private static final String DIGEST = "sha256:" + "a".repeat(64);
private static final String OTHER_DIGEST = "sha256:" + "b".repeat(64);
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
private EmrServerlessService applications;
@@ -318,6 +323,170 @@ class EmrServerlessJobRunServiceTest {
assertNull(runner.jobs.get(2).customImage());
}
@Test
void aRunReportsTheImageConfigurationsItAppliesEachWithTheDigestOfTheImageItsRunnerResolvedForIt() {
FakeRunner runner = new FakeRunner();
EmrServerlessJobRunService service = dockerService(runner, 2);
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
String driverImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/driver:7.5.0";
String executorImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/executor:7.5.0";
CreateApplicationRequest custom = applicationRequest("custom", "emr-7.5.0", "SPARK");
custom.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
custom.getImageConfiguration().setApplicationLevelDigestResolution(false);
custom.setWorkerTypeSpecifications(Map.of("Driver", EmrServerlessServiceTest.workerType(driverImage),
"Executor", EmrServerlessServiceTest.workerType(executorImage)));
String customId = applications.createApplication(custom).getApplicationId();
String jobRunId = service.startJobRun(customId, request(null, null)).getJobRunId();
String plain = service.startJobRun(applicationId, request(null, null)).getJobRunId();
runner.digests.put(driverImage, DIGEST);
runner.digests.put(executorImage, OTHER_DIGEST);
JobRun submitted = service.getJobRun(customId, jobRunId, null);
runNext();
runNext();
assertEquals(List.of("application " + applicationImage + " null", "Driver " + driverImage + " null",
"Executor " + executorImage + " null"), images(submitted));
// The driver and the executors each run their worker type's image, so the application's runs on none.
JobRun ran = service.getJobRun(customId, jobRunId, null);
assertEquals(List.of("application " + applicationImage + " null", "Driver " + driverImage + " " + DIGEST,
"Executor " + executorImage + " " + OTHER_DIGEST), images(ran));
assertNull(ran.getImageConfiguration().getApplicationLevelDigestResolution());
// The application's own stay as it gave them.
Application app = applications.getApplication(customId);
assertNull(app.getImageConfiguration().getResolvedImageDigest());
assertNull(app.getWorkerTypeSpecifications().get("Driver").getImageConfiguration().getResolvedImageDigest());
JobRun withoutImages = service.getJobRun(applicationId, plain, null);
assertNull(withoutImages.getImageConfiguration());
assertNull(withoutImages.getWorkerTypeSpecifications());
}
@Test
void aDigestGoesOnlyToTheConfigurationItsWorkerTypeTookItsImageFromNotToAnotherNamingThatImage() {
FakeRunner runner = new FakeRunner();
EmrServerlessJobRunService service = dockerService(runner);
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
String hiveDriverImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/hive/driver:7.5.0";
CreateApplicationRequest spark = applicationRequest("local-executors", "emr-7.5.0", "SPARK");
spark.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
spark.setWorkerTypeSpecifications(Map.of("Executor", EmrServerlessServiceTest.workerType(applicationImage)));
CreateApplicationRequest hive = applicationRequest("tez-tasks", "emr-7.5.0", "HIVE");
hive.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
hive.setWorkerTypeSpecifications(Map.of("HiveDriver", EmrServerlessServiceTest.workerType(hiveDriverImage),
"TezTask", EmrServerlessServiceTest.workerType(hiveDriverImage)));
String sparkId = applications.createApplication(spark).getApplicationId();
String hiveId = applications.createApplication(hive).getApplicationId();
String sparkRun = service.startJobRun(sparkId, request(null, null)).getJobRunId();
String hiveRun = service.startJobRun(hiveId, hiveRequest("s3://bucket/queries/report.sql", null, null))
.getJobRunId();
runner.digests.put(applicationImage, DIGEST);
runner.digests.put(hiveDriverImage, OTHER_DIGEST);
runNext();
runNext();
// Local mode runs the executors in the driver's container, and Tez a Hive run's tasks, so neither image runs.
assertEquals(List.of("application " + applicationImage + " " + DIGEST,
"Executor " + applicationImage + " null"), images(service.getJobRun(sparkId, sparkRun, null)));
assertEquals(List.of("application " + applicationImage + " null",
"HiveDriver " + hiveDriverImage + " " + OTHER_DIGEST, "TezTask " + hiveDriverImage + " null"),
images(service.getJobRun(hiveId, hiveRun, null)));
}
@Test
void eachWorkerTypeKeepsTheDigestOfItsOwnPullAndAConfigurationTheyShareHoldsTheDrivers() {
FakeRunner runner = new FakeRunner();
EmrServerlessJobRunService service = dockerService(runner, 2);
String sameTag = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
String shared = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/shared:7.5.0";
CreateApplicationRequest apart = applicationRequest("apart", "emr-7.5.0", "SPARK");
apart.setWorkerTypeSpecifications(Map.of("Driver", EmrServerlessServiceTest.workerType(sameTag),
"Executor", EmrServerlessServiceTest.workerType(sameTag)));
CreateApplicationRequest together = applicationRequest("together", "emr-7.5.0", "SPARK");
together.setImageConfiguration(EmrServerlessServiceTest.image(shared));
String apartId = applications.createApplication(apart).getApplicationId();
String togetherId = applications.createApplication(together).getApplicationId();
String apartRun = service.startJobRun(apartId, request(null, null)).getJobRunId();
String togetherRun = service.startJobRun(togetherId, request(null, null)).getJobRunId();
// The tag pushed again between the driver's pull and the executors'.
runner.digests.put(sameTag, DIGEST);
runner.executorDigests.put(sameTag, OTHER_DIGEST);
runner.digests.put(shared, DIGEST);
runner.executorDigests.put(shared, OTHER_DIGEST);
runNext();
runNext();
assertEquals(List.of("Driver " + sameTag + " " + DIGEST, "Executor " + sameTag + " " + OTHER_DIGEST),
images(service.getJobRun(apartId, apartRun, null)));
assertEquals(List.of("application " + shared + " " + DIGEST),
images(service.getJobRun(togetherId, togetherRun, null)));
}
@Test
void eachAttemptAppliesItsApplicationsImageAgainAndKeepsTheDigestItsOwnPullResolved() {
FakeRunner runner = new FakeRunner();
runner.outcome = SparkJobRunner.Outcome.exitedWith(1);
EmrServerlessJobRunService service = dockerService(runner);
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
CreateApplicationRequest custom = applicationRequest("retagged", "emr-7.5.0", "SPARK");
custom.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
String customId = applications.createApplication(custom).getApplicationId();
StartJobRunRequest resilient = request(null, null);
resilient.setRetryPolicy(Map.of("maxAttempts", 2));
String jobRunId = service.startJobRun(customId, resilient).getJobRunId();
runner.digests.put(applicationImage, DIGEST);
runNext();
JobRun secondScheduled = service.getJobRun(customId, jobRunId, null);
// The tag pushed again: "either by retagging an image in Amazon ECR or by updating the imageConfiguration".
runner.digests.put(applicationImage, OTHER_DIGEST);
runner.outcome = SparkJobRunner.Outcome.exitedWith(0);
runNext();
assertEquals(List.of("application " + applicationImage + " null"), images(secondScheduled));
assertEquals(List.of("application " + applicationImage + " " + OTHER_DIGEST),
images(service.getJobRun(customId, jobRunId, null)));
assertEquals(List.of("application " + applicationImage + " " + DIGEST),
images(service.getJobRun(customId, jobRunId, 1)));
}
@Test
void aDigestResolvedOnceAResetHasBegunIsNotWritten() {
FakeRunner runner = new FakeRunner();
EmrServerlessJobRunService service = dockerService(runner);
String applicationImage = "000000000000.dkr.ecr.us-east-1.amazonaws.com/spark/custom:7.5.0";
CreateApplicationRequest custom = applicationRequest("reset", "emr-7.5.0", "SPARK");
custom.setImageConfiguration(EmrServerlessServiceTest.image(applicationImage));
String customId = applications.createApplication(custom).getApplicationId();
String jobRunId = service.startJobRun(customId, request(null, null)).getJobRunId();
runner.digests.put(applicationImage, DIGEST);
runner.whileResolving = service::beforeReset;
runNext();
assertEquals(List.of("application " + applicationImage + " null"),
images(store.get(jobRunId).orElseThrow().getJobRun()));
}
// A run's image configurations, each "<whose> <imageUri> <resolvedImageDigest>": its own, then its worker types'
// by name.
private static List<String> images(JobRun run) {
List<String> images = new ArrayList<>();
if (run.getImageConfiguration() != null) {
images.add(described("application", run.getImageConfiguration()));
}
if (run.getWorkerTypeSpecifications() != null) {
new TreeMap<>(run.getWorkerTypeSpecifications()).forEach((workerType, specification) ->
images.add(described(workerType, specification.getImageConfiguration())));
}
return images;
}
private static String described(String whose, ImageConfiguration image) {
return whose + " " + image.getImageUri() + " " + image.getResolvedImageDigest();
}
@Test
void aRunsContainersRunForItsApplicationsArchitectureElseTheDockerHostsOwn() {
FakeRunner runner = new FakeRunner();
@@ -1198,6 +1367,11 @@ class EmrServerlessJobRunServiceTest {
Outcome outcome = Outcome.exitedWith(0);
Runnable whileRunning = () -> { };
Runnable whileTimingOut = () -> { };
// The manifest digest each custom image resolves to, told before the driver starts as the Docker runner does,
// and the executors' where their pull resolves another, as a push between the two pulls gives.
final Map<String, String> digests = new HashMap<>();
final Map<String, String> executorDigests = new HashMap<>();
Runnable whileResolving = () -> { };
@Override
public Outcome run(Job job, Progress progress) {
@@ -1206,6 +1380,13 @@ class EmrServerlessJobRunServiceTest {
if (progress.cancelled()) {
return Outcome.halted();
}
// The driver's first, so an executors' digest written over it shows.
resolved(progress, WorkerType.DRIVER, job.customImage(), digests);
if (job.executors() != null) {
Map<String, String> executorsResolve = new HashMap<>(digests);
executorsResolve.putAll(executorDigests);
resolved(progress, WorkerType.EXECUTOR, job.executors().image(), executorsResolve);
}
driversStarted.add(job.runId());
progress.started();
cancelledAsRunning.add(progress.cancelled());
@@ -1218,6 +1399,13 @@ class EmrServerlessJobRunServiceTest {
return stopped.contains(job.runId()) ? Outcome.halted() : outcome;
}
private void resolved(Progress progress, WorkerType workerType, String image, Map<String, String> resolve) {
if (image != null && resolve.containsKey(image)) {
whileResolving.run();
progress.imageResolved(workerType, resolve.get(image));
}
}
@Override
public void stop(String runId) {
stopped.add(runId);
@@ -696,6 +696,35 @@ class EmrServerlessSparkRunnerTest {
verify(builder, never()).newContainer(custom);
}
@Test
void aRunIsToldTheManifestDigestEachWorkerTypesCustomImageResolvedToAndNoneForAnImageWithout() {
ContainerBuilder builder = mock(ContainerBuilder.class);
ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
String driverImage = "123456789012.dkr.ecr.eu-west-1.amazonaws.com/spark/driver:7.5.0";
String executorImage = "123456789012.dkr.ecr.eu-west-1.amazonaws.com/spark/executor:7.5.0";
String builtLocally = "123456789012.dkr.ecr.eu-west-1.amazonaws.com/spark/local:7.5.0";
when(builder.newContainer(anyString())).thenReturn(spec);
when(builder.resolveImage(anyString())).thenAnswer(resolve -> resolve.getArgument(0));
when(ecr.rewriteImageUri(anyString())).thenAnswer(rewrite -> "localhost:5100/" + rewrite.getArgument(0));
when(lifecycle.resolveImageForLaunch("localhost:5100/" + driverImage, ImagePullBehavior.DEFAULT, null))
.thenReturn(new LaunchImage("sha256:" + "1".repeat(64), "sha256:" + "a".repeat(64)));
when(lifecycle.resolveImageForLaunch("localhost:5100/" + executorImage, ImagePullBehavior.DEFAULT, null))
.thenReturn(new LaunchImage("sha256:" + "2".repeat(64), "sha256:" + "b".repeat(64)));
when(lifecycle.resolveImageForLaunch("localhost:5100/" + builtLocally, ImagePullBehavior.DEFAULT, null))
.thenReturn(new LaunchImage("sha256:" + "3".repeat(64), null));
EmrServerlessSparkRunner runner = runner(builder);
ContainerExecStubs.completeEveryExec(docker, "driver", 7L, "", "");
runner.run(customImageJob(driverImage)
.withExecutors(new SparkJobRunner.Executors(2, executorImage, 0, 0, 0, null)), progress);
runner.run(customImageJob(builtLocally), progress);
// Each for the worker type that runs it.
verify(progress).imageResolved(SparkJobRunner.WorkerType.DRIVER, "sha256:" + "a".repeat(64));
verify(progress).imageResolved(SparkJobRunner.WorkerType.EXECUTOR, "sha256:" + "b".repeat(64));
verify(progress, times(2)).imageResolved(any(), any());
}
@Test
void aCommandRunsThroughFlocisWrapperWithTheJobsSparkSettingsInItsEnvironment() {
ContainerBuilder builder = mock(ContainerBuilder.class);