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

Merged
merged 1 commit into from
Jul 15, 2025

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

@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
Copilot

This comment was marked as outdated.

@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

@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from ccc7539 to 406e3f4 Compare July 2, 2025 04:20
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch 3 times, most recently from 713ca71 to 33d8acb Compare July 2, 2025 05:52
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch from 33d8acb to 1e3334b Compare July 2, 2025 09:31
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 88bf416 to cd30512 Compare July 2, 2025 09:46
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch from 1e3334b to 332f8da Compare July 2, 2025 09:46
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from cd30512 to 3a8822d Compare July 3, 2025 07:36
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch from 332f8da to 6cd9d68 Compare July 3, 2025 07:36
@ethanndickson ethanndickson marked this pull request as ready for review July 3, 2025 08:23
@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/populate-connection-log-count branch from 6cd9d68 to 6fa4d22 Compare July 10, 2025 05:58
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 02a93e0 to 2231707 Compare July 10, 2025 10:28
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch 2 times, most recently from 769b7a5 to fc195c3 Compare July 10, 2025 10:50
@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

This PR adds support for returning the total count of connection logs alongside paginated results by issuing a separate COUNT query.

  • API handler is updated to fetch and return Count in ConnectionLogResponse, with early exit on zero count.
  • searchquery.ConnectionLogs now returns a count filter, and corresponding tests are updated.
  • New SQL query, querier methods, authz, metrics, and tests are added to support CountConnectionLogs.

Reviewed Changes

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

Show a summary per file
File Description
enterprise/coderd/connectionlog.go Call CountConnectionLogs, early exit on zero, include count.
enterprise/coderd/connectionlog_test.go Updated tests to assert logs.Count for various scenarios.
coderd/searchquery/search.go & coderd/searchquery/search_test.go ConnectionLogs now returns countFilter; tests updated.
coderd/database/queries/connectionlogs.sql & queries.sql.go Added CountConnectionLogs SQL and generated Go code.
coderd/database/querier.go & coderd/database/querier_test.go Added CountConnectionLogs and CountAuthorizedConnectionLogs with tests.
coderd/database/dbmock/dbmock.go Mock methods for CountConnectionLogs and CountAuthorizedConnectionLogs.
coderd/database/dbmetrics/querymetrics.go Metrics wrappers for the new count methods.
coderd/database/dbauthz/*.go & setup_test.go & dbauthz_test.go Authorization logic and tests for counting connection logs.
Comments suppressed due to low confidence (1)

coderd/searchquery/search_test.go:430

  • [nitpick] The variable name values is ambiguous in this context. Consider renaming it to something like filterParams or offsetParams to clarify it holds the parameters for the offset query.
		})

@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/populate-connection-log-count branch from fc195c3 to df2d839 Compare July 14, 2025 02:04
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 133e51d to b8faf73 Compare July 14, 2025 06:12
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch from df2d839 to 78cc56b Compare July 14, 2025 06:13
@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/populate-connection-log-count branch from 78cc56b to e61fc41 Compare July 15, 2025 03:33
@ethanndickson ethanndickson force-pushed the ethan/connection-logs-api branch from 3ec1f06 to c013e9f Compare July 15, 2025 04:00
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch from e61fc41 to 4055dd7 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:45 AM UTC: Graphite couldn't merge this pull request because a downstack PR feat: add connectionlogs API #18628 failed to merge.
  • Jul 15, 4:55 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 15, 4:57 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 15, 5:03 AM UTC: @ethanndickson merged this pull request with Graphite.

@ethanndickson ethanndickson changed the base branch from ethan/connection-logs-api to graphite-base/18629 July 15, 2025 04:37
@ethanndickson ethanndickson changed the base branch from graphite-base/18629 to main July 15, 2025 04:55
@ethanndickson ethanndickson force-pushed the ethan/populate-connection-log-count branch from 4055dd7 to e10a5cf Compare July 15, 2025 04:56
@ethanndickson ethanndickson merged commit 7c077d3 into main Jul 15, 2025
31 checks passed
@ethanndickson ethanndickson deleted the ethan/populate-connection-log-count branch July 15, 2025 05:03
@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.

3 participants