From 76ab7503847675b82a5a2bdf31fa936d23d1d689 Mon Sep 17 00:00:00 2001 From: Anup Cowkur Date: Tue, 25 Feb 2025 15:15:26 +0530 Subject: [PATCH] chore(backend): cleanup stale bug reports closes #1838 --- backend/cleanup/cleanup/cleanup.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/backend/cleanup/cleanup/cleanup.go b/backend/cleanup/cleanup/cleanup.go index 360c76a24..91eaacb42 100644 --- a/backend/cleanup/cleanup/cleanup.go +++ b/backend/cleanup/cleanup/cleanup.go @@ -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) @@ -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) {