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.

Micrometer - JettyConnectionMetrics - not working

See original GitHub issue

Actual behavior (the bug) The included Micrometer plugin also includes JettyConnectionMetrics (including “jetty.connections.bytes.out”). This metric is always 0 in the statistics output.

Expected behavior The metric “jetty.connections.bytes.out” (and other metrics) should have with each request an increasing value.

To Reproduce Minimal working example demonstrating the issue (using Javalin, Micrometer, Kotlin coroutines, Ktor-Client and JUnit 5):

import io.javalin.Javalin
import io.javalin.plugin.metrics.MicrometerPlugin
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.micrometer.core.instrument.Metrics
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test

private const val TEST_STRING = "Hello world :)"

class IssueTest {
    @Test
    fun `Test JettyConnectionMetrics are increasing with one request`() {
        val app = Javalin.create { it.registerPlugin(MicrometerPlugin())}

        app.get("/") { it.result(TEST_STRING) }
        app.start(0)

        HttpClient().use {
            runBlocking {
                assertEquals(TEST_STRING, it.get<String>("http://127.0.0.1:${app.port()}"))
            }
        }

        app.stop()

        val measures = Metrics.globalRegistry.meters
            .first { it.id.name == "jetty.connections.bytes.out" }.measure()

        measures.forEach {
            assertNotEquals(0.0, it.value)
        }
    }
}

Additional context It turns out that JettyConnectionMetrics is never connected with the (jetty)server. There is also a static method JettyConnectionMetrics.addToAllConnectors(Server server, MeterRegistry registry, Iterable<Tag> tags) which is not called in any place. I tried to add it manually in the serverStarted() Javalin lifecycle (before the connector does not exists), but it also does’nt work (JettyConnectionMetrics has status STOPPED). I don’t know how jetty works and how the correct position of initialization of JettyConnectionMetrics would be correct.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tipsycommented, Jan 19, 2021
1reaction
gi-wg2commented, Jan 15, 2021

I just had the same problem now and then found this issue. I’ll see if I can make a proper fix.

When running the plugin, I don’t actually have any connectors so running addToAllConnectors doesn’t do any difference.

Running the method after the app has started does work, but it would be nice to fix the plugin instead:

val app = Javalin.create().start()
app.server()?.server()?.let { JettyConnectionMetrics.addToAllConnectors(it, registry)

Attaching it to a Jetty lifecycle hook would work, but not sure how elegant it is.

That is, in the plugin add:

server.addLifeCycleListener(object : LifeCycle.Listener {
    override fun lifeCycleStarting(event: LifeCycle) = Unit
    override fun lifeCycleStarted(event: LifeCycle) = JettyConnectionMetrics.addToAllConnectors(server, registry, tags)
    override fun lifeCycleFailure(event: LifeCycle, cause: Throwable) = Unit
    override fun lifeCycleStopping(event: LifeCycle) = Unit
    override fun lifeCycleStopped(event: LifeCycle) = Unit
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Micrometer - JettyConnectionMetrics - not working · Issue #1104
I tried to add it manually in the serverStarted() Javalin lifecycle (before the connector does not exists), but it also does'nt work ( ......
Read more >
JettyConnectionMetrics (micrometer-core 1.5.3 API) - javadoc.io
Class JettyConnectionMetrics​​ Jetty connection metrics. Usage example: MeterRegistry registry = ...; Server server = new Server(0); Connector connector = new ...
Read more >
What does JettyConnectionMetrics count? - jetty
I am right that it is updated only on connection close which could delay data when there is a HAProxy between real clients...
Read more >
Micrometer and the Modern Observability Stack
Leave the hard work to the querying and not the metric production. Another rule of thumb: if you are measuring anything temporal on...
Read more >
JettyConnectionMetricsBinder (Spring Boot 2.6.11 API)
AbstractJettyMetricsBinder for JettyConnectionMetrics . Since: 2.6.0; Author: Chris Bono ... JettyConnectionMetricsBinder(io.micrometer.core.instrument.
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