Commit bd23cbd6 authored by Stan Hu's avatar Stan Hu

Merge branch '500-metrics-creation' into 'master'

Generate metrics on commit

Closes #215166

See merge request gitlab-org/gitlab!32668
parents 64b93372 000f07c0
...@@ -104,7 +104,7 @@ class MergeRequest < ApplicationRecord ...@@ -104,7 +104,7 @@ class MergeRequest < ApplicationRecord
after_create :ensure_merge_request_diff after_create :ensure_merge_request_diff
after_update :clear_memoized_shas after_update :clear_memoized_shas
after_update :reload_diff_if_branch_changed after_update :reload_diff_if_branch_changed
after_save :ensure_metrics, unless: :importing? after_commit :ensure_metrics, on: [:create, :update], unless: :importing?
after_commit :expire_etag_cache, unless: :importing? after_commit :expire_etag_cache, unless: :importing?
# When this attribute is true some MR validation is ignored # When this attribute is true some MR validation is ignored
......
---
title: Fix for metrics creation when saving MR
merge_request: 32668
author:
type: fixed
...@@ -107,6 +107,10 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -107,6 +107,10 @@ class Gitlab::Seeder::CycleAnalytics
pipeline = FactoryBot.create(:ci_pipeline, :success, project: project) pipeline = FactoryBot.create(:ci_pipeline, :success, project: project)
build = FactoryBot.create(:ci_build, pipeline: pipeline, project: project, user: developers.sample) build = FactoryBot.create(:ci_build, pipeline: pipeline, project: project, user: developers.sample)
# Required because seeds run in a transaction and these are now
# created in an `after_commit` hook.
merge_request.ensure_metrics
merge_request.metrics.update!( merge_request.metrics.update!(
latest_build_started_at: merge_request.created_at, latest_build_started_at: merge_request.created_at,
latest_build_finished_at: within_end_time(merge_request.created_at + TEST_STAGE_MAX_DURATION_IN_HOURS.hours), latest_build_finished_at: within_end_time(merge_request.created_at + TEST_STAGE_MAX_DURATION_IN_HOURS.hours),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment