K8SPSMDB-1202 add logs for scheduled backup cleanup#2381
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds additional structured logging around scheduled backup retention cleanup in the Percona Server for MongoDB operator, improving observability when old scheduled backups are deleted.
Changes:
- Log when retention-count cleanup is about to remove scheduled backups.
- Log each backup deletion and include the backup name in deletion error logs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if len(oldjobs) > 0 { | ||
| log.Info("cleaning up old backups based on retention count", | ||
| "job", item.Name, "keep", ret.Count, "toDelete", len(oldjobs)) | ||
| } |
| for _, todel := range oldjobs { | ||
| log.Info("deleting outdated backup", "job", item.Name, "backup", todel.Name) | ||
| err = r.client.Delete(ctx, &todel) | ||
| if err != nil { | ||
| log.Error(err, "failed to delete backup object") | ||
| log.Error(err, "failed to delete backup object", "backup", todel.Name) |
| if len(oldjobs) > 0 { | ||
| log.Info("cleaning up old backups based on retention count", | ||
| "job", item.Name, "keep", ret.Count, "toDelete", len(oldjobs)) | ||
| } |
| if len(oldjobs) > 0 { | ||
| log.Info("cleaning up old backups based on retention count", | ||
| "job", item.Name, "keep", ret.Count, "toDelete", len(oldjobs)) | ||
| } |
There was a problem hiding this comment.
Why do we have this log when, at the same time we are iterating oldjobs and we generate one log for each old job we have?
| } | ||
|
|
||
| for _, todel := range oldjobs { | ||
| log.Info("deleting outdated backup", "job", item.Name, "backup", todel.Name) |
There was a problem hiding this comment.
I would't say that these old jobs are outdated, they are not. They are just exceeding retention. Maybe we can say exceeding retention
There was a problem hiding this comment.
suggestion: deleting backup exceeding retention
| log.Info("deleting backup exceeding retention", "job", item.Name, "backup", todel.Name) | ||
| err = r.client.Delete(ctx, &todel) | ||
| if err != nil { | ||
| log.Error(err, "failed to delete backup object") | ||
| log.Error(err, "failed to delete backup object", "backup", todel.Name) | ||
| return true |
| log.Info("deleting backup exceeding retention", "job", item.Name, "backup", todel.Name) | ||
| err = r.client.Delete(ctx, &todel) | ||
| if err != nil { | ||
| log.Error(err, "failed to delete backup object") | ||
| log.Error(err, "failed to delete backup object", "backup", todel.Name) | ||
| return true |
commit: c451228 |
| log.Info("deleting backup exceeding retention", "job", item.Name, "backup", todel.Name) | ||
| err = r.client.Delete(ctx, &todel) | ||
| if err != nil { | ||
| log.Error(err, "failed to delete backup object") | ||
| log.Error(err, "failed to delete backup object", "backup", todel.Name) | ||
| return true |
CHANGE DESCRIPTION
Problem:
Short explanation of the problem.
Logs about scheduled clean up were added.
Cause:
Short explanation of the root cause of the issue if applicable.
Solution:
Short explanation of the solution we are providing with this PR.
CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
compare/*-oc.yml)?Config/Logging/Testability