dongjoon-hyun opened a new pull request, #60591:
URL: https://github.com/apache/spark/pull/60591

   ### What changes were proposed in this pull request?
   
   This PR passes `basePath` to the four redirect handlers of the 
state-changing actions in `SparkUI`: `/jobs/job/kill`, `/stages/stage/kill`, 
`/jobs/hold` and `/jobs/resume`. The root redirect handler right above them 
already does this.
   
   ```scala
   attachHandler(createRedirectHandler("/", "/jobs/", basePath = basePath))
   ```
   
   With `basePath`, `JettyUtils.createRedirectHandler` uses `basePath + 
srcPath` as the context path and redirects to `basePath + destPath`.
   
   ### Why are the changes needed?
   
   The History Server creates the `SparkUI` of an application with `basePath` 
set to `/history/<appId>[/<attemptId>]`. When it loads the application, it 
attaches all handlers of that UI to its own server 
(`HistoryServer.attachSparkUI`). Because these four handlers ignore `basePath`, 
they are attached at global paths like `/jobs/job/kill/` instead of 
`/history/<appId>/jobs/job/kill/`.
   
   As a result, what the History Server returns for these global paths depends 
on its application cache.
   - With no application loaded, the History Server's own root page handler 
answers them, and `POST` returns 405.
   - While any application is loaded, a loaded application's handler answers 
them. `POST` returns 403 for the missing CSRF token, and `GET` returns 405.
   
   The redirect targets are global as well: `/jobs/` and `/stages/` lead to the 
History Server's application list instead of the application's own pages.
   
   This has no functional impact. Kill and hold are disabled in the History 
Server because its UIs have no `SparkContext`, and the UI renders the kill and 
hold forms only when they are enabled, with actions that are already prefixed 
with `basePath`. The kill handlers have ignored `basePath` since they were 
added (SPARK-1386 and SPARK-4411), and the hold and resume handlers 
(SPARK-58828) followed the same pattern.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. The live UI is unchanged because its `basePath` is empty. In the History 
Server, these endpoints do nothing either way, and they are now attached only 
under `/history/<appId>/`.
   
   ### How was this patch tested?
   
   Pass the CIs with the newly added test case in `HistoryServerSuite`. It 
starts a new History Server, records the response codes of `POST` requests to 
the four global paths, loads an application, and checks that the codes do not 
change. Without this fix, the test fails like the following.
   
   ```
   [info] - SPARK-61841: app UI action endpoints are not attached at global 
paths *** FAILED ***
   [info]   List(403, 403, 403, 403) did not equal List(405, 405, 405, 405)
   ```
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to