Repository navigation
feat(router)!: log numeric duration_ms and summarize hijacked connections at handoff - #142
Merged
Merged
Conversation
…ions at handoff The request summary logged zap.Duration, whose rendering depends on the application's EncodeDuration. With StringDurationEncoder it produced values like "1h25m30s" and "504.96ms" that log search tools cannot sort or aggregate. Emit duration_ms as a float64 number of milliseconds instead. Hijacked connections (WebSocket upgrades) were summarized when the handler returned, so the summary reported the full connection lifetime and logged every long-lived socket as a slow Warn request. Write the summary at a successful hijack, mark it with hijacked=true, and skip the end-of-request summary for that connection. BREAKING CHANGE: the request summary field "duration" is replaced by "duration_ms", and logkeys.Duration is replaced by logkeys.DurationMS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #142 +/- ##
=======================================
Coverage 99.93% 99.93%
=======================================
Files 31 31
Lines 3180 3193 +13
=======================================
+ Hits 3178 3191 +13
Misses 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Numeric duration. The request summary logged
zap.Duration, and the text of that field depends on the application'sEncodeDuration. go-common usesStringDurationEncoder, which writes values like"1h25m30s"and"504.96ms". Open Splunk, and SPL in general, can't sort or aggregate those, sosort num(duration)gave meaningless order. The summary now writesduration_msas a float64 number of milliseconds, whatever encoder the app uses.Hijacked connections. WebSocket upgrades were summarized when the handler returned. That meant the summary recorded the whole connection lifetime (hours), and every long-lived socket was logged at
Warnas a slow request. NowmetricsResponseWriter.Hijackwrites the summary at a successful hijack, withhijacked: trueadded, and the end-of-request summary is skipped for that connection. A failed hijack keeps the normal end-of-request summary.Breaking changes
durationis replaced byduration_ms.logkeys.Durationis replaced bylogkeys.DurationMS.logkeys.Hijackedis new.Notes
statusfor a hijacked summary is whatever the router saw before the handoff. That is101if the handler calledWriteHeader(101)first (coder/websocket does), otherwise the default200(gorilla writes its 101 straight to the hijacked conn).request_latency_secondsstill records the full hijacked-connection lifetime.ratelimit'swindow/reset_durationand the timeout log'stimeoutstill usezap.Duration.Test plan
go test ./...,go test -raceon the new testsgolangci-lint run,go vet ./...go test ./internal/doccheck,go build ./examples/...duration_msis a float64; a failed hijack keeps the end-of-request summary.🤖 Generated with Claude Code