An error occurred while fetching the assigned milestone of the selected merge_request.
Add feature to delete inactive projects
-
Review changes -
-
Download -
Patches
-
Plain diff
Merged
Huzaifa Iftikhar requested to merge 357376_add_inactive_projects_deletion_feature into master
What does this MR do and why?
-
This MR currently targets !86211 (merged), once that MR is merged toThe dependent MR has been merged and this MR now targetsmaster
we can update the base branch tomaster
for this MR as well.master
. - Add inactive projects deletion feature.
- Add a cronjob that runs once daily, finds the inactive projects and perform the following action:
- Send deletion warning email to the inactive project's maintainers and owners. Store the date when the email was sent in redis hash.
- If we've already sent an email then it checks whether the project is still inactive for a duration greater than
inactive_projects_delete_after_months
defined in theapplication_settings
table. In case the project is still inactive it permanently deletes the project. - When an activity is performed on an inactive project after the deletion warning email was sent, we remove that project's key from the redis hash.
- The documentation is added in a separate MR !86907 (merged)
Screenshots or screen recordings
HTML version | Plain text |
---|---|
![]() |
![]() |
Instance audit events | Project audit events |
---|---|
![]() |
![]() |
![]() |
How to set up and validate locally
- Create a project under a group A. Let's call it as Project A.
- Create another project in group B. Let's call it Project B.
- Modify the
last_activity_at
of both the projects so that they are considered as inactive. For example:
project = Project.find(<id of Project A>)
project.last_activity_at = 3.years.ago
project.save!
- Enable feature flag for group A only.
Feature.enable(:inactive_projects_deletion, Namespace.without_project_namespaces.find_by_full_path('<name of Group A>'))
- Enable inactive projects deletion settings using the application_settings API. Example :
https://gdk.test:3000/api/v4/application/settings?delete_inactive_projects=true&inactive_projects_send_warning_email_after_months=6&inactive_projects_delete_after_months=10&inactive_projects_min_size_mb=0
- Connect to your local redis using CLI -
redis-cli -s <path-to-gitlab-development-kit>/redis/redis.socket
. Verify that redis hash is empty by runninghgetall inactive_projects_deletion_warning_email_notified
inside the redis CLI. - Manually modify
1_settings.rb
file and update theinactive_projects_deletion_cron_worker
cron timing to run every minute. This will help us test the feature fast. Restart the background jobs usinggdk restart rails-background-jobs
- Settings.cron_jobs['inactive_projects_deletion_cron_worker']['cron'] ||= '0 1 * * *'
- Settings.cron_jobs['inactive_projects_deletion_cron_worker']['cron'] ||= '* * * * *'
- Wait for
Projects::InactiveProjectsDeletionCronWorker
to run. You can tail the logsgdk tail rails-background-jobs | grep -i inactive
. - After the cron has executed once, visit
https://gdk.test:3000/rails/letter_opener/
and verify that we've received the deletion warning email for Project A. Also verify that no email should have been received for Project B (we didn't enable the feature flag for this project). - Verify that the redis key has been updated. Run
hgetall inactive_projects_deletion_warning_email_notified
in redis-cli and verify that the key for project A exists. The value should be the current date which signifies the date when the deletion warning email was sent. - Manually update the redis value to simulate that the deletion warning email was sent more than (
inactive_projects_delete_after_months - inactive_projects_send_warning_email_after_months
) months ago (4 months as per our example). Run the following to update via redis-clihset inactive_projects_deletion_warning_email_notified project:<project_if of Project A> 2021-04-25
- Wait for
Projects::InactiveProjectsDeletionCronWorker
to run again. This time the project should get deleted immediately or should get marked for deletion if the project had enabled delayed project deletion. - Visit the homepage of Project A and verify that the project is either deleted or marked for deletion.
- Visit the homepage of Project B and verify that the project is neither deleted nor marked for deletion.
- Verify that the redis key has been deleted.
hgetall inactive_projects_deletion_warning_email_notified
- Visit the instance audit events dashboard and verify that audit events for deletion warning emails are captured successfully.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/357376
Edited by Huzaifa Iftikhar
Merge request reports
Compare and
Show latest version
- version 18b8cf25a5
- version 17ba26c1c4
- version 16ba26c1c4
- version 15db92450c
- version 14cd0c653b
- version 133a296f61
- version 123a296f61
- version 113a296f61
- version 103a296f61
- version 98f601018
- version 85faeeedf
- version 7c20942f3
- version 6f1acf38a
- version 5bc84c9b1
- version 48c228b31
- version 35bf97665
- version 207ddaef1
- version 11ef46cb6
- master (base)
- latest version17569f447 commits,
- version 18b8cf25a56 commits,
- version 17ba26c1c46 commits,
- version 16ba26c1c46 commits,
- version 15db92450c5 commits,
- version 14cd0c653b4 commits,
- version 133a296f613 commits,
- version 123a296f613 commits,
- version 113a296f611 commit,
- version 103a296f613 commits,
- version 98f6010181 commit,
- version 85faeeedf1 commit,
- version 7c20942f31 commit,
- version 6f1acf38a1 commit,
- version 5bc84c9b11 commit,
- version 48c228b311 commit,
- version 35bf976651 commit,
- version 207ddaef11 commit,
- version 11ef46cb61 commit,
Compare changes
- Side-by-side
- Inline
Files
203Loading