Refresh DORA metrics once per successful deployment

What does this MR do and why?

Every successful deployment schedules Dora::DailyMetrics::RefreshWorker twice:

  1. The after_transition any => :success hook added by Dora::Watchers::DeploymentWatcher.mount.
  2. 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 for LinkMergeRequestWorker, which has already finished at that point.
  • Adds sidekiq_retries_exhausted and sidekiq_interruptions_exhausted handlers to the link worker. When linking fails on every retry, or the job is killed repeatedly (for example during a deploy), after_perform never 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 in mount, 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_jobs ops 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: true is 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

Screenshots or screen recordings

Not applicable, no UI changes.

How to set up and validate locally

  1. In the Rails console, enable the feature flag:

    Feature.enable(:dora_metrics_refresh_once_per_deployment)
  2. 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
  3. Disable the flag and repeat with another running deployment. Two jobs are scheduled, each with an at 5 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.

Edited by Tanishq Jain

Merge request reports

Loading
Loading