samra-h opened a new pull request, #60350: URL: https://github.com/apache/spark/pull/60350
### Jira ticket https://issues.apache.org/jira/browse/SPARK-59613 ### What changes were proposed in this pull request? This PR fixes intermittent 404 responses for `/static/sql/*` requests in the Spark History Server (SHS). These 404s stop the SQL tab's ExecutionPage plan visualization from rendering its graphs. This PR is alternative implementation for #58965. That PR added a History Server-level handler for `/static/sql` through a new `AppHistoryServerPlugin` hook. This PR removes the need for any separate handler by moving the SQL UI's static files under core's existing static resource directory: - Moves the five SQL UI static files from `sql/core/src/main/resources/org/apache/spark/sql/execution/ui/static/` to `core/src/main/resources/org/apache/spark/ui/static/sql/`, with no content changes: - `allexecutionspage.js` - `executionpage.js` - `spark-sql-viz.css` - `spark-sql-viz.js` - `sql-table-utils.js` - Removes the per-application `addStaticHandler(..., "/static/sql")` calls, and their `STATIC_RESOURCE_DIR` constants, from `SQLTab` and `StreamingQueryTab`. - Updates `dev/lint-js` and `ui-test/tests/spark-sql-viz.test.js` to the new location. The URLs don't change. `ExecutionPage`, `AllExecutionsPage` and `spark-sql-viz.js` still load `/static/sql/<file>`. Those requests are now answered by the core `/static` handler, which every `SparkUI` (`SparkUI.initialize`) and the History Server (`HistoryServer.initialize`) register at startup. The `sql/` subdirectory maps to `/static/sql/`. ### Why are the changes needed? The SparkSQL ExecutionPage intermittently rendered no execution graphs, and browser network logs showed `GET /static/sql/...` returning 404. Because `/static/sql` only existed while some SQL- or streaming-bearing application UI was loaded, it disappeared when that application was evicted from `ApplicationCache`. `/static/sql/*` then returned 404 until another such application was loaded. This is much worse in multi-pod SHS deployments. Each pod has its own `ApplicationCache` and its own per-application handlers. The core `/static` handler exists on every pod, but `/static/sql` existed only on pods that currently had a matching application loaded. One browser page load fans out across pods: the ExecutionPage HTML can come from a pod that has the handler, while the follow-up `/static/sql/*` request goes to a pod that doesn't, which produces the seemingly random 404s. This is also why opening the SQL tab once was only an unreliable, temporary workaround: it registered the handler on one pod, until the next eviction. ### Does this PR introduce _any_ user-facing change? Yes, a bug fix. In the History Server, the SparkSQL ExecutionPage graphs now render reliably, because `/static/sql/*` is always served. Related behavior changes: - Access control. /static/sql/* is now served by the same /static handler as other core assets, so it follows the same rules as them. Previously, in the History Server, it was registered per application and went through that application's UI, so it could behave differently from other static files, for example when spark.history.ui.acls.enable=true. - Packaging. The five files now ship in spark-core instead of spark-sql. A live driver UI serves /static/sql/* even when the application has no SQL tab. They are inert UI assets, and no page that uses them changes. No API, configuration, or output format changes. ### How was this patch tested? Two new unit tests in core. Neither has a SQL plugin or SQL tab on its classpath, so nothing else registers a /static/sql handler. The requests can only be served by the core /static handler. Before this change, they returned 404. - HistoryServerSuite: "/static/sql resources are served on startup without loading any app" starts a History Server without opening any application. It checks that GET /static/sql/<file> returns 200 with a non-empty body for spark-sql-viz.css and spark-sql-viz.js. This covers the History Server case. - UISuite: "/static/sql resources are served by the core static handler" starts a live SparkUI and makes the same requests. This covers the driver UI case. Existing checks updated for the new location: `dev/lint-js`, and `ui-test/tests/spark-sql-viz.test.js`. Manually verified against a live multi-pod SHS deployment (6 History Server pods behind a Service/load balancer). <img width="768" height="363" alt="Screenshot 2026-09-21 at 22 43 53" src="https://github.com/user-attachments/assets/86fd925c-3b12-47dd-b650-02be58136957" /> #### Reproduction of the bug (before the fix): - Restarted the SHS pods. - Opened the SparkSQL plan visualization in the SHS UI. The execution graph failed to render. <img width="1281" height="321" alt="Screenshot 2026-09-21 at 22 38 17" src="https://github.com/user-attachments/assets/4f6a1cc4-a4db-4e32-bba3-693ef953f8e7" /> - Checked each of the 6 pods for the `/static/sql` static-resource registration. The handler was registered on only one pod. <img width="1028" height="577" alt="Screenshot 2026-09-21 at 22 08 27" src="https://github.com/user-attachments/assets/6bf89f6f-b7aa-415e-919d-8e0b6b43c784" /> - Concluded that the load balancer was routing the graph-rendering request to one of the "cold" pods with no `/static/sql` handler, which caused the 404 and the missing graph. #### Verification (after the fix): - Restarted the SHS pods again. - Checked all 6 pods for the `/static/sql` static-resource registration. It was present on all 6 immediately on startup, with no SQL-bearing application loaded. <img width="996" height="591" alt="Screenshot 2026-09-21 at 22 43 10" src="https://github.com/user-attachments/assets/423a418b-c1de-446e-98e5-829dca2f6ee3" /> - Repeatedly opened the SparkSQL plan visualization in the SHS UI and could not reproduce the missing-graph bug. The execution graph rendered every time, regardless of which pod served the request. <img width="1277" height="781" alt="Screenshot 2026-09-21 at 22 44 38" src="https://github.com/user-attachments/assets/ea14ce47-5a45-4c55-86d1-bae1af402a8f" /> ### Was this patch authored or co-authored using generative AI tooling? <!-- Update this if any of the review fixes, tests, or this description were written with AI assistance, e.g. "Generated-by: <tool and version>". Otherwise keep "No". --> No -- 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]
