[KYUUBI #6615] Make Jetty sending server version in response configurable
# 🔍 Description ## Issue References 🔗 This pull request fixes #6615 ## Describe Your Solution 🔧 Add a config item that controls whether Jetty should send its version in response. This is an additional patch which enables/disables sending Jetty version for prometheus reporter. Sending Jetty version could be disabled by calling HttpConfiguration::setSendServerVersion(false) ## Types of changes 🔖 - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 Compiled and tested manually. #### Behavior Without This Pull Request ⚰️ #### Behavior With This Pull Request 🎉 #### Related Unit Tests --- # Checklist 📝 - [ ] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6685 from paul8263/KYUUBI-6615-patch. Closes #6615 0638a5116 [zhang_yao] [KYUUBI #6615] Make Jetty sending server version in response configurable Authored-by: zhang_yao <xzhangyao@126.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
parent
3c72fef476
commit
d50cf17ede
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user