Repository navigation
feat: expose connection duration and client session ID in connection logs - #30759
Conversation
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
26b3694 to
3382be8
Compare
9a9b317 to
ac3bf16
Compare
…otent (#31056) `TestPubsub/CloseIdempotent` in `coderd/nats` flakes in CI with "embedded nats server not ready within 10s" (for example in [`test-go-pg-17` on main](https://github.com/coder/coder/actions/runs/39412671012/job/118594196090)). It is the only subtest that calls `nats.New` with `nats.Options{}` directly. With `ClusterPort` unset, `buildServerOptions` falls back to the fixed production cluster port 6222. Test packages run in parallel, and `cli` `TestServer/SpammyLogs` runs `coder server --cluster-host 127.0.0.1`, which holds 127.0.0.1:6222. When the route listener cannot bind, nats-server logs nothing under `NoLog`, and `ReadyForConnections` waits out the 10 s `readyTimeout`. The fix gives the subtest `ClusterPort: natsserver.RANDOM_PORT`, the option the `newPubsub` helper already sets for every other subtest. It is a one-line, test-only change. ## Testing - Red on the merge base: with 127.0.0.1:6222 held by a plain listener, `TestPubsub/CloseIdempotent` fails after 10.01 s with the CI message. - Green on this branch: with the port held, `go test ./coderd/nats/...` passes. - `go test ./coderd/nats/... -count=3` and `make pre-commit` pass. - Remote dogfood UAT ran on the tested SHA 451c4ec and passed. It repeated red and green with 127.0.0.1:6222 and 0.0.0.0:6222 held, ran `-count=5` with no port held, and showed that an overlay whose second `Close` returns an error makes the subtest fail, so it still checks idempotent `Close`. Polish and the test audit made no changes, so both stayed inside the implementation diff (`coderd/nats/pubsub_test.go`). Draft #30759 carries the same one-line edit as a drive-by, so whichever lands second merges cleanly. > Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.
ac3bf16 to
d264325
Compare
nickvigilante
left a comment
There was a problem hiding this comment.
Documentation Check
Checked the new content in docs/admin/monitoring/connection-logs.md and the regenerated API reference pages against the code at the head: the client session ID filter semantics (including the case-insensitive match, pinned by TestSearchConnectionLogs/ClientSessionID), the duration.status values and their mapping to status:ongoing and status:completed, the ssh_info.client_session_id and ssh_info.duration fields, the CLI behavior described under SSH and IDE Sessions, and the UI labels in the Duration status values table. I found nothing to change.
Generated by Coder Agents on behalf of @nickvigilante, using the proposed doc-check skill from #31193 on Solstice-1 Local. Reply in a thread if a finding is wrong.
code-asher
left a comment
There was a problem hiding this comment.
Love it! I think we could get away without making an API change.
396a9f2 to
7f5bf09
Compare
…logs Adds a duration and duration status to SSH and reconnecting PTY connection logs, derived from the stored connect and disconnect timestamps. Exposes the client session ID, adds a client_session_id filter, and replaces the row's hover tooltip with a details popover that can copy the ID and link to related connections.
Drop ssh_info.duration from the API. Clients derive the duration from connect_time and disconnect_time, and treat equal timestamps as a disconnect recorded without its connect.
7f5bf09 to
c41eba5
Compare
…popover Use the Badge component for the connection time range and duration, and switch the details popover to the default PopoverContent styling with sentence-case labels.
c41eba5 to
1da7329
Compare
Shows how long each SSH and reconnecting PTY connection lasted, and lets you find connections that share a client session ID. No schema changes.
API (
ssh_info)client_session_id: the ID the client (the Coder CLI, or a tool that launches it) supplied, if any.client_session_id:<32 hex chars>.connect_timeanddisconnect_time, and the docs explain how to read equal timestamps.UI
connect → disconnectand the duration. A connection with no disconnect yet shows Ongoing, one with equal timestamps shows an Unknown start, and a disconnect recorded before its connect is labeled as such.Session ID lookups aren't indexed. The UI link always filters by
workspace_idtoo, which is already indexed. A manualclient_session_id:search across the whole deployment scans the table (about 560 ms on 1M synthetic rows). See the decision log for why there's no index yet.Closes CLIENT-1010. Grouping related connections is CLIENT-1047.
Decision log
Duration is derived on the client. A disconnect that arrives without its connect stores its own time as
connect_time, so equal timestamps mean the connect wasn't recorded. An earlier version returned adurationobject with a status and seconds, but both can be derived from the timestamps, so it was dropped after review. The UI compares the raw timestamp strings because JavaScriptDatedrops sub-millisecond precision, and a test checks that both timestamps serialize identically.Missing connects become legacy-only in a follow-up. CLIENT-1064 (feat(agent): include the original connect time in connection disconnect reports #31308) has the agent send the original connect time with each disconnect, so equal timestamps would only remain in existing rows and rows from older agents.
A missing disconnect reads as "Ongoing". Coder can't tell an open connection from a lost disconnect event, and the existing
status:ongoingfilter already uses that term for the same rows.No index on
client_session_idfor now. Benchmark on 1M synthetic rows:(client_session_id, connect_time DESC)The index would also block connection-log writes while it builds (migrations run in a transaction, so
CONCURRENTLYisn't available), and it slowed inserts by about 32%. Since the UI path already uses the workspace index, the index is left for a follow-up if deployment-wide lookups turn out to matter. A(workspace_id, client_session_id, connect_time DESC)index is another option, but it hasn't been benchmarked.Generated by Coder Agents on behalf of @EhabY.