Skip to content

feat(context): delete old scanner runs - #1335

Merged
MR2011 merged 6 commits into
mainfrom
mikrzyz/issue-1328
Nov 18, 2026
Merged

MR2011 merged 6 commits into
mainfrom
mikrzyz/issue-1328

Conversation

@michalkrzyz

@michalkrzyz michalkrzyz commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Delete scanner runs which are old (with configurable retention)
  • For deleted scanner runs delete all associated Coponent Instance Trackers and Errors
  • Change autopatch database objects' ids from int to int64

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

  • Related Issue # (issue)
  • Closes # (issue)
  • Fixes # (issue)

Remove if not applicable

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 10:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Concurrent cleanup can delete trackers still needed by autopatch, leaving vulnerabilities unpatched, while soft-deleted runs remain visible and counted by production queries.

4 open issues
What changed in this PR

Adds configurable scanner-run retention to the scanner completion workflow, removing older completed runs’ trackers and errors while soft-deleting the runs.

Changes:

  • Adds per-tag retention configuration, disabled by default, and invokes cleanup after autopatch.
  • Extends database interfaces and wrappers for cleanup and standardizes autopatch identifiers on int64.
  • Adds cleanup tests and fixtures, updates handler construction, and changes gRPC checksums.
File Description
internal/​util/​config.go Adds scanner-run retention configuration.
internal/​database/​mariadb/​trace_db.go Adds traced context-aware execution.
internal/​database/​mariadb/​test/​scanner_fixture.go Adds scanner-run error seeding.
internal/​database/​mariadb/​test/​fixture.go Seeds runs with associated errors and trackers.
internal/​database/​mariadb/​quiet_db.go Adds context-aware execution forwarding.
internal/​database/​mariadb/​db.go Extends the database wrapper interface with ExecContext.
internal/​database/​mariadb/​database.go Exposes the database wrapper for test queries.
internal/​database/​mariadb/​component_instance.go Adds a TODO comment about tracker deletion.
internal/​database/​mariadb/​autopatch.go Standardizes run and component identifiers on int64.
internal/​database/​mariadb/​autoclean.go Implements retention selection and associated-data cleanup.
internal/​database/​mariadb/​autoclean_test.go Tests retention and removal of associated data.
internal/​database/​interface.go Adds the Autoclean database operation.
internal/​app/​scanner_run/​scanner_run_test.go Updates handler construction with retention arguments.
internal/​app/​scanner_run/​scanner_run_handler.go Invokes cleanup after successful autopatch.
internal/​app/​heureka.go Passes retention configuration to the scanner-run handler.
go.sum Replaces gRPC 1.83.1 checksums with 1.83.2 checksums.

Review effort: Balanced

Comment thread internal/database/mariadb/autoclean.go Resolved
Comment thread internal/database/mariadb/autoclean.go Resolved
Comment thread internal/database/mariadb/autoclean.go Resolved
@michalkrzyz michalkrzyz changed the title feat(scanner): Add autoclean for scannerrun feat(context): delete old scanner runs Nov 9, 2026
@michalkrzyz
michalkrzyz force-pushed the mikrzyz/issue-1328 branch 2 times, most recently from 6971434 to 177248e Compare November 10, 2026 10:33
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Retention cleanup leaves soft-deleted runs visible in public reads, can delete runs still uploading, and lacks transactional protection against partial deletion of scan history.

7 open issues
1 resolved since last review

Review effort: Balanced

Comment thread internal/database/mariadb/autoclean.go Resolved
Comment thread internal/database/mariadb/autoclean.go Resolved
Comment thread internal/database/mariadb/autopatch.go Resolved
Comment thread internal/database/mariadb/autopatch.go Resolved
@michalkrzyz
michalkrzyz force-pushed the mikrzyz/issue-1328 branch 2 times, most recently from f6241bf to f73edfe Compare November 16, 2026 12:31
@michalkrzyz
michalkrzyz requested a balanced review from Copilot November 16, 2026 12:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cleanup can delete newly created runs and their associated data because it uses a stale keep-list, while the new tests also leave seeder database connections open.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Close the seeder connection pool after test setup

internal/​database/​mariadb/​autoclean_test.go:138

NewDatabaseSeeder opens a separate database connection pool, but this helper drops the seeder reference without closing it. The teardown only closes at.db and the database manager's client, so each new test leaves its seeder pool open. Please defer dbSeeder.CloseDbConnection() after the successful setup check; the seeder is no longer needed once this helper returns.

7 resolved since last review

Review effort: Balanced

Comment thread internal/database/mariadb/autoclean.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Autopatch now loads all non-deleted failed and in-progress runs on every successful completion, creating growing transfer and allocation overhead because default retention never prunes that history.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread internal/database/mariadb/autopatch.go Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The global guard can cause scanner lifecycle requests to time out across tags, while retention-count overflow can trigger unintended deletion of run history.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment on lines +17 to +20
if err := s.acquireScannerRunAccess(defaultTimeoutForScannerRunLock); err != nil {
return false, err
}
defer s.releaseScannerRunAccess()
Comment thread internal/database/mariadb/autoclean.go Resolved
- change logic to delete not listed items
- add synchronization for Autoclean, Autopatch and
scannerrun table create/update

On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
michalkrzyz and others added 2 commits November 17, 2026 16:07
On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com>
Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
@MR2011
MR2011 merged commit b8d6b2b into main Nov 18, 2026
11 checks passed
@MR2011
MR2011 deleted the mikrzyz/issue-1328 branch November 18, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants