pan3793 commented on code in PR #6399:
URL: https://github.com/apache/kyuubi/pull/6399#discussion_r1608449823


##########
externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/ui/EngineTab.scala:
##########
@@ -53,49 +60,96 @@ case class EngineTab(
       .getOrElse(0L)
   }
 
+  private val enginePage = {
+    val dispatchMethod = classOf[EnginePage].getMethod("dispatchRender", 
classOf[AnyRef])
+    new ByteBuddy()
+      .subclass(classOf[EnginePage], 
ConstructorStrategy.Default.IMITATE_SUPER_CLASS_PUBLIC)
+      .method(isConstructor()).intercept(MethodCall.invokeSuper())
+      
.method(named("render")).intercept(MethodCall.invoke(dispatchMethod).withAllArguments())
+      .make()
+      .load(SparkUtils.getContextOrSparkClassLoader, 
ClassLoadingStrategy.Default.INJECTION)
+      .getLoaded
+      .getDeclaredConstructor(classOf[EngineTab])
+      .newInstance(this)
+  }
+
+  private val engineSessionPage = {
+    val dispatchMethod = 
classOf[EngineSessionPage].getMethod("dispatchRender", classOf[AnyRef])
+    new ByteBuddy()
+      .subclass(classOf[EngineSessionPage], 
ConstructorStrategy.Default.IMITATE_SUPER_CLASS_PUBLIC)
+      .method(isConstructor()).intercept(MethodCall.invokeSuper())
+      
.method(named("render")).intercept(MethodCall.invoke(dispatchMethod).withAllArguments())
+      .make()
+      .load(SparkUtils.getContextOrSparkClassLoader, 
ClassLoadingStrategy.Default.INJECTION)
+      .getLoaded
+      .getDeclaredConstructor(classOf[EngineTab])
+      .newInstance(this)
+  }
+
   sparkUI.foreach { ui =>
-    this.attachPage(EnginePage(this))
-    this.attachPage(EngineSessionPage(this))
+    this.attachPage(enginePage)
+    this.attachPage(engineSessionPage)
     ui.attachTab(this)
     Utils.addShutdownHook(() => ui.detachTab(this))
   }
 
   sparkUI.foreach { ui =>
     try {
-      // [KYUUBI #3627]: the official spark release uses the shaded and 
relocated jetty classes,
-      // but if we use sbt to build for testing, e.g. docker image, it still 
uses the vanilla
-      // jetty classes.
       val sparkServletContextHandlerClz = DynClasses.builder()
+        // for official Spark releases and distributions built via Maven
         .impl("org.sparkproject.jetty.servlet.ServletContextHandler")
+        // for distributions built via SBT
         .impl("org.eclipse.jetty.servlet.ServletContextHandler")
         .buildChecked()
       val attachHandlerMethod = DynMethods.builder("attachHandler")
         .impl("org.apache.spark.ui.SparkUI", sparkServletContextHandlerClz)
         .buildChecked(ui)
-      val createRedirectHandlerMethod = 
DynMethods.builder("createRedirectHandler")
-        .impl(
-          "org.apache.spark.ui.JettyUtils",
-          classOf[String],
-          classOf[String],
-          classOf[HttpServletRequest => Unit],
-          classOf[String],
-          classOf[Set[String]])
-        .buildStaticChecked()
-
-      attachHandlerMethod
-        .invoke(
+
+      if (SemanticVersion(SPARK_VERSION) >= "4.0") {

Review Comment:
   code branch is guarded by checking the runtime spark version to avoid 
loading non-existing classes, e.g. there is no 
`jakarta.servlet.http.HttpServletRequest` under Spark 3.5 classpath, 
ClassNotFound will be thrown if it goes this code branch unconditionally.



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