diff --git a/dev/dependencyList b/dev/dependencyList index 9ffefe930..8a3287471 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 40f8b7c39..4afd7246e 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 6df0713bb..e1ac527c0 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 638dcbda6..303d14410 100644 --- a/kyuubi-server/pom.xml +++ b/kyuubi-server/pom.xml @@ -218,6 +218,11 @@ jetty-proxy + + io.dropwizard.metrics + metrics-jetty9 + + org.glassfish.jersey.test-framework jersey-test-framework-core 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 b93dcf7b5..7fa111c7f 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 ee8dd3989..24fa52b01 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 05283418a..17f237140 100644 --- a/pom.xml +++ b/pom.xml @@ -693,6 +693,12 @@ ${codahale.metrics.version} + + io.dropwizard.metrics + metrics-jetty9 + ${codahale.metrics.version} + + com.fasterxml.jackson.core jackson-annotations