dongjoon-hyun commented on code in PR #60135:
URL: https://github.com/apache/spark/pull/60135#discussion_r4484136395
##########
core/src/main/scala/org/apache/spark/status/api/v1/ApiRootResource.scala:
##########
@@ -61,7 +61,18 @@ private[spark] object ApiRootResource {
val jerseyContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
jerseyContext.setContextPath("/api")
val holder: ServletHolder = new ServletHolder(classOf[ServletContainer])
- holder.setInitParameter(ServerProperties.PROVIDER_PACKAGES,
"org.apache.spark.status.api.v1")
+ // Register the JAX-RS resources explicitly by class name instead of
scanning
+ // the package. Package scanning (PROVIDER_PACKAGES) relies on the
classpath
+ // being enumerable from the filesystem, which fails when spark-core is
loaded
+ // from a non-scannable location (e.g. an OSGi bundle where resources are
+ // exposed as "bundleresource://" URLs, or a shaded/modular classpath). The
+ // root resource ApiRootResource and the JacksonMessageWriter provider are
+ // sufficient; all nested resources are reached via sub-resource locators.
+ holder.setInitParameter(
Review Comment:
**[1] This drops the SQL, streaming and Connect REST endpoints on a standard
classpath.** `PROVIDER_PACKAGES` scanning is recursive by default in Jersey
3.1.11 (`ResourceConfig.scanClasses()` sets `recursive = true` when
`PROVIDER_SCANNING_RECURSIVE` is unset), so it also registered three more
`@Path("/v1")` root resources from other modules, in subpackages of this one:
- `ApiSqlRootResource` (sql/core, `org.apache.spark.status.api.v1.sql`)
- `ApiStreamingApp` (streaming, `org.apache.spark.status.api.v1.streaming`)
- `ApiConnectRootResource` (sql/connect/server,
`org.apache.spark.status.api.v1.connect`)
Nothing else references these classes, so the scan is their only
registration path. With only `ApiRootResource` and `JacksonMessageWriter`
listed, `/api/v1/applications/<app-id>/sql`, `.../sql/<execution-id>` and
`.../sql/sqlTable` return 404. `allexecutionspage.js` and `executionpage.js`
call them through `createSqlApiBase`, so the SQL / DataFrame tab stops loading,
and the `/streaming/...` and `/connect/...` endpoints documented in
docs/monitoring.md disappear too.
I have not run it, but I expect `SqlResourceWithActualMetricsSuite`,
`AllExecutionsPageSuite` ("SPARK-56137: REST API returns data after SQL
queries"), the sql `UISeleniumSuite` and `ConnectResourceWithActualDataSuite`
to fail; streaming has no REST test, so that part would break silently. The
comment at L69-70 and the PR description say the opposite. Could you keep these
root resources registered (see [5] for options) and fix the comment?
##########
core/src/main/scala/org/apache/spark/status/api/v1/PrometheusResource.scala:
##########
@@ -113,7 +113,18 @@ private[spark] object PrometheusResource {
val jerseyContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
jerseyContext.setContextPath("/metrics")
val holder: ServletHolder = new ServletHolder(classOf[ServletContainer])
- holder.setInitParameter(ServerProperties.PROVIDER_PACKAGES,
"org.apache.spark.status.api.v1")
+ // Register the JAX-RS resources explicitly by class name instead of
scanning
+ // the package. Package scanning (PROVIDER_PACKAGES) relies on the
classpath
+ // being enumerable from the filesystem, which fails when spark-core is
loaded
+ // from a non-scannable location (e.g. an OSGi bundle where resources are
+ // exposed as "bundleresource://" URLs, or a shaded/modular classpath). The
+ // root resource PrometheusResource and the JacksonMessageWriter provider
are
+ // sufficient for this endpoint.
+ holder.setInitParameter(
Review Comment:
**[3] This also removes two routes, which is a user-facing change.** Today
each context scans the whole package, so both register every root resource:
`/api/executors/prometheus` is served even with
`spark.ui.prometheus.enabled=false`, and `/metrics/v1/...` mirrors the REST
API. After this PR both return 404, while the PR description says there is no
user-facing change. Dropping them looks reasonable to me (on the History
Server, `/api/executors/prometheus` already fails at
`uiRoot.asInstanceOf[SparkUI]`), but a scraper pointed at
`/api/executors/prometheus` would break on upgrade. Could you describe this in
the PR description, pin the new routing in a test, and consider a migration
guide note?
##########
core/src/main/scala/org/apache/spark/status/api/v1/PrometheusResource.scala:
##########
@@ -113,7 +113,18 @@ private[spark] object PrometheusResource {
val jerseyContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
jerseyContext.setContextPath("/metrics")
val holder: ServletHolder = new ServletHolder(classOf[ServletContainer])
- holder.setInitParameter(ServerProperties.PROVIDER_PACKAGES,
"org.apache.spark.status.api.v1")
+ // Register the JAX-RS resources explicitly by class name instead of
scanning
+ // the package. Package scanning (PROVIDER_PACKAGES) relies on the
classpath
+ // being enumerable from the filesystem, which fails when spark-core is
loaded
+ // from a non-scannable location (e.g. an OSGi bundle where resources are
+ // exposed as "bundleresource://" URLs, or a shaded/modular classpath). The
+ // root resource PrometheusResource and the JacksonMessageWriter provider
are
+ // sufficient for this endpoint.
+ holder.setInitParameter(
+ ServerProperties.PROVIDER_CLASSNAMES,
+ Seq(
+ classOf[PrometheusResource].getName,
+ classOf[JacksonMessageWriter].getName).mkString(","))
Review Comment:
**[8] Nit: `JacksonMessageWriter` is never selected on `/metrics`.** The
only endpoint returns a `String` with `@Produces(TEXT_PLAIN)`, and
`UIUtils.buildErrorResponse` also uses `TEXT_PLAIN`, while
`JacksonMessageWriter` is `@Produces(APPLICATION_JSON)`. Could you register
only `PrometheusResource` here and drop "and the JacksonMessageWriter provider
are sufficient" from the comment, so the minimal set is explicit?
##########
core/src/main/scala/org/apache/spark/status/api/v1/PrometheusResource.scala:
##########
@@ -113,7 +113,18 @@ private[spark] object PrometheusResource {
val jerseyContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
jerseyContext.setContextPath("/metrics")
val holder: ServletHolder = new ServletHolder(classOf[ServletContainer])
- holder.setInitParameter(ServerProperties.PROVIDER_PACKAGES,
"org.apache.spark.status.api.v1")
+ // Register the JAX-RS resources explicitly by class name instead of
scanning
+ // the package. Package scanning (PROVIDER_PACKAGES) relies on the
classpath
+ // being enumerable from the filesystem, which fails when spark-core is
loaded
+ // from a non-scannable location (e.g. an OSGi bundle where resources are
+ // exposed as "bundleresource://" URLs, or a shaded/modular classpath). The
+ // root resource PrometheusResource and the JacksonMessageWriter provider
are
+ // sufficient for this endpoint.
+ holder.setInitParameter(
+ ServerProperties.PROVIDER_CLASSNAMES,
+ Seq(
Review Comment:
**[4] Could you add a regression test for the new registration?** The only
test listed, `HistoryServerSuite`, never attaches the `/metrics` handler
(`HistoryServer` does not call `PrometheusResource.getServletHandler`), and no
suite requests `/metrics/executors/prometheus` over HTTP, so a mis-registration
here would pass CI. The streaming part of [1] has no REST test at all. A test
on a live `SparkUI` with `spark.ui.prometheus.enabled=true` that requests
`/api/v1/version` and `/metrics/executors/prometheus`, plus a streaming REST
test, would cover both.
##########
core/src/main/scala/org/apache/spark/status/api/v1/ApiRootResource.scala:
##########
@@ -61,7 +61,18 @@ private[spark] object ApiRootResource {
val jerseyContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
jerseyContext.setContextPath("/api")
val holder: ServletHolder = new ServletHolder(classOf[ServletContainer])
- holder.setInitParameter(ServerProperties.PROVIDER_PACKAGES,
"org.apache.spark.status.api.v1")
+ // Register the JAX-RS resources explicitly by class name instead of
scanning
+ // the package. Package scanning (PROVIDER_PACKAGES) relies on the
classpath
+ // being enumerable from the filesystem, which fails when spark-core is
loaded
+ // from a non-scannable location (e.g. an OSGi bundle where resources are
+ // exposed as "bundleresource://" URLs, or a shaded/modular classpath). The
+ // root resource ApiRootResource and the JacksonMessageWriter provider are
+ // sufficient; all nested resources are reached via sub-resource locators.
+ holder.setInitParameter(
+ ServerProperties.PROVIDER_CLASSNAMES,
+ Seq(
Review Comment:
**[5] A hard-coded class list in core cannot know about root resources from
other modules or downstream jars.** `org.apache.spark.status.api.v1` and its
subpackages work as a de facto extension point: besides sql, streaming and
Connect, downstream projects add root resources there and rely on the scan,
e.g. `SnappyApiRootResource` in TIBCOSoftware/snappydata and
`ExecutorNumResource` in Qihoo360/XSQL. Could you fix how resources are
contributed instead of listing core's own classes? Some options:
1. a registration hook, e.g. `ServiceLoader`, or `SQLTab`, `StreamingTab`
and `SparkConnectServerTab` registering their own root resource;
2. also listing the known optional module classes by name (Jersey skips
missing ones, though see [2]);
3. keeping `PROVIDER_PACKAGES` and falling back to explicit classes only
when scanning fails;
4. fixing it in the embedding environment, since Jersey has its own OSGi
support (`OsgiRegistry`, `BundleSchemeResourceFinderFactory`).
##########
core/src/main/scala/org/apache/spark/status/api/v1/ApiRootResource.scala:
##########
@@ -61,7 +61,18 @@ private[spark] object ApiRootResource {
val jerseyContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
jerseyContext.setContextPath("/api")
val holder: ServletHolder = new ServletHolder(classOf[ServletContainer])
- holder.setInitParameter(ServerProperties.PROVIDER_PACKAGES,
"org.apache.spark.status.api.v1")
+ // Register the JAX-RS resources explicitly by class name instead of
scanning
+ // the package. Package scanning (PROVIDER_PACKAGES) relies on the
classpath
+ // being enumerable from the filesystem, which fails when spark-core is
loaded
+ // from a non-scannable location (e.g. an OSGi bundle where resources are
+ // exposed as "bundleresource://" URLs, or a shaded/modular classpath). The
+ // root resource ApiRootResource and the JacksonMessageWriter provider are
+ // sufficient; all nested resources are reached via sub-resource locators.
+ holder.setInitParameter(
+ ServerProperties.PROVIDER_CLASSNAMES,
Review Comment:
**[2] On OSGi or JPMS, `PROVIDER_CLASSNAMES` can fail with no visible
error.** Jersey loads each name through the class loader of
`ResourceConfig.State`, which is the thread context class loader captured when
the `ResourceConfig` is created, and `scanClasses()` catches
`ClassNotFoundException` and logs it only at `Level.CONFIG`, below JUL's
default `INFO`. In the OSGi setups this PR targets, the TCCL at servlet init is
not necessarily the spark-core bundle loader, so Jersey would start with no
resources and every `/api/v1` request would return 404 with nothing in the
logs. That is harder to diagnose than the current `ResourceFinderException`.
Could you pass the `Class` objects instead of names, e.g. `new
ServletHolder(new ServletContainer(new ResourceConfig(classOf[ApiRootResource],
classOf[JacksonMessageWriter])))`? The same applies to
PrometheusResource.scala:124.
##########
core/src/main/scala/org/apache/spark/status/api/v1/ApiRootResource.scala:
##########
@@ -61,7 +61,18 @@ private[spark] object ApiRootResource {
val jerseyContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
jerseyContext.setContextPath("/api")
val holder: ServletHolder = new ServletHolder(classOf[ServletContainer])
- holder.setInitParameter(ServerProperties.PROVIDER_PACKAGES,
"org.apache.spark.status.api.v1")
+ // Register the JAX-RS resources explicitly by class name instead of
scanning
+ // the package. Package scanning (PROVIDER_PACKAGES) relies on the
classpath
+ // being enumerable from the filesystem, which fails when spark-core is
loaded
+ // from a non-scannable location (e.g. an OSGi bundle where resources are
+ // exposed as "bundleresource://" URLs, or a shaded/modular classpath). The
+ // root resource ApiRootResource and the JacksonMessageWriter provider are
+ // sufficient; all nested resources are reached via sub-resource locators.
+ holder.setInitParameter(
+ ServerProperties.PROVIDER_CLASSNAMES,
+ Seq(
+ classOf[ApiRootResource].getName,
+ classOf[JacksonMessageWriter].getName).mkString(","))
Review Comment:
**[6] Minor: the `JacksonMessageWriter` scaladoc becomes stale.**
JacksonMessageWriter.scala:38 still says "Note that jersey automatically
discovers this class based on its package and its annotations.", which is no
longer true after this change. Someone adding a new `@Provider` next to it
(e.g. an `ExceptionMapper`) could trust that note and never register it.
JacksonMessageWriter.scala is outside this diff, so I left this here. Could you
update that note to point at the registration here?
##########
core/src/main/scala/org/apache/spark/status/api/v1/PrometheusResource.scala:
##########
@@ -113,7 +113,18 @@ private[spark] object PrometheusResource {
val jerseyContext = new
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
jerseyContext.setContextPath("/metrics")
val holder: ServletHolder = new ServletHolder(classOf[ServletContainer])
- holder.setInitParameter(ServerProperties.PROVIDER_PACKAGES,
"org.apache.spark.status.api.v1")
+ // Register the JAX-RS resources explicitly by class name instead of
scanning
Review Comment:
**[7] Minor: this comment and the `setInitParameter` block are copied almost
verbatim from ApiRootResource.scala:64-75.** The two `getServletHandler`
methods already differed only in the context path and the resource class, and
now any fix (e.g. for [1] or [2]) has to be made in both. Could you move them
into a shared `private[v1]` helper, e.g. `createJerseyHandler(contextPath:
String, uiRoot: UIRoot, classes: Class[_]*)`, so the comment and the logic live
in one place?
--
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]