Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce maintenance tasks; Unify cron and lock duration configs for tasks #840

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

nscuro
Copy link
Member

@nscuro nscuro commented Aug 8, 2024

Description

Adds maintenance tasks to help with freeing the database from unwanted bloat:

  • ComponentMetadataMaintenanceTask deletes dangling IntegrityMetaComponent and RepositoryMetaComponent records, which would otherwise accumulate forever.
  • MetricsMaintenanceTask deletes metrics records older than a configurable retention period (90 days per default). Since the frontend only shows metrics for up to 90 days, it doesn't make sense to keep older data around. Users with longer retention requirements can re-configure this in the UI.
  • TagMaintenanceTask deletes tags that are not used, i.e. not associated with any project, policy, or notification rule. This is particularly useful for organizations that make use of ephemeral, or frequently changing tags.
  • VulnerabilityDatabaseMaintenanceTask deletes VulnerableSoftware records that are no longer referenced by any Vulnerability. Such orphaned records can happen when vulnerability databases such as the NVD update a vulnerability's affected version ranges, or affected components entirely.

The following existing cleanup tasks were renamed accordingly to fit the new maintenance convention:

  • VulnerabilityScanCleanupTask -> VulnerabilityScanMaintenanceTask
  • WorkflowStateCleanupTask -> WorkflowMaintenanceTask

They were additionally refactored to make use of bulk SQL UPDATE / DELETE statements, rather than modifying individual records via the ORM. This makes them both better performing and more concurrency-friendly.

The way how cron and lock duration configuration is retrieved for tasks was refactored to be more uniform. Now, property names align with a task's class name, and follow a predictable structure, voiding the need for separate ConfigKey definitions.

For example:

  • task.cron.metrics.portfolio -> task.portfolio.metrics.update.cron
  • task.metrics.portfolio.lockAtMostForInMillis -> task.portfolio.metrics.update.lock.max.duration
  • task.metrics.portfolio.lockAtLeastForInMillis -> task.portfolio.metrics.update.lock.min.duration

Addressed Issue

N/A

Additional Details

N/A

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have updated the migration changelog accordingly
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

@nscuro nscuro added enhancement New feature or request technical debt labels Aug 8, 2024
@nscuro nscuro added this to the 5.6.0 milestone Aug 8, 2024
Copy link

codacy-production bot commented Aug 8, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.02% (target: -1.00%) 78.41% (target: 70.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (40293f8) 21233 17467 82.26%
Head commit (9bfe302) 21308 (+75) 17524 (+57) 82.24% (-0.02%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#840) 352 276 78.41%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@nscuro nscuro force-pushed the merge-housekeeping-tasks branch from 18689e4 to 70d4d71 Compare August 14, 2024 15:25
@nscuro nscuro modified the milestones: 5.6.0, 5.7.0 Aug 22, 2024
@nscuro nscuro force-pushed the merge-housekeeping-tasks branch 5 times, most recently from 513f55c to e03fcff Compare August 30, 2024 13:26
@nscuro nscuro marked this pull request as draft August 30, 2024 13:27
@nscuro nscuro force-pushed the merge-housekeeping-tasks branch 5 times, most recently from 283094a to 989ecee Compare September 2, 2024 15:15
@nscuro nscuro changed the title Merge cleanup tasks into a single Housekeeping task Introduce maintenance tasks; Unify cron and lock duration configs for tasks Sep 2, 2024
@nscuro nscuro force-pushed the merge-housekeeping-tasks branch 2 times, most recently from 5319d08 to 6c5e730 Compare September 6, 2024 08:57
@nscuro nscuro force-pushed the merge-housekeeping-tasks branch 3 times, most recently from faecfa9 to 2deddf4 Compare September 6, 2024 16:07
@nscuro nscuro marked this pull request as ready for review September 6, 2024 16:43
@nscuro nscuro force-pushed the merge-housekeeping-tasks branch 3 times, most recently from ef0de73 to 8ab260e Compare September 9, 2024 10:42
@nscuro nscuro force-pushed the merge-housekeeping-tasks branch 2 times, most recently from 235fd7a to 9fac32d Compare September 9, 2024 12:44
@nscuro nscuro modified the milestones: 5.7.0, 5.6.0 Sep 9, 2024
@nscuro nscuro force-pushed the merge-housekeeping-tasks branch from 9fac32d to 5c8f3ab Compare September 9, 2024 19:27
… tasks

Adds maintenance tasks to help with freeing the database from unwanted bloat:

* `ComponentMetadataMaintenanceTask` deletes dangling `IntegrityMetaComponent` and `RepositoryMetaComponent` records, which would otherwise accumulate forever.
* `MetricsMaintenanceTask` deletes metrics records older than a configurable retention period (90 days per default). Since the frontend only shows metrics for up to 90 days, it doesn't make sense to keep older data around. Users with longer retention requirements can re-configure this in the UI.
* `TagMaintenanceTask` deletes tags that are not used, i.e. not associated with any project, policy, or notification rule. This is particularly useful for organizations that make use of ephemeral, or frequently changing tags.
* `VulnerabilityDatabaseMaintenanceTask` deletes `VulnerableSoftware` records that are no longer referenced by any `Vulnerability`. Such orphaned records can happen when vulnerability databases such as the NVD update a vulnerability's affected version ranges, or affected components entirely.

The following existing cleanup tasks were renamed accordingly to fit the new maintenance convention:

* `VulnerabilityScanCleanupTask` -> `VulnerabilityScanMaintenanceTask`
* `WorkflowStateCleanupTask` -> `WorkflowMaintenanceTask`

They were additionally refactored to make use of bulk SQL `UPDATE` / `DELETE` statements, rather than modifying individual records via the ORM. This makes them both better performing and more concurrency-friendly.

The way how cron and lock duration configuration is retrieved for tasks was refactored to be more uniform. Now, property names align with a task's class name, and follow a predictable structure, voiding the need for separate `ConfigKey` definitions.

For example:

* `task.cron.metrics.portfolio` -> `task.portfolio.metrics.update.cron`
* `task.metrics.portfolio.lockAtMostForInMillis` -> `task.portfolio.metrics.update.lock.max.duration`
* `task.metrics.portfolio.lockAtLeastForInMillis` -> `task.portfolio.metrics.update.lock.min.duration`

Signed-off-by: nscuro <[email protected]>
@nscuro nscuro force-pushed the merge-housekeeping-tasks branch from 5c8f3ab to 9bfe302 Compare September 9, 2024 20:26
@nscuro nscuro merged commit eca7ab7 into main Sep 9, 2024
9 checks passed
@nscuro nscuro deleted the merge-housekeeping-tasks branch September 9, 2024 20:58
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant