https://kotlinlang.org logo
#ktor
Title
# ktor
s

Scott Rankin

10/24/2023, 10:53 PM
Hello, I have a question about the ktor_http_server_requests_seconds_bucket Micrometer metric. We are pretty consistently seeing that it reports 30s for the
Upgrade
of a websocket. Do you have any guidance about the best way to assess why this would report such a large value? We don't appear to see websocket connection errors on our libwebsockets.org based client or within our ktor based server in production. Locally we also see this with just kotlin based clients connecting to our service. We are using Netty if it matters. Using ktor 2.3.0. Is there a particular logger we can turn up to see the activity between ktor and the MicrometerMetrics? I will try to create a minimal example and send a github if I am able to do so. Any assistance would be greatly appreciated.
I realize I neglected to mention I added these to our logging config:
Copy code
io.ktor.websocket: "ALL"
        io.ktor.server: "ALL"
        io.micrometer: "ALL"
but I'm not seeing anything related to this particular Timer or how this metric is started/stopped.
c

Chris Lee

10/25/2023, 12:58 AM
would suspect this has something to do with a websocket no longer being http requests - perhaps the transition to websocket is not measured correctly there. Perhaps dig through the code to see where the timing occurs.
s

Scott Rankin

10/25/2023, 3:22 PM
Thanks! That is my suspicion as well. I'm just not familiar with how Micrometer timers are started in ktor. I will clone the repo and see if I can find something.
The one thing that is curious is that it's not happening for all of the Upgrade but only after a period of activity and some number of websocket sessions have upgraded successfully. I'll update if I find out more.
c

Chris Lee

10/25/2023, 3:27 PM
iirc the observability hooks in ktor are based on events (that ktor emits); perhaps something in there that isn’t tracking event state properly etc.
smells a bit like a race condition.
3 Views