Skip to content

chore: populate connectionlog count using a separate query #18629

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

Draft
wants to merge 1 commit into
base: ethan/connection-logs-api
Choose a base branch
from

Conversation

ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Jun 27, 2025

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

This PR populates count on ConnectionLogResponse using a separate query, to preemptively mitigate the issue described in #17689. It's structurally identical to a portion of #18600, but for the connection log instead of the audit log.

Future PRs:

  • 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

Copy link
Member Author

ethanndickson commented Jun 27, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from ed8e139 to 8cec6d1 Compare June 27, 2025 14:08
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch from a031154 to d03fe73 Compare June 27, 2025 14:08
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 8cec6d1 to 482a5d3 Compare June 30, 2025 04:28
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch from d03fe73 to 8cbd44a Compare June 30, 2025 04:28
@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/populate-connection-log-count branch from 8cbd44a to 09cbe49 Compare June 30, 2025 12:03
@ethanndickson ethanndickson requested a review from Copilot July 1, 2025 02:46
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

This PR adds a separate count query for connection logs so that the ConnectionLogResponse includes a total count, mitigating performance issues described in #17689. Key changes include:

  • HTTP handler now runs CountConnectionLogs and populates Count in its response.
  • searchquery.ConnectionLogs returns two filter structs (offsetFilter and countFilter) and the handler invokes the new CountConnectionLogs method.
  • Added SQL and Go plumbing (queries, querier interfaces, mocks, metrics, in-memory impl, authorization, and tests) to support counting connection logs.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
enterprise/coderd/connectionlog.go Calls CountConnectionLogs before fetching paged results and writes Count in the response
enterprise/coderd/connectionlog_test.go Adds assertions for the new Count field in tests
coderd/searchquery/search.go Updated ConnectionLogs to return a CountConnectionLogsParams filter
coderd/searchquery/search_test.go Adjusted tests to unpack the new return value
coderd/database/queries/connectionlogs.sql Introduced CountConnectionLogs SQL query
coderd/database/queries.sql.go Added countConnectionLogs constant and CountConnectionLogs implementation
coderd/database/querier.go Extended querier interface with CountConnectionLogs
coderd/database/modelqueries_internal_test.go Added consistency test to ensure both queries share the same WHERE clause
coderd/database/modelqueries.go Implemented CountAuthorizedConnectionLogs
coderd/database/dbmock/dbmock.go Generated mocks for the new count methods
coderd/database/dbmetrics/querymetrics.go Wrapped new count methods with latency metrics
coderd/database/dbmem/dbmem.go Added in-memory implementation of CountConnectionLogs
coderd/database/dbauthz/setup_test.go Unified empty-response checks for count tests
coderd/database/dbauthz/dbauthz_test.go Added RBAC tests for count methods
coderd/database/dbauthz/dbauthz.go Authorized count methods in the dbauthz layer

@kacpersaw kacpersaw marked this pull request as ready for review July 1, 2025 06:14
@ethanndickson ethanndickson marked this pull request as draft July 1, 2025 06:15
Copy link
Contributor

@kacpersaw kacpersaw left a comment

Choose a reason for hiding this comment

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

LGTM - similar to my PR #18600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants