Delete historical vulnerability statistics entries older than 90 days
What does this MR do?
Related to #217811 (closed)
This change adds a new worker that deletes historical vulnerability statistics from the database that are older than 90 days. We are deleting historical vulnerability statistic entries older than 90 days, and leaving only one record that is older or from 90 days ago.
Migrations
⋊> ~/D/g/gitlab on 217811-add-vulnerability-historical-statistcs-deletion-worker ⨯ be rake db:migrate 08:16:39
== 20200724100123 AddIndexOnVulnerabilityHistoricalStatisticsDate: migrating ==
-- transaction_open?()
-> 0.0000s
-- index_exists?(:vulnerability_historical_statistics, :date, {:algorithm=>:concurrently})
-> 0.0021s
-- add_index(:vulnerability_historical_statistics, :date, {:algorithm=>:concurrently})
-> 0.0123s
== 20200724100123 AddIndexOnVulnerabilityHistoricalStatisticsDate: migrated (0.0147s)
⋊> ~/D/g/gitlab on 217811-add-vulnerability-historical-statistcs-deletion-worker ⨯ be rake db:rollback 08:16:55
== 20200724100123 AddIndexOnVulnerabilityHistoricalStatisticsDate: reverting ==
-- transaction_open?()
-> 0.0000s
-- index_exists?(:vulnerability_historical_statistics, :date, {:algorithm=>:concurrently})
-> 0.0032s
-- remove_index(:vulnerability_historical_statistics, {:algorithm=>:concurrently, :column=>:date})
-> 0.0032s
== 20200724100123 AddIndexOnVulnerabilityHistoricalStatisticsDate: reverted (0.0068s)
Queries
SELECT "vulnerability_historical_statistics"."id" FROM "vulnerability_historical_statistics" WHERE (vulnerability_historical_statistics.date < now() - interval '100 days') ORDER BY "vulnerability_historical_statistics"."id";
Without index: https://explain.depesz.com/s/AbCc (~0.4ms) [only few hundred rows] With index: https://explain.depesz.com/s/xPsQ (~0.8ms)
Rows generated with:
exec INSERT INTO vulnerability_historical_statistics (date, project_id, letter_grade, created_at, updated_at) (SELECT date_trunc(‘day’, dd)::date date, 278964 project_id, 0 letter_grade, now() created_at, now() updated_at FROM generate_series (‘2018-01-01’::timestamp, ‘2020-05-01’::timestamp, ‘1 day’::interval) dd);
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Alan (Maciej) Paruszewski