Skip to content

Update namespace statistics when a project is deleted

What does this MR do and why?

Update namespace statistics when a project is deleted.

When a project is deleted, its dependent records that uses storage are also deleted (e.g job artifacts, pipeline artifacts, packages, etc).

Usually, changes to these records would trigger an update on project statistics and eventually namespace statistics through ProjectStatistics.increment_statistic and FlushCounterIncrementsWorker.

However, when the project is deleted, FlushCounterIncrementsWorker would not do anything because the record has been deleted. As a result, it does not execute the counter_attribute_after_flush callback and the Namespaces::ScheduleAggregationWorker.

To address this problem, when a project is deleted, we publishes a ProjectDeletedEvent to the event store. A Namespaces::RefreshStatisticsWorker is subscribed to this event, which then refreshes the namespace statistics.

Screenshots or screen recordings

Before deleting a project: Screenshot_2022-01-24_at_5.46.27_PM

After deleting a project: Screenshot_2022-01-24_at_5.46.48_PM

How to set up and validate locally

  1. Create a group group-1
  2. Create a project in group-1, group-1/project-1
  3. Create another project in group-1, group-1/project-2
  4. In both projects, run a CI pipeline to create artifacts. An example CI job can be found below.
  5. Wait until group-1 usage quota (Settings > Usage Quota) is updated to include all build artifacts from both projects.
  6. Delete project-2.
  7. View group-1 usage quota and verify that the usage no longer includes project-2 usage.

Example CI (creates ~23.84 MiB of artifact per pipeline):

test:
    parallel: 5
    script:
        - head -c 5000000 /dev/urandom > foo.txt
    artifacts:
        paths:
            - foo.txt

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #342049 (closed)

Edited by Albert

Merge request reports