Adjust max age for cron stats entries (#9190)

This commit is contained in:
gillespi314
2023-01-16 10:23:52 -06:00
committed by GitHub
parent 4033a95d25
commit bae10e0ba2
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ func (ds *Datastore) UpdateAllCronStatsForInstance(ctx context.Context, instance
func (ds *Datastore) CleanupCronStats(ctx context.Context) error {
deleteStmt := `DELETE FROM cron_stats WHERE created_at < DATE_SUB(NOW(), INTERVAL ? DAY)`
const MAX_DAYS_RETAINED = 14
const MAX_DAYS_RETAINED = 2
if _, err := ds.writer.ExecContext(ctx, deleteStmt, MAX_DAYS_RETAINED); err != nil {
return ctxerr.Wrap(ctx, err, "deleting old cron stats")
}
+3 -3
View File
@@ -105,7 +105,7 @@ func TestCleanupCronStats(t *testing.T) {
ctx := context.Background()
ds := CreateMySQLDS(t)
now := time.Now().UTC().Truncate(time.Second)
twoWeeksAgo := now.Add(-14 * 24 * time.Hour)
twoDaysAgo := now.Add(-2 * 24 * time.Hour)
name := "test_sched"
instance := "test_instance"
@@ -152,13 +152,13 @@ func TestCleanupCronStats(t *testing.T) {
shouldCleanupMaxAge: false,
},
{
createdAt: twoWeeksAgo.Add(1 * time.Hour),
createdAt: twoDaysAgo.Add(1 * time.Hour),
status: fleet.CronStatsStatusCompleted,
shouldCleanupMaxPending: false,
shouldCleanupMaxAge: false,
},
{
createdAt: twoWeeksAgo.Add(-1 * time.Hour),
createdAt: twoDaysAgo.Add(-1 * time.Hour),
status: fleet.CronStatsStatusCompleted,
shouldCleanupMaxPending: false,
shouldCleanupMaxAge: true,