554221 Fix Negative LtfC Dora metrics

What does this MR do and why?

During investigation of Dora::DailyMetrics::RefreshWorker errors (issue #553333 (closed)), we discovered that deployments can be linked to merge requests where the deployment finishes before the MR is merged. This causes negative Lead Time for Changes (LtfC) values, which violate the database constraint dora_daily_metrics_lead_time_for_changes_in_seconds_positive.

References

Screenshots or screen recordings

Before After

How to set up and validate locally

  • Update a deployment finished_at to be after the merge request merged_at timestamp:
d = Deployment.first 
d.update!(finsihed_at: Time.now)
  • Make sure that query can be executed without errors
dora = Dora::LeadTimeForChangesMetric.new(d.environment, Date.today)

ActiveRecord::Base.connection.execute(dora.data_queries[:lead_time_for_changes_in_seconds])

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #554221 (closed)

Edited by Amr Taha

Merge request reports

Loading