Skip to content

Commit 9ccd75d

Browse files
committed
chore: remove global retention fallback for workspace agent logs
Workspace agent logs retention is now explicit - it's enabled when --workspace-agent-logs-retention is set to a non-zero duration (default 7d), and disabled when set to 0. No fallback to global retention.
1 parent 9fcac9f commit 9ccd75d

File tree

6 files changed

+22
-37
lines changed

6 files changed

+22
-37
lines changed

coderd/database/dbpurge/dbpurge.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, vals *coder
6767
}
6868

6969
workspaceAgentLogsRetention := vals.Retention.WorkspaceAgentLogs.Value()
70-
if workspaceAgentLogsRetention == 0 {
71-
workspaceAgentLogsRetention = vals.Retention.Global.Value()
72-
}
7370
if workspaceAgentLogsRetention > 0 {
7471
deleteOldWorkspaceAgentLogsBefore := start.Add(-workspaceAgentLogsRetention)
7572
if err := tx.DeleteOldWorkspaceAgentLogs(ctx, deleteOldWorkspaceAgentLogsBefore); err != nil {

coderd/database/dbpurge/dbpurge_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,7 @@ func TestDeleteOldWorkspaceAgentLogsRetention(t *testing.T) {
423423
logsAge: 60 * 24 * time.Hour, // 60 days ago
424424
expectDeleted: false,
425425
},
426-
{
427-
name: "GlobalRetentionFallback",
428-
retentionConfig: codersdk.RetentionConfig{
429-
Global: serpent.Duration(14 * 24 * time.Hour), // 14 days global
430-
WorkspaceAgentLogs: serpent.Duration(0), // Not set, falls back to global
431-
},
432-
logsAge: 15 * 24 * time.Hour, // 15 days ago
433-
expectDeleted: true,
434-
},
426+
435427
{
436428
name: "CustomRetention30Days",
437429
retentionConfig: codersdk.RetentionConfig{

coderd/database/queries/workspaceagents.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ INSERT INTO
199199
-- name: GetWorkspaceAgentLogSourcesByAgentIDs :many
200200
SELECT * FROM workspace_agent_log_sources WHERE workspace_agent_id = ANY(@ids :: uuid [ ]);
201201

202-
-- If an agent hasn't connected in the last 7 days, we purge it's logs.
202+
-- If an agent hasn't connected within the retention period, we purge its logs.
203203
-- Exception: if the logs are related to the latest build, we keep those around.
204204
-- Logs can take up a lot of space, so it's important we clean up frequently.
205205
-- name: DeleteOldWorkspaceAgentLogs :exec

docs/admin/setup/data-retention.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ a YAML configuration file.
2626

2727
### Settings
2828

29-
| Setting | CLI Flag | Environment Variable | Default | Description |
30-
|----------------------|------------------------------------|----------------------------------------|----------------|------------------------------------------|
31-
| Audit Logs | `--audit-logs-retention` | `CODER_AUDIT_LOGS_RETENTION` | `0` (disabled) | How long to retain Audit Log entries |
32-
| Connection Logs | `--connection-logs-retention` | `CODER_CONNECTION_LOGS_RETENTION` | `0` (disabled) | How long to retain Connection Logs |
33-
| API Keys | `--api-keys-retention` | `CODER_API_KEYS_RETENTION` | `7d` | How long to retain expired API keys |
34-
| Workspace Agent Logs | `--workspace-agent-logs-retention` | `CODER_WORKSPACE_AGENT_LOGS_RETENTION` | `7d` | How long to retain workspace agent logs |
29+
| Setting | CLI Flag | Environment Variable | Default | Description |
30+
|----------------------|------------------------------------|----------------------------------------|----------------|-----------------------------------------|
31+
| Audit Logs | `--audit-logs-retention` | `CODER_AUDIT_LOGS_RETENTION` | `0` (disabled) | How long to retain Audit Log entries |
32+
| Connection Logs | `--connection-logs-retention` | `CODER_CONNECTION_LOGS_RETENTION` | `0` (disabled) | How long to retain Connection Logs |
33+
| API Keys | `--api-keys-retention` | `CODER_API_KEYS_RETENTION` | `7d` | How long to retain expired API keys |
34+
| Workspace Agent Logs | `--workspace-agent-logs-retention` | `CODER_WORKSPACE_AGENT_LOGS_RETENTION` | `7d` | How long to retain workspace agent logs |
3535

3636
### Duration Format
3737

@@ -107,13 +107,14 @@ error message when users attempt to use an expired key.
107107

108108
### Workspace Agent Logs Behavior
109109

110-
Workspace agent logs are retained based on the retention period, but **logs from
111-
the latest build of each workspace are always retained** regardless of age. This
112-
ensures you can always debug issues with active workspaces.
110+
Workspace agent logs are deleted based on when the agent last connected, not the
111+
age of the logs themselves. **Logs from the latest build of each workspace are
112+
always retained** regardless of when the agent last connected. This ensures you
113+
can always debug issues with active workspaces.
113114

114-
Only logs from non-latest workspace builds that are older than the retention
115-
period are deleted. Setting `--workspace-agent-logs-retention=7d` keeps all logs
116-
from the latest build plus logs from previous builds for up to 7 days.
115+
For non-latest builds, logs are deleted if the agent hasn't connected within the
116+
retention period. Setting `--workspace-agent-logs-retention=7d` deletes logs for
117+
agents that haven't connected in 7 days (excluding those from the latest build).
117118

118119
## Best Practices
119120

@@ -183,4 +184,4 @@ containing the table name (e.g., `audit_logs`, `connection_logs`, `api_keys`).
183184
- [Audit Logs](../security/audit-logs.md): Learn about Audit Logs and manual
184185
purge procedures.
185186
- [Connection Logs](../monitoring/connection-logs.md): Learn about Connection
186-
Logs and monitoring.
187+
Logs and monitoring.

docs/reference/api/general.md

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/api/schemas.md

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)