From 0638a5116b254a3e92aadb7ee1dd56773673456c Mon Sep 17 00:00:00 2001 From: zhang_yao Date: Wed, 11 Sep 2024 15:47:12 +0800 Subject: [PATCH] [KYUUBI #6615] Make Jetty sending server version in response configurable --- .../metrics/PrometheusReporterService.scala | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/PrometheusReporterService.scala b/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/PrometheusReporterService.scala index ab014caf14e..e62e2190906 100644 --- a/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/PrometheusReporterService.scala +++ b/kyuubi-metrics/src/main/scala/org/apache/kyuubi/metrics/PrometheusReporterService.scala @@ -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) @@ -35,12 +36,21 @@ class PrometheusReporterService(registry: MetricRegistry) // VisibleForTesting private[metrics] var httpServer: Server = _ + private[metrics] var httpServerConnector: 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 jettyVersionEnabled = conf.get(FRONTEND_JETTY_SEND_VERSION_ENABLED) + + val httpConf = new HttpConfiguration() + httpConf.setSendServerVersion(jettyVersionEnabled) + httpServer = new Server() + httpServerConnector = new ServerConnector(httpServer, new HttpConnectionFactory(httpConf)) + httpServerConnector.setPort(port) + httpServer.addConnector(httpServerConnector) + val context = new ServletContextHandler context.setContextPath("/") httpServer.setHandler(context) @@ -56,6 +66,7 @@ class PrometheusReporterService(registry: MetricRegistry) if (!isStarted) { try { httpServer.start() + httpServerConnector.start() info(s"Prometheus metrics HTTP server has started at ${httpServer.getURI}.") } catch { case rethrow: Exception => @@ -78,12 +89,14 @@ class PrometheusReporterService(registry: MetricRegistry) private def stopHttpServer(): Unit = { if (httpServer != null) { try { + httpServerConnector.stop() httpServer.stop() info("Prometheus metrics HTTP server has stopped.") } catch { case err: Exception => error("Cannot safely stop prometheus metrics HTTP server", err) } finally { httpServer = null + httpServerConnector = null } } }