You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by fe...@apache.org on 2025/04/25 07:03:04 UTC

(kyuubi) branch master updated: [KYUUBI #7045] Expose jetty metrics

This is an automated email from the ASF dual-hosted git repository.

feiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new 4cbff4d192 [KYUUBI #7045] Expose jetty metrics
4cbff4d192 is described below

commit 4cbff4d192f75dd2a66b259c309d28f8c34f3e89
Author: Wang, Fei <fw...@ebay.com>
AuthorDate: Fri Apr 25 00:02:56 2025 -0700

    [KYUUBI #7045] Expose jetty metrics
    
    ### Why are the changes needed?
    
    Expose the jetty metrics to help detect issue.
    Refer: https://metrics.dropwizard.io/4.2.0/manual/jetty.html
    
    ### How was this patch tested?
    
    <img width="1425" alt="image" src="https://github.com/user-attachments/assets/ac8c9a48-eaa1-48ee-afec-6f33980d4270" />
    
    <img width="1283" alt="image" src="https://github.com/user-attachments/assets/c2fa444b-6337-4662-832b-3d02f206bd13" />
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    No.
    
    Closes #7045 from turboFei/metrics_jetty.
    
    Closes #7045
    
    122b93f3d [Wang, Fei] metrics
    45a73e7cd [Wang, Fei] metrics
    
    Authored-by: Wang, Fei <fw...@ebay.com>
    Signed-off-by: Wang, Fei <fw...@ebay.com>
---
 dev/dependencyList                                          |  2 ++
 .../scala/org/apache/kyuubi/metrics/MetricsConstants.scala  |  3 +++
 .../scala/org/apache/kyuubi/metrics/MetricsSystem.scala     |  2 ++
 kyuubi-server/pom.xml                                       |  5 +++++
 .../apache/kyuubi/server/KyuubiRestFrontendService.scala    |  6 ++++--
 .../authentication/KyuubiHttpAuthenticationFactory.scala    | 13 +++++++++++--
 pom.xml                                                     |  6 ++++++
 7 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/dev/dependencyList b/dev/dependencyList
index 9ffefe9302..8a3287471e 100644
--- a/dev/dependencyList
+++ b/dev/dependencyList
@@ -129,7 +129,9 @@ log4j-core/2.24.3//log4j-core-2.24.3.jar
 log4j-layout-template-json/2.24.3//log4j-layout-template-json-2.24.3.jar
 log4j-slf4j-impl/2.24.3//log4j-slf4j-impl-2.24.3.jar
 logging-interceptor/3.12.12//logging-interceptor-3.12.12.jar
+metrics-annotation/4.2.26//metrics-annotation-4.2.26.jar
 metrics-core/4.2.26//metrics-core-4.2.26.jar
+metrics-jetty9/4.2.26//metrics-jetty9-4.2.26.jar
 metrics-jmx/4.2.26//metrics-jmx-4.2.26.jar
 metrics-json/4.2.26//metrics-json-4.2.26.jar
 metrics-jvm/4.2.26//metrics-jvm-4.2.26.jar
diff --git a/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsConstants.scala b/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsConstants.scala
index 40f8b7c394..4afd7246e6 100644
--- a/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsConstants.scala
+++ b/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsConstants.scala
@@ -95,4 +95,7 @@ object MetricsConstants {
   final val METADATA_REQUEST_TOTAL = METADATA_REQUEST + "total"
   final val METADATA_REQUEST_FAIL = METADATA_REQUEST + "failed"
   final val METADATA_REQUEST_RETRYING = METADATA_REQUEST + "retrying"
+
+  final private val JETTY = KYUUBI + "jetty."
+  final val JETTY_API_V1 = JETTY + "api.v1"
 }
diff --git a/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala b/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala
index 6df0713bb5..e1ac527c0c 100644
--- a/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala
+++ b/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala
@@ -105,6 +105,8 @@ object MetricsSystem {
 
   @volatile private var maybeSystem: Option[MetricsSystem] = None
 
+  private[kyuubi] def getMetricsRegistry: Option[MetricRegistry] = maybeSystem.map(_.registry)
+
   def tracing[T](func: MetricsSystem => T): Unit = {
     maybeSystem.foreach(func(_))
   }
diff --git a/kyuubi-server/pom.xml b/kyuubi-server/pom.xml
index 638dcbda64..303d144106 100644
--- a/kyuubi-server/pom.xml
+++ b/kyuubi-server/pom.xml
@@ -218,6 +218,11 @@
             <artifactId>jetty-proxy</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>io.dropwizard.metrics</groupId>
+            <artifactId>metrics-jetty9</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.glassfish.jersey.test-framework</groupId>
             <artifactId>jersey-test-framework-core</artifactId>
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
index b93dcf7b5b..7fa111c7ff 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
@@ -31,8 +31,8 @@ import org.eclipse.jetty.servlet.{ErrorPageErrorHandler, FilterHolder}
 import org.apache.kyuubi.{KyuubiException, Utils}
 import org.apache.kyuubi.config.KyuubiConf
 import org.apache.kyuubi.config.KyuubiConf._
+import org.apache.kyuubi.metrics.{MetricsConstants, MetricsSystem}
 import org.apache.kyuubi.metrics.MetricsConstants.OPERATION_BATCH_PENDING_MAX_ELAPSE
-import org.apache.kyuubi.metrics.MetricsSystem
 import org.apache.kyuubi.server.api.v1.ApiRootResource
 import org.apache.kyuubi.server.http.authentication.{AuthenticationFilter, KyuubiHttpAuthenticationFactory}
 import org.apache.kyuubi.server.ui.{JettyServer, JettyUtils}
@@ -118,7 +118,9 @@ class KyuubiRestFrontendService(override val serverable: Serverable)
     val holder = new FilterHolder(new AuthenticationFilter(conf))
     contextHandler.addFilter(holder, "/v1/*", EnumSet.allOf(classOf[DispatcherType]))
     val authenticationFactory = new KyuubiHttpAuthenticationFactory(conf)
-    server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(contextHandler))
+    server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(
+      contextHandler,
+      Some(MetricsConstants.JETTY_API_V1)))
 
     val proxyHandler = ApiRootResource.getEngineUIProxyHandler(this)
     server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(proxyHandler))
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/authentication/KyuubiHttpAuthenticationFactory.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/authentication/KyuubiHttpAuthenticationFactory.scala
index ee8dd3989d..24fa52b01e 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/authentication/KyuubiHttpAuthenticationFactory.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/authentication/KyuubiHttpAuthenticationFactory.scala
@@ -20,6 +20,7 @@ package org.apache.kyuubi.server.http.authentication
 import java.security.PrivilegedAction
 import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
 
+import com.codahale.metrics.jetty9.InstrumentedHandler
 import org.apache.hadoop.security.UserGroupInformation
 import org.eclipse.jetty.server.{Handler, Request}
 import org.eclipse.jetty.server.handler.HandlerWrapper
@@ -44,8 +45,8 @@ class KyuubiHttpAuthenticationFactory(conf: KyuubiConf) {
     new HttpHandlerWrapperFactory(ugi, kerberosEnabled)
 
   class HttpHandlerWrapperFactory(ugi: UserGroupInformation, kerberosEnabled: Boolean) {
-    def wrapHandler(handler: Handler): HandlerWrapper = {
-      new HandlerWrapper {
+    def wrapHandler(handler: Handler, metricPrefix: Option[String] = None): HandlerWrapper = {
+      val handlerWrapper = new HandlerWrapper {
         _handler = handler
 
         override def handle(
@@ -91,6 +92,14 @@ class KyuubiHttpAuthenticationFactory(conf: KyuubiConf) {
           handler.start()
         }
       }
+
+      (MetricsSystem.getMetricsRegistry, metricPrefix) match {
+        case (Some(metricRegistry), Some(prefix)) =>
+          val instrumentedHandler = new InstrumentedHandler(metricRegistry, prefix)
+          instrumentedHandler.setHandler(handlerWrapper)
+          instrumentedHandler
+        case _ => handlerWrapper
+      }
     }
   }
 }
diff --git a/pom.xml b/pom.xml
index 05283418ae..17f2371401 100644
--- a/pom.xml
+++ b/pom.xml
@@ -693,6 +693,12 @@
                 <version>${codahale.metrics.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>io.dropwizard.metrics</groupId>
+                <artifactId>metrics-jetty9</artifactId>
+                <version>${codahale.metrics.version}</version>
+            </dependency>
+
             <dependency>
                 <groupId>com.fasterxml.jackson.core</groupId>
                 <artifactId>jackson-annotations</artifactId>