From d49268558c0e7f887d0d258596fcfd6f74431825 Mon Sep 17 00:00:00 2001 From: Mahendra Paipuri Date: Thu, 4 Jan 2024 16:23:35 +0100 Subject: [PATCH] feat: Query for changes after db row deletion * Emit log in debug mode on how many rows deleted Signed-off-by: Mahendra Paipuri --- pkg/jobstats/db/db.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/jobstats/db/db.go b/pkg/jobstats/db/db.go index 4ba1c26d..7f346ba1 100644 --- a/pkg/jobstats/db/db.go +++ b/pkg/jobstats/db/db.go @@ -401,16 +401,21 @@ func (j *jobStatsDB) vacuumDB() error { // Delete old entries in DB func (j *jobStatsDB) deleteOldJobs(tx *sql.Tx) error { - deleteSQLCmd := fmt.Sprintf( + deleteRowQuery := fmt.Sprintf( "DELETE FROM %s WHERE Start <= date('now', '-%d day')", j.jobstatDBTable, int(j.retentionPeriod.Hours()/24), ) - _, err := tx.Exec(deleteSQLCmd) + _, err := tx.Exec(deleteRowQuery) if err != nil { level.Error(j.logger).Log("msg", "Failed to delete old jobs", "err", err) return err } + + // Get changes + var rowsDeleted int + _ = tx.QueryRow("SELECT changes();").Scan(&rowsDeleted) + level.Debug(j.logger).Log("msg", "Queried for changes after deletion", "rowsDeleted", rowsDeleted) return nil }