Micrometer - JettyConnectionMetrics - not working
See original GitHub issueActual 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:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
This is out now ! https://javalin.io/news/2021/01/19/javalin-3.13.0-released.html
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:
Attaching it to a Jetty lifecycle hook would work, but not sure how elegant it is.
That is, in the plugin add: