Skip to content

feat: expose connection duration and client session ID in connection logs - #30759

Merged
EhabY merged 7 commits into
mainfrom
feat/connection-log-duration
Oct 27, 2026
Merged

EhabY merged 7 commits into
mainfrom
feat/connection-log-duration

Conversation

@EhabY

@EhabY EhabY commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

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.
  • New filter client_session_id:<32 hex chars>.
  • No new duration field. Clients compute it from connect_time and disconnect_time, and the docs explain how to read equal timestamps.

UI

  • Each row shows connect → disconnect and 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.
  • The info icon now opens a popover instead of a hover tooltip, so the client session ID can be copied and linked to View related connections (same workspace).

Session ID lookups aren't indexed. The UI link always filters by workspace_id too, which is already indexed. A manual client_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 a duration object 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 JavaScript Date drops 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:ongoing filter already uses that term for the same rows.

  • No index on client_session_id for now. Benchmark on 1M synthetic rows:

    Query No index Partial index on (client_session_id, connect_time DESC)
    Session ID only, rare ID ~560 ms <1 ms
    Session ID + workspace, rare ID ~79 ms <1 ms
    Session ID + workspace, widely shared ID 1.7 ms 29.6 ms

    The index would also block connection-log writes while it builds (migrations run in a transaction, so CONCURRENTLY isn'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.

@linear-code

linear-code Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

CLIENT-1010

CLIENT-1063

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview

Check 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.

@EhabY
EhabY force-pushed the feat/connection-log-duration branch 5 times, most recently from 26b3694 to 3382be8 Compare October 15, 2026 11:54
@EhabY
EhabY force-pushed the feat/connection-log-duration branch 5 times, most recently from 9a9b317 to ac3bf16 Compare October 19, 2026 18:37
ibetitsmike added a commit that referenced this pull request Oct 20, 2026
…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.
@EhabY
EhabY force-pushed the feat/connection-log-duration branch from ac3bf16 to d264325 Compare October 21, 2026 13:04
@EhabY
EhabY marked this pull request as ready for review October 21, 2026 13:04
@EhabY
EhabY requested a review from nickvigilante as a code owner October 21, 2026 13:04
@EhabY
EhabY requested a review from aslilac October 23, 2026 13:27

@nickvigilante nickvigilante left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! I think we could get away without making an API change.

Comment thread codersdk/connectionlog.go Resolved
@EhabY
EhabY removed the request for review from aslilac October 27, 2026 09:46
EhabY added 6 commits October 27, 2026 13:35
…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.
@EhabY
EhabY force-pushed the feat/connection-log-duration branch from 7f5bf09 to c41eba5 Compare October 27, 2026 10:37
…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.
@EhabY
EhabY force-pushed the feat/connection-log-duration branch from c41eba5 to 1da7329 Compare October 27, 2026 10:45
@EhabY
EhabY enabled auto-merge (squash) October 27, 2026 11:02
@EhabY
EhabY disabled auto-merge October 27, 2026 11:03
@EhabY
EhabY merged commit 0d1cba2 into main Oct 27, 2026
30 checks passed
@EhabY
EhabY deleted the feat/connection-log-duration branch October 27, 2026 11:04
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants