- Notifications
You must be signed in to change notification settings - Fork1.1k
feat(coderd/database/dbpurge): add retention for connection logs#21022
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:mafredri/feat-coderd-db-retention-policy
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -25,6 +25,9 @@ const ( | ||
| // but we won't touch the `connection_logs` table. | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Should probably be updated | ||
| maxAuditLogConnectionEventAge = 90 * 24 * time.Hour // 90 days | ||
| auditLogConnectionEventBatchSize = 1000 | ||
| // Batch size for connection log deletion. Smaller batches prevent long-held | ||
| // locks that could impact concurrent database operations. | ||
| connectionLogsBatchSize = 1000 | ||
| // Telemetry heartbeats are used to deduplicate events across replicas. We | ||
| // don't need to persist heartbeat rows for longer than 24 hours, as they | ||
| // are only used for deduplication across replicas. The time needs to be | ||
| @@ -111,9 +114,26 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, vals *coder | ||
| return xerrors.Errorf("failed to delete old aibridge records: %w", err) | ||
| } | ||
| var purgedConnectionLogs int64 | ||
| connectionLogsRetention := vals.Retention.ConnectionLogs.Value() | ||
| if connectionLogsRetention == 0 { | ||
| connectionLogsRetention = vals.Retention.Global.Value() | ||
| } | ||
| if connectionLogsRetention > 0 { | ||
| deleteConnectionLogsBefore := start.Add(-connectionLogsRetention) | ||
| purgedConnectionLogs, err = tx.DeleteOldConnectionLogs(ctx, database.DeleteOldConnectionLogsParams{ | ||
| BeforeTime: deleteConnectionLogsBefore, | ||
| LimitCount: connectionLogsBatchSize, | ||
| }) | ||
| if err != nil { | ||
| return xerrors.Errorf("failed to delete old connection logs: %w", err) | ||
| } | ||
| } | ||
| logger.Debug(ctx, "purged old database entries", | ||
| slog.F("expired_api_keys", expiredAPIKeys), | ||
| slog.F("aibridge_records", purgedAIBridgeRecords), | ||
| slog.F("connection_logs", purgedConnectionLogs), | ||
| slog.F("duration", clk.Since(start)), | ||
| ) | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.