This is an automated email from the ASF dual-hosted git repository.
feiwang pushed a commit to branch branch-1.10
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/branch-1.10 by this push:
new a7d2ac43e6 [KYUUBI #7045] Expose jetty metrics
a7d2ac43e6 is described below
commit a7d2ac43e614a280748db0e90157d75f467a3594
Author: Wang, Fei <[email protected]>
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 <[email protected]>
Signed-off-by: Wang, Fei <[email protected]>
(cherry picked from commit 4cbff4d192f75dd2a66b259c309d28f8c34f3e89)
Signed-off-by: Wang, Fei <[email protected]>
---
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 6945adbb9c..a9d5849b29 100644
--- a/dev/dependencyList
+++ b/dev/dependencyList
@@ -128,7 +128,9 @@ log4j-api/2.20.0//log4j-api-2.20.0.jar
log4j-core/2.20.0//log4j-core-2.20.0.jar
log4j-slf4j-impl/2.20.0//log4j-slf4j-impl-2.20.0.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 814cac535e..13c73cff97 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 f312c7a60e..3786a1999e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -687,6 +687,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>