Refresh DORA metrics once per successful deployment
What does this MR do and why?
Every successful deployment schedules Dora::DailyMetrics::RefreshWorker twice:
- The
after_transition any => :successhook added byDora::Watchers::DeploymentWatcher.mount. EE::Deployments::LinkMergeRequestWorker#after_perform, added later to fix lead time inconsistencies when linking took longer than 5 minutes.
Both go through DeploymentWatcher#process, which uses perform_in(5.minutes). The two jobs reach the queue at different times, so deduplicate :until_executing rarely collapses them. Each run recounts the environment's deployments for the whole day on the primary database.
Behind the dora_metrics_refresh_once_per_deployment flag (gitlab_com_derisk), this MR:
- Skips the transition hook, so only the link worker triggers the refresh.
- Enqueues the refresh with
perform_async. The 5-minute delay existed to wait forLinkMergeRequestWorker, which has already finished at that point. - Adds
sidekiq_retries_exhaustedandsidekiq_interruptions_exhaustedhandlers to the link worker. When linking fails on every retry, or the job is killed repeatedly (for example during a deploy),after_performnever runs, so the handlers trigger the refresh instead. Today the transition hook covers those cases.
With the flag disabled, behaviour is unchanged.
Notes for reviewers
- The flag is checked inside the transition hook and inside
#process, not inmount, which runs at class load time. - While the flag is being toggled, a deployment can still get two refreshes (as today). It only gets none if linking fails or is interrupted on every attempt and the flag goes from enabled to disabled in that window.
- A link job dropped outright (for example by the
drop_sidekiq_jobsops flag) calls neither handler, so that deployment's refresh waits for the next deployment or incident on the same environment. deduplicate :until_executing, including_scheduled: trueis not added. Once the flag is enabled, nothing schedules this worker with a delay, so it would have no effect, and it can't be put behind the flag.- No changelog entry, because the change is behind a default-off flag.
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/636174
- Commit that added the link worker trigger: 74100901
Screenshots or screen recordings
Not applicable, no UI changes.
How to set up and validate locally
-
In the Rails console, enable the feature flag:
Feature.enable(:dora_metrics_refresh_once_per_deployment) -
Make a running deployment succeed and run the link worker inline, then check the enqueued jobs:
require 'sidekiq/testing' Sidekiq::Testing.fake! do deployment = Deployment.running.last # or create one for any project with an environment deployment.succeed! Deployments::LinkMergeRequestWorker.new.perform(deployment.id) Dora::DailyMetrics::RefreshWorker.jobs.map { |job| [job['args'], job['at']] } # => one job, with no `at` (enqueued immediately) end -
Disable the flag and repeat with another running deployment. Two jobs are scheduled, each with an
at5 minutes ahead.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.