Skip to content

Properly process stale container repository cleanups

David Fernandez requested to merge 330322-unstuck-stuck-cleanup-policies into master

🌵 Context

Cleanup policies are executed by background workers. Their execution can be summarized as getting the tags for the linked container images, apply the parameters of the cleanup policy and destroy all the tags that are excluded by the policy. This whole process is done using the container registry API (container image tags are not persisted in the rails backend database).

To be able to monitor what is happening with the cleanups, we introduced a cleanup status on container images (those are persisted in the rails backend database) that are processed by cleanup policies:

  • scheduled: cleanup will be done shortly
  • ongoing: cleanup is being executed
  • unfinished: cleanup took so long that it hit a limit and has been stopped

Since the cleanup process can go through different type of errors, such as network timeouts, we introduced a rescue block to make sure that the cleanup status was reset to something else than ongoing. This is important because ongoing cleanups are not considered by background workers when they pick the next work.

The problem is that Sidekiq can be shutdown in a rather abruptly way. The job is effectively "killed" and as such, the rescue block is not executed. This leads to stale ongoing cleanups.

This is issue #330322 (closed).

As part of the background jobs for cleanup policies, we have one that is roughly running each hour. This is the perfect place to add a change: detect stale ongoing cleanups and put them in the unfinished state.

🤔 What does this MR do?

  • Detect stale ongoing container repository cleanups and put them in the unfinished
  • The "stale" detection is done as the following:
    • The cleanup was started before T + 30.minutes. T is a limit we have for the service destroying all the tags. It is set in the application settings.
      • Let's illustrate this with gitlab.com. There we have a limit of 5.minutes for the destruction of all tags. Stale cleanups will therefore be all the cleanups that started 35 minutes ago. That's a period long enough to be confident that no job is actually executing the cleanup.

🖼 Screenshots (strongly suggested)

n / a

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • [-] 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

💽 Database review

We have a single UPDATE query: !62005 (comment 578411092)

Edited by David Fernandez

Merge request reports