Skip to content

Commit

Permalink
Delete container logs older than 24 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed Jun 1, 2024
1 parent 0384967 commit a6893f3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/icinga-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ func main() {
return
}
}, periodic.Immediate()).Stop()

defer periodic.Start(ctx, time.Hour, func(tick periodic.Tick) {
olderThan := tick.Time.AddDate(0, 0, -1)

_, err := db.CleanupOlderThan(
ctx, database.CleanupStmt{
Table: "container_log",
PK: "container_id, pod_id, period",
Column: "last_update",
}, 5000, olderThan,
)
if err != nil {
select {
case errs <- err:
case <-ctx.Done():
}

return
}
}, periodic.Immediate()).Stop()
com.ErrgroupReceive(ctx, g, errs)

if err := g.Wait(); err != nil {
Expand Down

0 comments on commit a6893f3

Please sign in to comment.