Skip to content

Conversation

@mafredri
Copy link
Member

@mafredri mafredri commented Dec 1, 2025

Add RetentionConfig with server flags for configuring data retention:

  • --audit-logs-retention: retention for audit log entries
  • --connection-logs-retention: retention for connection logs
  • --api-keys-retention: retention for expired API keys (default 7d)

Note: AI Bridge already has retention flags which are kept separate from RetentionConfig, which only affects core coderd.

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

@mafredri mafredri force-pushed the mafredri/feat-coderd-db-retention-policy branch from 75a0de4 to b5e66fa Compare December 1, 2025 13:03
@mafredri mafredri marked this pull request as ready for review December 1, 2025 13:12
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

wait a sec, is it only deployment config, or are you going to use these options soon? if the plan is to continue after some time, maybe park these changes in a side branch. Otherwise the commit message will be confusing.

@mafredri
Copy link
Member Author

mafredri commented Dec 1, 2025

@mtojek #21022

mafredri added a commit that referenced this pull request Dec 1, 2025
Add `DeleteOldConnectionLogs` query and integrate it into the `dbpurge`
routine. Retention is controlled by `--retention-connection-logs` flag,
falling back to `--retention-global` when not set. Disabled (0) by
default.

Depends on #21021
Updates #20743
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Thanks for context 👍 👍

mafredri added a commit that referenced this pull request Dec 1, 2025
Add `DeleteOldConnectionLogs` query and integrate it into the `dbpurge`
routine. Retention is controlled by `--retention-connection-logs` flag,
falling back to `--retention-global` when not set. Disabled (0) by
default.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request 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.

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

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 1, 2025
Replace hardcoded 7-day retention for expired API keys with configurable
retention from deployment settings. Falls back to global retention when
not set, and skips deletion entirely when effective retention is 0.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 1, 2025
Document configurable retention policies for Audit Logs, Connection Logs,
and API keys. Add new data-retention.md page and update existing docs to
reference it.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 1, 2025
Document configurable retention policies for Audit Logs, Connection Logs,
and API keys. Add new data-retention.md page and update existing docs to
reference it.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 1, 2025
Replace hardcoded 7-day retention for expired API keys with configurable
retention from deployment settings. Falls back to global retention when
not set, and skips deletion entirely when effective retention is 0.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 1, 2025
Document configurable retention policies for Audit Logs, Connection Logs,
and API keys. Add new data-retention.md page and update existing docs to
reference it.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 1, 2025
Document configurable retention policies for Audit Logs, Connection Logs,
and API keys. Add new data-retention.md page and update existing docs to
reference it.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request 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.

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

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 1, 2025
Replace hardcoded 7-day retention for expired API keys with configurable
retention from deployment settings. Falls back to global retention when
not set, and skips deletion entirely when effective retention is 0.

Depends on #21021
Updates #20743
Add `RetentionConfig` with server flags for configuring data retention:

- `--global-retention`: default policy for all retention settings
- `--audit-logs-retention`: retention for audit log entries
- `--connection-logs-retention`: retention for connection logs
- `--api-keys-retention`: retention for expired API keys (default 7d)

Updates #20743
@mafredri mafredri force-pushed the mafredri/feat-coderd-db-retention-policy branch from b34ee61 to d5062e2 Compare December 2, 2025 09:48
Remove the global retention fallback in favor of explicit per-topic
retention settings. This makes the retention behavior clearer and
easier for operators to reason about.

Each retention setting now:
- Enables retention when set to a non-zero duration
- Disables retention (keep indefinitely) when set to 0
mafredri added a commit that referenced this pull request Dec 2, 2025
Add `DeleteOldConnectionLogs` query and integrate it into the `dbpurge`
routine. Retention is controlled by `--retention-connection-logs` flag,
falling back to `--retention-global` when not set. Disabled (0) by
default.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 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.

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

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 2025
Replace hardcoded 7-day retention for expired API keys with configurable
retention from deployment settings. Falls back to global retention when
not set, and skips deletion entirely when effective retention is 0.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 2025
Document configurable retention policies for Audit Logs, Connection Logs,
and API keys. Add new data-retention.md page and update existing docs to
reference it.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 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.

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

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 2025
Replace hardcoded 7-day retention for expired API keys with configurable
retention from deployment settings. Falls back to global retention when
not set, and skips deletion entirely when effective retention is 0.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 2025
Document configurable retention policies for Audit Logs, Connection Logs,
and API keys. Add new data-retention.md page and update existing docs to
reference it.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 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.

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

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 2025
Replace hardcoded 7-day retention for expired API keys with configurable
retention from deployment settings. Falls back to global retention when
not set, and skips deletion entirely when effective retention is 0.

Depends on #21021
Updates #20743
mafredri added a commit that referenced this pull request Dec 2, 2025
Document configurable retention policies for Audit Logs, Connection Logs,
and API keys. Add new data-retention.md page and update existing docs to
reference it.

Depends on #21021
Updates #20743
@mafredri mafredri merged commit 56e7858 into main Dec 2, 2025
37 checks passed
@mafredri mafredri deleted the mafredri/feat-coderd-db-retention-policy branch December 2, 2025 14:04
@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