Jetty StatisticsHandler
See original GitHub issueI really like Javalin. Hits the sweet spot for me in being functional out of the box with enough knobs to tune (EmbeddedJettyServer). But one of the things I can’t do right now is add any Handler instances to my custom Jetty Server. They are always overwritten.
By being able to add a handler, I can use the StatisticsHandler and then hook it up to Prometheus (or Micrometer or what have you). I was able to get around it by deriving a class from Jetty Server and overriding setHandler
but that just feels dirty.
Maybe you don’t want to allow all kinds of handlers. But StatisticsHandler is really useful because of existing integration with Prometheus (and others). And RequestLogHandler will also be nice. I like Javalin’s request logging, but RequestLogHandler outputs a well known Ops-preferred format.
But for this issue, StatisticsHandler is what I’m after.
I’m thinking something like this on Embedded
class EmbeddedJettyFactory(
jettyServer: () -> Server = { Server(QueuedThreadPool(250, 8, 60000)) },
statisticsHandler: StatisticsHandler? = null) : EmbeddedServer() {
private val server = jettyServer()
override fun create(javalinServlet: JavalinServlet, staticFileConfig: StaticFileConfig?): EmbeddedServer {
return EmbeddedJettyServer(server, javalinServlet.apply { staticResourceHandler = JettyResourceHandler(staticFileConfig) }, statisticsHandler)
}
}
And then in EmbeddedJettyServer start at line 69…
server.apply {
val h = HandlerList(httpHandler, webSocketHandler, notFoundHandler)
handler = statisticsHandler?.apply { handler = h } ?: h
connectors = connectors.takeIf { it.isNotEmpty() } ?: arrayOf(ServerConnector(server).apply {
this.port = port
})
}.start()
Thoughts?
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (19 by maintainers)
Top GitHub Comments
@tipsy - sorry for the communication blackout. Works been crazy busy. I’ll update the PR tonight. And your usage of
insertTail
looks right. It always ends up looking backwards to me so I always forget about it and do things the hard way.Don’t be sorry, I’m happy we have the feature. Let me know if you run into any trouble.