Skip to content

Commit 4cbff4d

Browse files
committed
[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 122b93f [Wang, Fei] metrics 45a73e7 [Wang, Fei] metrics Authored-by: Wang, Fei <[email protected]> Signed-off-by: Wang, Fei <[email protected]>
1 parent 3e638b6 commit 4cbff4d

File tree

7 files changed

+33
-4
lines changed

7 files changed

+33
-4
lines changed

dev/dependencyList

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ log4j-core/2.24.3//log4j-core-2.24.3.jar
129129
log4j-layout-template-json/2.24.3//log4j-layout-template-json-2.24.3.jar
130130
log4j-slf4j-impl/2.24.3//log4j-slf4j-impl-2.24.3.jar
131131
logging-interceptor/3.12.12//logging-interceptor-3.12.12.jar
132+
metrics-annotation/4.2.26//metrics-annotation-4.2.26.jar
132133
metrics-core/4.2.26//metrics-core-4.2.26.jar
134+
metrics-jetty9/4.2.26//metrics-jetty9-4.2.26.jar
133135
metrics-jmx/4.2.26//metrics-jmx-4.2.26.jar
134136
metrics-json/4.2.26//metrics-json-4.2.26.jar
135137
metrics-jvm/4.2.26//metrics-jvm-4.2.26.jar

kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsConstants.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,7 @@ object MetricsConstants {
9595
final val METADATA_REQUEST_TOTAL = METADATA_REQUEST + "total"
9696
final val METADATA_REQUEST_FAIL = METADATA_REQUEST + "failed"
9797
final val METADATA_REQUEST_RETRYING = METADATA_REQUEST + "retrying"
98+
99+
final private val JETTY = KYUUBI + "jetty."
100+
final val JETTY_API_V1 = JETTY + "api.v1"
98101
}

kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/MetricsSystem.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ object MetricsSystem {
105105

106106
@volatile private var maybeSystem: Option[MetricsSystem] = None
107107

108+
private[kyuubi] def getMetricsRegistry: Option[MetricRegistry] = maybeSystem.map(_.registry)
109+
108110
def tracing[T](func: MetricsSystem => T): Unit = {
109111
maybeSystem.foreach(func(_))
110112
}

kyuubi-server/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@
218218
<artifactId>jetty-proxy</artifactId>
219219
</dependency>
220220

221+
<dependency>
222+
<groupId>io.dropwizard.metrics</groupId>
223+
<artifactId>metrics-jetty9</artifactId>
224+
</dependency>
225+
221226
<dependency>
222227
<groupId>org.glassfish.jersey.test-framework</groupId>
223228
<artifactId>jersey-test-framework-core</artifactId>

kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import org.eclipse.jetty.servlet.{ErrorPageErrorHandler, FilterHolder}
3131
import org.apache.kyuubi.{KyuubiException, Utils}
3232
import org.apache.kyuubi.config.KyuubiConf
3333
import org.apache.kyuubi.config.KyuubiConf._
34+
import org.apache.kyuubi.metrics.{MetricsConstants, MetricsSystem}
3435
import org.apache.kyuubi.metrics.MetricsConstants.OPERATION_BATCH_PENDING_MAX_ELAPSE
35-
import org.apache.kyuubi.metrics.MetricsSystem
3636
import org.apache.kyuubi.server.api.v1.ApiRootResource
3737
import org.apache.kyuubi.server.http.authentication.{AuthenticationFilter, KyuubiHttpAuthenticationFactory}
3838
import org.apache.kyuubi.server.ui.{JettyServer, JettyUtils}
@@ -118,7 +118,9 @@ class KyuubiRestFrontendService(override val serverable: Serverable)
118118
val holder = new FilterHolder(new AuthenticationFilter(conf))
119119
contextHandler.addFilter(holder, "/v1/*", EnumSet.allOf(classOf[DispatcherType]))
120120
val authenticationFactory = new KyuubiHttpAuthenticationFactory(conf)
121-
server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(contextHandler))
121+
server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(
122+
contextHandler,
123+
Some(MetricsConstants.JETTY_API_V1)))
122124

123125
val proxyHandler = ApiRootResource.getEngineUIProxyHandler(this)
124126
server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(proxyHandler))

kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/authentication/KyuubiHttpAuthenticationFactory.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package org.apache.kyuubi.server.http.authentication
2020
import java.security.PrivilegedAction
2121
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
2222

23+
import com.codahale.metrics.jetty9.InstrumentedHandler
2324
import org.apache.hadoop.security.UserGroupInformation
2425
import org.eclipse.jetty.server.{Handler, Request}
2526
import org.eclipse.jetty.server.handler.HandlerWrapper
@@ -44,8 +45,8 @@ class KyuubiHttpAuthenticationFactory(conf: KyuubiConf) {
4445
new HttpHandlerWrapperFactory(ugi, kerberosEnabled)
4546

4647
class HttpHandlerWrapperFactory(ugi: UserGroupInformation, kerberosEnabled: Boolean) {
47-
def wrapHandler(handler: Handler): HandlerWrapper = {
48-
new HandlerWrapper {
48+
def wrapHandler(handler: Handler, metricPrefix: Option[String] = None): HandlerWrapper = {
49+
val handlerWrapper = new HandlerWrapper {
4950
_handler = handler
5051

5152
override def handle(
@@ -91,6 +92,14 @@ class KyuubiHttpAuthenticationFactory(conf: KyuubiConf) {
9192
handler.start()
9293
}
9394
}
95+
96+
(MetricsSystem.getMetricsRegistry, metricPrefix) match {
97+
case (Some(metricRegistry), Some(prefix)) =>
98+
val instrumentedHandler = new InstrumentedHandler(metricRegistry, prefix)
99+
instrumentedHandler.setHandler(handlerWrapper)
100+
instrumentedHandler
101+
case _ => handlerWrapper
102+
}
94103
}
95104
}
96105
}

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,12 @@
693693
<version>${codahale.metrics.version}</version>
694694
</dependency>
695695

696+
<dependency>
697+
<groupId>io.dropwizard.metrics</groupId>
698+
<artifactId>metrics-jetty9</artifactId>
699+
<version>${codahale.metrics.version}</version>
700+
</dependency>
701+
696702
<dependency>
697703
<groupId>com.fasterxml.jackson.core</groupId>
698704
<artifactId>jackson-annotations</artifactId>

0 commit comments

Comments
 (0)