Skip to content

Commit

Permalink
chore(backend): cleanup stale bug reports
Browse files Browse the repository at this point in the history
closes #1838
  • Loading branch information
anupcowkur committed Feb 25, 2025
1 parent fdb2b64 commit 76ab750
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backend/cleanup/cleanup/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func DeleteStaleData(ctx context.Context) {
// delete span user defined attributes
deleteSpanUserDefAttrs(ctx, appRetentions)

// delete bug reports
deleteBugReports(ctx, appRetentions)

// delete sessions
deleteSessions(ctx, appRetentions)

Expand Down Expand Up @@ -288,6 +291,31 @@ func deleteSpanUserDefAttrs(ctx context.Context, retentions []AppRetention) {
}
}

// deleteBugReports deletes stale bug reports for each
// app's retention threshold.
func deleteBugReports(ctx context.Context, retentions []AppRetention) {
errCount := 0
for _, retention := range retentions {
stmt := sqlf.
DeleteFrom("bug_reports").
Where("app_id = toUUID(?)", retention.AppID).
Where("timestamp < ?", retention.Threshold)

if err := server.Server.ChPool.Exec(ctx, stmt.String(), stmt.Args()...); err != nil {
errCount += 1
fmt.Printf("Failed to delete stale bug reports for app id %q: %v\n", retention.AppID, err)
stmt.Close()
continue
}

stmt.Close()
}

if errCount < 1 {
fmt.Println("Successfully deleted stale bug reports")
}
}

// deleteSessions deletes stale sessions for each
// app's retention threshold.
func deleteSessions(ctx context.Context, retentions []AppRetention) {
Expand Down

0 comments on commit 76ab750

Please sign in to comment.