question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jetty StatisticsHandler

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
justruddcommented, Nov 30, 2017

@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.

0reactions
tipsycommented, Dec 4, 2017

Don’t be sorry, I’m happy we have the feature. Let me know if you run into any trouble.

Read more comments on GitHub >

github_iconTop Results From Across the Web

StatisticsHandler (Jetty :: Project 9.4.46.v20220331 API)
Class StatisticsHandler. java.lang.Object. org.eclipse.jetty.util.component.AbstractLifeCycle · org.eclipse ...
Read more >
org.eclipse.jetty.server.handler.StatisticsHandler java code ...
Best Java code snippets using org.eclipse.jetty.server.handler.StatisticsHandler (Showing top 20 results out of 360). origin: dropwizard/dropwizard ...
Read more >
StatisticsHandler - jetty-server 9.4.0.M0 javadoc
org.eclipse. · jetty-server · 9.4.0.
Read more >
jetty/StatisticsHandler.java at master · dekellum/jetty
Jetty - Servlet Engine and Http Server project repository (jetty.project) - jetty/StatisticsHandler.java at master · dekellum/jetty.
Read more >
org.eclipse.jetty.server.handler.StatisticsHandler
This page shows Java code examples of org.eclipse.jetty.server.handler.StatisticsHandler.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found