Skip to content

Conversation

@mafredri
Copy link
Member

@mafredri mafredri commented Dec 1, 2025

Add configurable retention policy for audit logs. The DeleteOldAuditLogs
query excludes deprecated connection events (connect, disconnect, open,
close) which are handled separately by DeleteOldAuditLogConnectionEvents.

Disabled (0) by default.

Depends on #21021
Updates #20743


PR Stack

PR Title
#21021 feat(coderd): add retention policy configuration
#21022 feat(coderd/database/dbpurge): add retention for connection logs
👉 #21025 feat(coderd/database/dbpurge): add retention for audit logs
#21037 feat(coderd/database/dbpurge): make API keys retention configurable
#21038 docs: add data retention documentation
#21039 feat: add retention config for workspace_agent_logs

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM, except for batch size; I won't need to re-review.

@mafredri mafredri force-pushed the mafredri/feat-coderd-db-retention-policy-3 branch from a21395a to 82f1c2b Compare December 2, 2025 11:37
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

👍

Agree 1k is low

@mafredri mafredri force-pushed the mafredri/feat-coderd-db-retention-policy-3 branch from 82f1c2b to 2ce8f62 Compare December 2, 2025 12:56
@mafredri
Copy link
Member Author

mafredri commented Dec 2, 2025

@dannykopping @Emyrk I've bumped to 10k for both audit and connection logs 👍🏻

@mafredri mafredri force-pushed the mafredri/feat-coderd-db-retention-policy-2 branch from 6433def to d456497 Compare December 2, 2025 14:05
@mafredri mafredri force-pushed the mafredri/feat-coderd-db-retention-policy-3 branch from 2ce8f62 to 8cb020d Compare December 2, 2025 14:13
Base automatically changed from mafredri/feat-coderd-db-retention-policy-2 to main December 2, 2025 14:17
Add configurable retention policy for audit logs. The DeleteOldAuditLogs
query excludes deprecated connection events (connect, disconnect, open,
close) which are handled separately by DeleteOldAuditLogConnectionEvents.

Falls back to global retention if audit logs retention is unset.
Disabled (0) by default.

Depends on #21021
Updates #20743
Audit logs retention is now explicit - it's enabled when
--audit-logs-retention is set to a non-zero duration, and
disabled when set to 0. No fallback to global retention.
Use :execrows instead of :one to simplify the query by removing the
extra CTE wrapper. This lets PostgreSQL return the row count directly
via RowsAffected() instead of requiring an explicit COUNT(*) scan.
@mafredri mafredri force-pushed the mafredri/feat-coderd-db-retention-policy-3 branch from 8cb020d to 2a45adb Compare December 2, 2025 14:18
@mafredri mafredri merged commit c85d79b into main Dec 2, 2025
30 checks passed
@mafredri mafredri deleted the mafredri/feat-coderd-db-retention-policy-3 branch December 2, 2025 14:50
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 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.

4 participants