Skip to content

Commit

Permalink
fix: wrongfully undeleting deleted items
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed Jul 4, 2024
1 parent c1757d5 commit 6c8bbc3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
3 changes: 3 additions & 0 deletions db/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func updateCI(ctx api.ScrapeContext, result v1.ScrapeResult, ci, existing *model
if ci.DeletedAt != existing.DeletedAt {
updates["deleted_at"] = ci.DeletedAt
updates["delete_reason"] = ci.DeleteReason
} else {
updates["deleted_at"] = gorm.Expr("NULL")
updates["delete_reason"] = gorm.Expr("NULL")
}

changeResult, err := generateConfigChange(*ci, *existing)
Expand Down
18 changes: 0 additions & 18 deletions scrapers/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,5 @@ func UpdateStaleConfigItems(ctx api.ScrapeContext, results v1.ScrapeResults) err
}
}

// Any config item that was previously marked as deleted should be un-deleted
// if the item was re-discovered in this run.
if val := ctx.Value(contextKeyScrapeStart); val != nil {
if start, ok := val.(time.Time); ok {
query := `UPDATE config_items
SET deleted_at = NULL
WHERE deleted_at IS NOT NULL
AND deleted_at != updated_at
AND ((NOW() - last_scraped_time) <= INTERVAL '1 SECOND' * ?)`
tx := ctx.DutyContext().DB().Exec(query, time.Since(start).Seconds())
if err := tx.Error; err != nil {
return fmt.Errorf("error un-deleting stale config items: %w", err)
}

ctx.Logger.V(3).Infof("undeleted %d stale config items", tx.RowsAffected)
}
}

return nil
}

0 comments on commit 6c8bbc3

Please sign in to comment.