Skip to content

Commit

Permalink
[KYUUBI #6615] Make Jetty sending server version in response configur…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
paul8263 committed Sep 11, 2024
1 parent edbe3f3 commit 14880fe
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import com.codahale.metrics.MetricRegistry
import io.prometheus.client.CollectorRegistry
import io.prometheus.client.dropwizard.DropwizardExports
import io.prometheus.client.exporter.MetricsServlet
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.server.{HttpConfiguration, HttpConnectionFactory, Server, ServerConnector}
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}

import org.apache.kyuubi.KyuubiException
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.FRONTEND_JETTY_SEND_VERSION_ENABLED
import org.apache.kyuubi.service.AbstractService

class PrometheusReporterService(registry: MetricRegistry)
Expand All @@ -35,12 +36,21 @@ class PrometheusReporterService(registry: MetricRegistry)

// VisibleForTesting
private[metrics] var httpServer: Server = _
private[metrics] var connector: ServerConnector = _
@volatile protected var isStarted = false

override def initialize(conf: KyuubiConf): Unit = {
val port = conf.get(MetricsConf.METRICS_PROMETHEUS_PORT)
val contextPath = conf.get(MetricsConf.METRICS_PROMETHEUS_PATH)
httpServer = new Server(port)
val sendServerVersion = conf.get(FRONTEND_JETTY_SEND_VERSION_ENABLED)

val httpConf = new HttpConfiguration()
httpConf.setSendServerVersion(sendServerVersion)
httpServer = new Server()
connector = new ServerConnector(httpServer, new HttpConnectionFactory(httpConf))
connector.setPort(port)
httpServer.addConnector(connector)

val context = new ServletContextHandler
context.setContextPath("/")
httpServer.setHandler(context)
Expand All @@ -56,6 +66,7 @@ class PrometheusReporterService(registry: MetricRegistry)
if (!isStarted) {
try {
httpServer.start()
connector.start()
info(s"Prometheus metrics HTTP server has started at ${httpServer.getURI}.")
} catch {
case rethrow: Exception =>
Expand All @@ -79,11 +90,13 @@ class PrometheusReporterService(registry: MetricRegistry)
if (httpServer != null) {
try {
httpServer.stop()
connector.stop()
info("Prometheus metrics HTTP server has stopped.")
} catch {
case err: Exception => error("Cannot safely stop prometheus metrics HTTP server", err)
} finally {
httpServer = null
connector = null
}
}
}
Expand Down

0 comments on commit 14880fe

Please sign in to comment.