Skip to content

feat: add connectionlogs API #18628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2025
Merged

feat: add connectionlogs API #18628

merged 1 commit into from
Jul 15, 2025

Conversation

ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Jun 27, 2025

This is the second PR for moving connection events out of the audit log.

This PR:

  • Adds the /api/v2/connectionlog endpoint
  • Adds filtering for GetAuthorizedConnectionLogsOffset and thus the endpoint.
    There's quite a few, but I was aiming for feature parity with the audit log.
    1. organization:<id|name>
    2. workspace_owner:<username>
    3. workspace_owner_email:<email>
    4. type:<ssh|vscode|jetbrains|reconnecting_pty|workspace_app|port_forwarding>
    5. username:<username>
      • Only includes web-based connection events (workspace apps, web port forwarding) as only those include user metadata.
    6. user_email:<email>
    7. connected_after:<time>
    8. connected_before:<time>
    9. workspace_id:<id>
    10. connection_id:<id>
      • If you have one snapshot of the connection log, and some sessions are ongoing in that snapshot, you could use this filter to check if they've been closed since.
    11. status:<connected|disconnected>
      • If connected only sessions with a null close_time are returned, if disconnected, only those with a non-null close_time. If filter is omitted, both are returned.

Future PRs:

  • Populate count on ConnectionLogResponse using a seperate query (to preemptively mitigate the issue described in Audit log slows to a crawl when nearing 1 million entries #17689)
  • Implement a table in the Web UI for viewing connection logs.
  • Write a query to delete old events from the audit log, call it from dbpurge.
  • Write documentation for the endpoint / feature (including these filters)

Copilot

This comment was marked as outdated.


httpapi.Write(ctx, rw, http.StatusOK, codersdk.ConnectionLogResponse{
ConnectionLogs: convertConnectionLogs(dblogs),
Count: 0, // TODO(ethanndickson): Set count
Copy link
Member Author

Choose a reason for hiding this comment

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

This is populated in the next PR in the stack.

@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch 2 times, most recently from 8cec6d1 to 482a5d3 Compare June 30, 2025 04:28
@ethanndickson ethanndickson force-pushed the ethan/reroute-connection-logs branch from e4e1a04 to 1fcd8d7 Compare June 30, 2025 12:03
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 482a5d3 to ccc7539 Compare June 30, 2025 12:03
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from ccc7539 to 406e3f4 Compare July 2, 2025 04:20
@ethanndickson ethanndickson requested a review from Copilot July 8, 2025 05:05
Copilot

This comment was marked as outdated.

@ethanndickson ethanndickson force-pushed the ethan/reroute-connection-logs branch from 1fcd8d7 to f47a3f7 Compare July 10, 2025 05:58
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 3a8822d to 02a93e0 Compare July 10, 2025 05:58
@ethanndickson ethanndickson force-pushed the ethan/reroute-connection-logs branch from f47a3f7 to 0346609 Compare July 10, 2025 10:28
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 02a93e0 to 2231707 Compare July 10, 2025 10:28
@ethanndickson ethanndickson requested a review from Copilot July 10, 2025 10:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Introduces the new ConnectionLogs API to mirror audit log functionality for connection events, including server routing, handler logic, DB queries, client SDK support, tests, and docs.

  • Adds /api/v2/connectionlog endpoint and pagination/filtering logic on the server
  • Implements search parser, SQL filters, and Go SDK client method
  • Updates TypeScript types, autogenerated docs, enterprise tests, and pagination helpers

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
enterprise/coderd/connectionlog.go New handler, routing, and conversion logic
coderd/searchquery/search.go Added ConnectionLogs query parser
coderd/database/queries/connectionlogs.sql New SQL filters for connection log queries
codersdk/connectionlog.go Client method and types for ConnectionLogs
site/src/api/typesGenerated.ts TS interfaces for new API types
Multiple enterprise/coderd/*_test.go files Tests for parsing, DB querier, and handler
coderd/pagination.go Renamed and updated pagination helper
docs/reference/api/* and Swagger JSON files Documentation for new endpoint and schemas

@ethanndickson ethanndickson force-pushed the ethan/reroute-connection-logs branch from 0346609 to 72ebddb Compare July 14, 2025 02:04
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 2231707 to 133e51d Compare July 14, 2025 02:04
@ethanndickson ethanndickson force-pushed the ethan/reroute-connection-logs branch from 72ebddb to 7d13236 Compare July 14, 2025 06:12
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 133e51d to b8faf73 Compare July 14, 2025 06:13
@ethanndickson ethanndickson force-pushed the ethan/reroute-connection-logs branch from 7d13236 to bea35a3 Compare July 15, 2025 03:33
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from b8faf73 to 3ec1f06 Compare July 15, 2025 03:33
@ethanndickson ethanndickson force-pushed the ethan/reroute-connection-logs branch from bea35a3 to 3164ea2 Compare July 15, 2025 04:00
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 3ec1f06 to c013e9f Compare July 15, 2025 04:00
Copy link
Member Author

ethanndickson commented Jul 15, 2025

Merge activity

  • Jul 15, 4:35 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 15, 4:38 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 15, 4:45 AM UTC: Graphite couldn't merge this PR because it was not satisfying all requirements (Failed CI: 'required', 'test-go-race-pg').
  • Jul 15, 4:55 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 15, 4:55 AM UTC: @ethanndickson merged this pull request with Graphite.

@ethanndickson ethanndickson changed the base branch from ethan/reroute-connection-logs to graphite-base/18628 July 15, 2025 04:36
@ethanndickson ethanndickson changed the base branch from graphite-base/18628 to main July 15, 2025 04:36
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from c013e9f to afdb48d Compare July 15, 2025 04:37
@ethanndickson ethanndickson merged commit 7a339a1 into main Jul 15, 2025
53 of 57 checks passed
@ethanndickson ethanndickson deleted the ethan/connection-logs-api branch July 15, 2025 04:55
@github-actions github-actions bot locked and limited conversation to collaborators Jul 15, 2025
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.

2 participants