chore!: delete old connection events from audit log by ethanndickson · Pull Request #18735 · coder/coder · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

chore!: delete old connection events from audit log #18735

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

Open
wants to merge 2 commits into
base: ethan/fe-connection-log
Choose a base branch
from

Conversation

ethanndickson
Copy link
Member

@ethanndickson ethanndickson commented Jul 3, 2025

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

In previous PRs:

  • New connection logs have been routed to the connection_logs table, in a previous PR. They will not appear in the audit log.
  • These new connection logs are served from the new /api/v2/connectionlog endpoint.

In this PR:

  • We'll now clean existing connection events out of the audit log, if they are older than 90 days, We do this in batches of 1000, every 10 minutes.

The criteria for deletion is simple:

WHERE
(
     action = 'connect'
     OR action = 'disconnect'
     OR action = 'open'
     OR action = 'close'
)
AND "time" < @before_time::timestamp with time zone

where @before_time is currently configured to 90 days in the past.

If you require this data, we recommend querying it from the REST API or making a backup of the database/these events before upgrading.
There are currently no plans to delete connection events from the new connection_logs table.

Future PRs:

  • Write documentation for the endpoint / feature

Copy link
Member Author

ethanndickson commented Jul 3, 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.

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

Adds a new cleanup step to remove old connection-related events from the audit_logs table once they’re more than 90 days old, running in batches of 1000 every 10 minutes.

  • Introduces a SQL query (DeleteOldAuditLogConnectionEvents) and corresponding Go method to delete old connection events.
  • Wires the deletion into the periodic dbpurge service, along with interface, mocks, metrics, and in-memory store updates.
  • Adds tests to verify deletion logic, limits, and authorization.

Reviewed Changes

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

Show a summary per file
File Description
coderd/database/queries/auditlogs.sql Define SQL delete to purge old connection events
coderd/database/queries.sql.go Add Go constant, params, and method for deletion
coderd/database/querier.go Extend interface with new deletion method
coderd/database/dbpurge/dbpurge.go Integrate the new deletion into the purge loop
coderd/database/dbpurge/dbpurge_test.go Add tests for deletion behavior and limits
coderd/database/dbmock/dbmock.go Mock the new deletion call in the mock store
coderd/database/dbmetrics/querymetrics.go Instrument deletion in metrics wrapper
coderd/database/dbmem/dbmem.go Implement fake deletion in in-memory querier
coderd/database/dbauthz/dbauthz.go Add authz check and proxy for the deletion call
coderd/database/dbauthz/dbauthz_test.go Add authorization test for the new delete method
Comments suppressed due to low confidence (1)

coderd/database/dbpurge/dbpurge.go:22

  • Update the comment to reference the correct table name (audit_logs) to match the actual table and avoid confusion.
	// We'll slowly remove old connection events from the `audit_log` table,

@ethanndickson ethanndickson force-pushed the ethan/fe-connection-log branch from 5db1b73 to 4be35f4 Compare July 3, 2025 07:36
@ethanndickson ethanndickson force-pushed the ethan/delete-old-connection-events branch from da6d50a to 0386f5b Compare July 3, 2025 07:36
@ethanndickson ethanndickson marked this pull request as ready for review July 3, 2025 08:24
@github-actions github-actions bot added the release/breaking This label is applied to PRs to detect breaking changes as part of the release process label Jul 3, 2025
@ethanndickson ethanndickson force-pushed the ethan/fe-connection-log branch from 4be35f4 to 9239251 Compare July 3, 2025 08:29
@ethanndickson ethanndickson force-pushed the ethan/delete-old-connection-events branch from 0386f5b to ab296c6 Compare July 3, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/breaking This label is applied to PRs to detect breaking changes as part of the release process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.