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..41271f0bea8 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 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) @@ -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 => @@ -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 } } }