From 3ffec01a76c72aa61d255e2c56a51253b2a760ec Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Wed, 18 Nov 2026 15:41:25 -0400 Subject: [PATCH] feat(emr-serverless): open the live Spark UI from dashboard links (#8890) With runner-mode docker, GetDashboardForJobRun's link for a Spark run's attempt that has not ended now opens its driver's Spark UI for real, and GetResourceDashboard's link does the same for a session's Spark Connect server, as "For jobs in a running state, the application UI is a live user interface such as the Spark or Tez web UI" and "While a session is active, the URL opens the live Apache Spark UI". Each link opens on a host of its own, -4040.emr-serverless-ui., through the application UI proxy EMR's on-cluster UIs use. That proxy moves to core.common (AppUiProxy, AppUiRoutes, AppUiRoute, AppUiHost), and each service registers the label its hosts are under. The runner turns the driver's UI on for every EMR Serverless Spark run, as the release's image turns it off, publishes port 4040 on the Docker host's loopback interface, and keeps where Floci reaches it while the container runs. A run whose logs are not kept in managed storage gets no live UI, as with logs in S3 alone the application UI is "Not supported". A Hive run, a run or session that has ended, and every link in the immediate mode still open Floci's own page, which now says whether the attempt's logs are in managed storage. --- .github/ci/prefetch-images.sh | 6 +- .github/workflows/nightly-checks.yml | 9 +- docs/services/emr-serverless.md | 44 ++- .../io/floci/aws/config/TlsConfigSource.java | 1 + .../io/floci/aws/core/common/AppUiHost.java | 58 ++++ .../common/AppUiProxy.java} | 65 ++-- .../io/floci/aws/core/common/AppUiRoute.java | 33 ++ .../io/floci/aws/core/common/AppUiRoutes.java | 20 ++ .../aws/services/emr/EmrAppUiService.java | 89 ++--- .../emrserverless/EmrServerlessAppUis.java | 192 ++++++++++ .../EmrServerlessController.java | 20 +- .../EmrServerlessDashboardController.java | 20 +- .../EmrServerlessDashboards.java | 6 +- .../EmrServerlessJobRunService.java | 30 +- .../EmrServerlessSparkRunner.java | 56 ++- .../emrserverless/SparkJobRunner.java | 27 ++ .../model/DriverLogDestinations.java | 12 +- .../common/AppUiProxyTest.java} | 76 +++- .../services/emr/EmrAppUiIntegrationTest.java | 11 + .../services/emr/EmrOnClusterAppUiTest.java | 11 +- .../services/emr/EmrPersistentAppUiTest.java | 3 +- .../EmrServerlessAppUisTest.java | 327 ++++++++++++++++++ ...erlessDashboardNightlyIntegrationTest.java | 177 ++++++++++ .../EmrServerlessJobRunServiceTest.java | 22 ++ .../EmrServerlessSparkRunnerTest.java | 56 ++- .../AslExecutorEmrServerlessSyncTest.java | 7 +- 26 files changed, 1226 insertions(+), 152 deletions(-) create mode 100644 src/main/java/io/floci/aws/core/common/AppUiHost.java rename src/main/java/io/floci/aws/{services/emr/EmrAppUiProxy.java => core/common/AppUiProxy.java} (78%) create mode 100644 src/main/java/io/floci/aws/core/common/AppUiRoute.java create mode 100644 src/main/java/io/floci/aws/core/common/AppUiRoutes.java create mode 100644 src/main/java/io/floci/aws/services/emrserverless/EmrServerlessAppUis.java rename src/test/java/io/floci/aws/{services/emr/EmrAppUiProxyTest.java => core/common/AppUiProxyTest.java} (75%) create mode 100644 src/test/java/io/floci/aws/services/emrserverless/EmrServerlessAppUisTest.java create mode 100644 src/test/java/io/floci/aws/services/emrserverless/EmrServerlessDashboardNightlyIntegrationTest.java diff --git a/.github/ci/prefetch-images.sh b/.github/ci/prefetch-images.sh index 17160fcd7d..ee055d4836 100755 --- a/.github/ci/prefetch-images.sh +++ b/.github/ci/prefetch-images.sh @@ -131,8 +131,10 @@ starts EmrServerlessHiveDockerIntegrationTest EmrHiveStepsNightlyIntegrationTest EmrNotebookExecutionNightlyIntegrationTest EmrAppUiNightlyIntegrationTest \ && 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. -starts EmrServerlessSparkConnectNightlyIntegrationTest && ecr public.ecr.aws/emr-serverless/spark/emr-7.13.0:latest +# the emr-7.13.0 image, 3.7 GB, the first release with sessions, and EmrServerlessDashboardNightlyIntegrationTest a job +# run and a session in it, whose dashboards it opens. +starts EmrServerlessSparkConnectNightlyIntegrationTest EmrServerlessDashboardNightlyIntegrationTest \ + && ecr public.ecr.aws/emr-serverless/spark/emr-7.13.0:latest # The nightly EmrSessionServerNightlyIntegrationTest runs an EMR session's Spark Connect server on an emr-spark-8.1.0 # cluster, Spark 4, sessions needing the AWS runtime for Apache Spark, and its client in that image. starts EmrSessionServerNightlyIntegrationTest && ecr public.ecr.aws/emr-serverless/spark4/emr-spark-8.1.0:latest diff --git a/.github/workflows/nightly-checks.yml b/.github/workflows/nightly-checks.yml index e5341e4e94..86e93e9438 100644 --- a/.github/workflows/nightly-checks.yml +++ b/.github/workflows/nightly-checks.yml @@ -34,10 +34,11 @@ jobs: # 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, and EmrAppUiNightlyIntegrationTest's 30, 321 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. - timeout-minutes: 341 + # 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 # 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: >- diff --git a/docs/services/emr-serverless.md b/docs/services/emr-serverless.md index 33e7eedada..685fc944ad 100644 --- a/docs/services/emr-serverless.md +++ b/docs/services/emr-serverless.md @@ -143,13 +143,30 @@ runner mode a Spark run executes; see [Running Spark job runs](#running-spark-jo * **Dashboard**: `GetDashboardForJobRun` gives "a URL that you can use to access the application UIs for a job run", for the latest attempt or the `attempt` asked for, checked as `GetJobRun` checks it, and, as AWS's, "The URL is valid for one hour after you generate it". EMR Serverless opens the run's live Spark or Tez UI while it runs and its - Spark History Server or persistent Tez UI once it has ended; Floci keeps neither, so the URL opens a page Floci - serves at `/_aws/emr-serverless/dashboard` on its own address (`base-url`, or `hostname`), with the attempt's - state, its times and where its driver's logs go in S3 and in CloudWatch Logs, kept as the attempt was admitted, so - a later change to the application's monitoring configuration does not move them. The link names the run and is signed - with a key Floci makes as it starts: one changed, or past its hour, or given before Floci restarted, opens a `403` - page asking for a new one, and one whose run has gone a `404`. Like the rest of Floci, the page asks for no - credentials. `accessSystemProfileLogs`, for jobs on Lake Formation, changes nothing. + Spark History Server or persistent Tez UI once it has ended. With `runner-mode` set to `docker`, a link given for a + Spark run's attempt that has not ended opens its driver's Spark UI for real, through Floci, on a host of its own: + `http://-4040.emr-serverless-ui./`, the secret 26 random letters and digits that only + this link holds, so the host itself is the link's authority, as the UI takes no AWS credentials. Floci's host must + resolve its subdomains: `localhost` and `localhost.floci.io` do, and Floci's TLS certificate names + `*.emr-serverless-ui.localhost` and `*.emr-serverless-ui.localhost.floci.io`. Requests to the host go on to the + driver's UI, port 4040 of its container, which Docker publishes on the host's loopback interface alone, or which + Floci, in a container on the same network, reaches there. The release's image turns the UI off; Floci turns it on + before the run's own settings, so a run that turns it off again has none. Until the driver runs, and then until its + Spark has started the UI, or for good where the run turned it off, the host answers with a `503` page asking to try + again; once the attempt has ended, with a `404` one; past its hour, or given before Floci restarted, with a `403` + one. A run whose logs are not kept in managed storage, + its `managedPersistenceMonitoringConfiguration`, or else its application's, with `enabled` false, gets no live UI, + as with logs in S3 alone the application UI is "Not supported" ("Otherwise, you can't use the built-in application + UIs"). Floci keeps no Spark History Server for a run that has ended, and runs no Tez UI, so the link for an ended + run, a Hive run, one without managed storage, or any in the `immediate` mode, opens a page Floci serves at + `/_aws/emr-serverless/dashboard` on its own address (`base-url`, or `hostname`), with the attempt's state, its times, + where its driver's logs go in S3 and in CloudWatch Logs, and whether they are kept in managed storage, kept as the + attempt was admitted, so a later change to the application's monitoring configuration does not move them. That link + names the run and is signed with a key Floci makes as it starts: one changed, or past its hour, or given before + Floci restarted, opens a `403` page asking for a new one, and one whose run has gone a `404`. Like the rest of Floci, + neither link asks for credentials. AWS's link, by a user's report, opens a limited number of times ("This URL has + already been used the maximum number of times. Please generate a new URL."); Floci's open as often as asked within + their hour. `accessSystemProfileLogs`, for jobs on Lake Formation, changes nothing. ## Sessions @@ -193,8 +210,11 @@ and its lifecycle but runs no driver for it. * **ListSessions** returns the newest sessions first, as `ListJobRuns` orders runs, filtered by `states`, `createdAtAfter` and `createdAtBefore`, at most 50 per page, grouped by state as `ListJobRuns` groups runs. * **GetResourceDashboard** takes a `resourceType` of `SESSION`, the only one, and gives a link like - `GetDashboardForJobRun`'s, valid for an hour, to a page about the session on Floci's address, which stands in for - the session's Spark UI or Spark History Server. `accessSystemProfileLogs` changes nothing. + `GetDashboardForJobRun`'s, valid for an hour: "While a session is active, the URL opens the live Apache Spark UI". + With `runner-mode` set to `docker`, a link given before the session has ended, or begun to, opens its Spark Connect + server's Spark UI, as a run's link opens its driver's (see [Running a session's Spark Connect + server](#running-a-sessions-spark-connect-server)); any other opens a page about the session on Floci's address, + which stands in for the session's Spark UI or Spark History Server. `accessSystemProfileLogs` changes nothing. A state machine drives applications and job runs through the `emr-serverless:` integrations, `.sync` included; see [Step Functions: Amazon EMR Serverless tasks](step-functions.md#amazon-emr-serverless-tasks). @@ -236,7 +256,11 @@ The server's port is published on the Docker host's loopback interface only, and 24 hours count from when the server answers. * **Logs**: no source gives where a session's driver logs go, so Floci sends the server's output to its own log only, not to the application's monitoring configuration. -* **Spark UI**: `GetResourceDashboard` still links to Floci's page about the session, not to the server's Spark UI. +* **Spark UI**: `GetResourceDashboard`'s link opens the server's Spark UI on a host of its own, as a run's link opens + its driver's (see **Dashboard** under job runs): port 4040 of the server's container, published on the host's + loopback interface alone. Its host answers with a `503` page until the server's container runs, and with a `404` one + once the session has ended. Floci keeps no Spark History Server for a session that has ended, whose link opens + Floci's page about it. ## Running Spark job runs diff --git a/src/main/java/io/floci/aws/config/TlsConfigSource.java b/src/main/java/io/floci/aws/config/TlsConfigSource.java index 812eb788fe..c2228bcbcd 100644 --- a/src/main/java/io/floci/aws/config/TlsConfigSource.java +++ b/src/main/java/io/floci/aws/config/TlsConfigSource.java @@ -79,6 +79,7 @@ public class TlsConfigSource implements ConfigSource { "*.execute-api.localhost.localstack.cloud", "*.cloudfront.localhost.floci.io", "*.cloudfront.localhost", "*.emrappui.localhost.floci.io", "*.emrappui.localhost", + "*.emr-serverless-ui.localhost.floci.io", "*.emr-serverless-ui.localhost", "host.docker.internal")); for (String region : AwsRegions.KNOWN_IDS.stream().sorted().toList()) { sans.add("*.dkr.ecr." + region + ".localhost.floci.io"); diff --git a/src/main/java/io/floci/aws/core/common/AppUiHost.java b/src/main/java/io/floci/aws/core/common/AppUiHost.java new file mode 100644 index 0000000000..6b72581951 --- /dev/null +++ b/src/main/java/io/floci/aws/core/common/AppUiHost.java @@ -0,0 +1,58 @@ +package io.floci.aws.core.common; + +import java.net.URI; +import java.security.SecureRandom; +import java.util.Locale; + +/** + * The host of an application UI Floci opens through {@link AppUiProxy}, {@code -.