Add WebSocket server metrics - #4317
Open
LivingLikeKrillin wants to merge 4 commits into
Open
LivingLikeKrillin wants to merge 4 commits into
LivingLikeKrillin wants to merge 4 commits into
Conversation
Signed-off-by: Jooyoung Jung <livinglikekrillin@gmail.com>
Signed-off-by: Jooyoung Jung <livinglikekrillin@gmail.com>
Signed-off-by: Jooyoung Jung <livinglikekrillin@gmail.com>
| * @param status the WebSocket handshake status | ||
| * @param time the time in nanoseconds that is spent for the handshake | ||
| */ | ||
| public abstract void recordWebSocketHandshakeTime(ContextView contextView, SocketAddress remoteAddress, String uri, |
| * @param status the WebSocket handshake status | ||
| * @param time the time in nanoseconds that is spent for the handshake | ||
| */ | ||
| public abstract void recordWebSocketHandshakeTime(ContextView contextView, SocketAddress remoteAddress, String uri, |
| * @param status the WebSocket handshake status | ||
| * @param time the time in nanoseconds that is spent for the handshake | ||
| */ | ||
| public abstract void recordWebSocketHandshakeTime(ContextView contextView, SocketAddress remoteAddress, String uri, |
| * @param time the time in nanoseconds that is spent for the handshake | ||
| */ | ||
| public abstract void recordWebSocketHandshakeTime(ContextView contextView, SocketAddress remoteAddress, String uri, | ||
| String status, Duration time); |
| * @param time the time in nanoseconds that is spent for the handshake | ||
| */ | ||
| public abstract void recordWebSocketHandshakeTime(ContextView contextView, SocketAddress remoteAddress, String uri, | ||
| String status, Duration time); |
| * @param uri the requested URI | ||
| * @param time the duration of the connection | ||
| */ | ||
| public abstract void recordWebSocketConnectionDuration(ContextView contextView, SocketAddress remoteAddress, |
| * @param uri the requested URI | ||
| * @param time the duration of the connection | ||
| */ | ||
| public abstract void recordWebSocketConnectionDuration(ContextView contextView, SocketAddress remoteAddress, |
| * @param time the duration of the connection | ||
| */ | ||
| public abstract void recordWebSocketConnectionDuration(ContextView contextView, SocketAddress remoteAddress, | ||
| String uri, Duration time); |
| * @param time the duration of the connection | ||
| */ | ||
| public abstract void recordWebSocketConnectionDuration(ContextView contextView, SocketAddress remoteAddress, | ||
| String uri, Duration time); |
Contributor
Author
|
Hi @violetagg, pushed a small fix: This may be a lot to review in one pass. If smaller pieces would be easier, I am glad to split it myself: it divides cleanly along the three content commits (roughly 860, 710 and 620 lines), in whatever grouping suits you. If you would rather keep it as one PR, that works too. |
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add WebSocket server metrics, mirroring the client WebSocket metrics (#4118). This is the first step of #4305. The meters are registered under the
reactor.netty.websocket.serverprefix, tagged withuri(mapped through the configureduriTagValuewhen one is set, as for the HTTP server meters):handshake.time(tagsuri,status):101on a successful HTTP/1.1 upgrade,200on a successful HTTP/2 Extended CONNECT,ERRORwhen the handshake fails after the metrics handler is installed. Pre-upgrade rejections (unsupported version on HTTP/1.1, invalid Extended CONNECT on HTTP/2) are answered before installation and record no WebSocket meterconnection.duration: from handler installation on upgrade to pipeline removal on close, so it includes the handshake and is also recorded when the handshake fails (same as the client)data.received,data.sent,data.received.time,data.sent.time: recorded once per message on the final fragment; control frames (Close, Ping, Pong) are excludederrors: pipeline exceptions and application errors raised while sending the WebSocket outboundOn the Micrometer path — as on the client — the handshake meter is produced by a
reactor.netty.websocket.server.handshake.timeobservation instead of a direct recorder call.Changes
On upgrade,
WebsocketServerOperations(HTTP/1.1) andHttp2WebsocketServerOperations(HTTP/2) install a WebSocket metrics handler at theWsMetricsHandlerslot, selected from the configured HTTP metrics handler the same way the client'sswapMetricsHandlerdoes. The Micrometer path always uses the built-in WebSocket recorder; on the other two, a recorder that does not implement the matching WebSocket type (ContextAwareWebSocketServerMetricsRecorderon the context-aware path,WebSocketServerMetricsRecorderon the plain one) is wrapped in an adapter that delegates the inherited HTTP methods and no-ops the two WebSocket ones. TheWebsocketHttpServerMetricsHandlerpass-through is kept unchanged, since it carries the connection/stream count accounting (#4290); the new handler is additive.New public API:
WebSocketServerMetricsRecorder(extendsHttpServerMetricsRecorder, two methods) andContextAwareWebSocketServerMetricsRecorder(adds the twoContextViewoverloads), plusMetrics.WEBSOCKET_SERVER_PREFIX. All other new types are package-private, and no meter of the built-in Micrometer recorder carries aremote.addressorproxy.addresstag. Native-image reflection configuration for the four new handlers and a reference documentation section are included.Test plan
101) and HTTP/2 Extended CONNECT (200)ERRORhandshake status when the handshake fails after the handler is installeduriTagValuemapping applied to theuritagThese cover the Micrometer recorder path. The custom-recorder path is exercised end to end by the existing
testServerConnectionsWebsocketRecorder, but no test asserts the WebSocket recordings made on it, and the context-aware recorder path is not covered by a test yet.Related to #4305