- Notifications
You must be signed in to change notification settings - Fork1.1k
feat: purge expired api keys in dbpurge#20863
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
Changes fromall commits
591f15fa0df0019dd6bb7d068ae011bf986db6f8be55986af43290cd2bd04087851a70File 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 |
|---|---|---|
| @@ -78,6 +78,19 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, vals *coder | ||
| if err := tx.ExpirePrebuildsAPIKeys(ctx, dbtime.Time(start)); err != nil { | ||
| return xerrors.Errorf("failed to expire prebuilds user api keys: %w", err) | ||
| } | ||
| expiredAPIKeys, err := tx.DeleteExpiredAPIKeys(ctx, database.DeleteExpiredAPIKeysParams{ | ||
| // Leave expired keys for a week to allow the backend to know the difference | ||
| // between a 404 and an expired key. This purge code is just to bound the size of | ||
| // the table to something more reasonable. | ||
| Before: dbtime.Time(start.Add(time.Hour * 24 * 7 * -1)), | ||
| // There could be a lot of expired keys here, so set a limit to prevent this | ||
| // taking too long. | ||
| // This runs every 10 minutes, so it deletes ~1.5m keys per day at most. | ||
| LimitCount: 10000, | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| }) | ||
| if err != nil { | ||
| return xerrors.Errorf("failed to delete expired api keys: %w", err) | ||
| } | ||
| deleteOldTelemetryLocksBefore := start.Add(-maxTelemetryHeartbeatAge) | ||
| if err := tx.DeleteOldTelemetryLocks(ctx, deleteOldTelemetryLocksBefore); err != nil { | ||
| return xerrors.Errorf("failed to delete old telemetry locks: %w", err) | ||
| @@ -93,13 +106,16 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, vals *coder | ||
| deleteAIBridgeRecordsBefore := start.Add(-vals.AI.BridgeConfig.Retention.Value()) | ||
| // nolint:gocritic // Needs to run as aibridge context. | ||
| purgedAIBridgeRecords, err := tx.DeleteOldAIBridgeRecords(dbauthz.AsAIBridged(ctx), deleteAIBridgeRecordsBefore) | ||
| if err != nil { | ||
| return xerrors.Errorf("failed to delete old aibridge records: %w", err) | ||
| } | ||
| logger.Debug(ctx, "purged old database entries", | ||
| slog.F("expired_api_keys", expiredAPIKeys), | ||
| slog.F("aibridge_records", purgedAIBridgeRecords), | ||
| slog.F("duration", clk.Since(start)), | ||
| ) | ||
| return nil | ||
| }, database.DefaultTXOptions().WithID("db_purge")); err != nil { | ||
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.