samra-h commented on code in PR #58965:
URL: https://github.com/apache/spark/pull/58965#discussion_r4524789179


##########
core/src/main/scala/org/apache/spark/status/AppHistoryServerPlugin.scala:
##########
@@ -36,8 +44,82 @@ private[spark] trait AppHistoryServerPlugin {
    */
   def setupUI(ui: SparkUI): Unit
 
+  /**
+   * Static resources (JS/CSS) to serve from the History Server's own UI, as 
(classpath resource
+   * directory, URL path) pairs. They are registered once at startup. The URL 
path must be under
+   * /static/; other paths are rejected so they cannot shadow the History 
Server's own routes.
+   * The directory is resolved with Spark's class loader, not the plugin's, so 
it must be on
+   * Spark's class path. Unlike a handler attached in [[setupUI]], which is 
torn down when the
+   * application cache evicts that application, these live as long as the 
History Server.
+   *
+   * This does not replace the registration in [[setupUI]] or in the tabs: the 
live driver UI
+   * never calls this hook, so tabs must still register their own handlers.
+   */
+  def staticResources: Seq[(String, String)] = Nil
+
   /**
    * The position of a plugin tab relative to the other plugin tabs in the 
history UI.
    */
   def displayOrder: Int = Integer.MAX_VALUE
 }
+
+private[spark] object AppHistoryServerPlugin extends Logging {
+
+  // Consecutive load failures tolerated before giving up on the remaining 
plugins
+  private[spark] val MAX_LOAD_FAILURES = 10
+
+  /**
+   * Loads the available plugins, skipping with a warning any that cannot be 
loaded, so that a
+   * broken plugin does not take down the History Server or the loading of an 
application UI.
+   */
+  def loadPlugins(): Seq[AppHistoryServerPlugin] = 
skipUnloadable(loadPluginsOrFail())
+
+  /**
+   * Lazily loads the available plugins. A plugin that cannot be loaded makes 
iteration throw.
+   * Use this where a missing plugin must not go unnoticed.
+   */
+  def loadPluginsOrFail(): Iterable[AppHistoryServerPlugin] = {
+    ServiceLoader.load(classOf[AppHistoryServerPlugin], 
Utils.getContextOrSparkClassLoader).asScala
+  }
+
+  /**
+   * Iterates through the plugins and attempts to load them one by one. If a 
plugin
+   * fails to load, it increments a failure counter. If the number of 
consecutive failures reaches
+   * MAX_LOAD_FAILURES, the loading process is aborted and remaining plugins 
are skipped.
+   *
+   * @param plugins an iterable collection of AppHistoryServerPlugin instances 
to load
+   * @return a sequence of successfully loaded AppHistoryServerPlugin instances
+   *
+   * @note This method will stop loading after MAX_LOAD_FAILURES consecutive 
failures to prevent
+   *       infinite loops or excessive error conditions
+   * @note Successfully loading a plugin resets the consecutive failure counter
+   * @note Non-fatal exceptions and LinkageErrors are caught and logged as 
warnings
+   */
+  private[spark] def skipUnloadable(

Review Comment:
   Thanks. Agreed, I'll leave skipUnloadable as is in this PR and open a 
follow-up JIRA to make it a generic Utils helper for all four copies, with the 
SparkSession callback and the log levels as noted. Link:
   https://issues.apache.org/jira/browse/SPARK-61365



-- 
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