diff options
Diffstat (limited to 'lib/gitlab/analytics/cycle_analytics/stage_events')
6 files changed, 37 insertions, 4 deletions
diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb index 9f0ca80ba50..c5f843d5f1a 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/code_stage_start.rb @@ -21,6 +21,11 @@ module Gitlab issue_metrics_table[:first_mentioned_in_commit_at] end + override :column_list + def column_list + [timestamp_projection] + end + # rubocop: disable CodeReuse/ActiveRecord def apply_query_customization(query) issue_metrics_join = mr_closing_issues_table diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end.rb index 0ea98e82ecc..7c1f4436c93 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/issue_stage_end.rb @@ -18,10 +18,15 @@ module Gitlab end def timestamp_projection - Arel::Nodes::NamedFunction.new('COALESCE', [ + Arel::Nodes::NamedFunction.new('COALESCE', column_list) + end + + override :column_list + def column_list + [ issue_metrics_table[:first_associated_with_milestone_at], issue_metrics_table[:first_added_to_board_at] - ]) + ] end # rubocop: disable CodeReuse/ActiveRecord diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/metrics_based_stage_event.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/metrics_based_stage_event.rb index 4ca8745abe4..fe477490648 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/metrics_based_stage_event.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/metrics_based_stage_event.rb @@ -10,6 +10,11 @@ module Gitlab query.joins(:metrics) end # rubocop: enable CodeReuse/ActiveRecord + + override :column_list + def column_list + [timestamp_projection] + end end end end diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start.rb index 37168a1fb0f..bddc326de71 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/plan_stage_start.rb @@ -18,10 +18,15 @@ module Gitlab end def timestamp_projection - Arel::Nodes::NamedFunction.new('COALESCE', [ + Arel::Nodes::NamedFunction.new('COALESCE', column_list) + end + + override :column_list + def column_list + [ issue_metrics_table[:first_associated_with_milestone_at], issue_metrics_table[:first_added_to_board_at] - ]) + ] end # rubocop: disable CodeReuse/ActiveRecord diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/production_stage_end.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/production_stage_end.rb index 619b45664fa..cf05ebeb706 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/production_stage_end.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/production_stage_end.rb @@ -21,6 +21,11 @@ module Gitlab mr_metrics_table[:first_deployed_to_production_at] end + override :column_list + def column_list + [timestamp_projection] + end + # rubocop: disable CodeReuse/ActiveRecord def apply_query_customization(query) query.joins(merge_requests_closing_issues: { merge_request: [:metrics] }).where(mr_metrics_table[:first_deployed_to_production_at].gteq(mr_table[:created_at])) diff --git a/lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb b/lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb index 0c75a141c3c..79738747e71 100644 --- a/lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb +++ b/lib/gitlab/analytics/cycle_analytics/stage_events/stage_event.rb @@ -7,6 +7,7 @@ module Gitlab # Base class for expressing an event that can be used for a stage. class StageEvent include Gitlab::CycleAnalytics::MetricsTables + extend Gitlab::Utils::Override delegate :label_based?, to: :class @@ -32,6 +33,13 @@ module Gitlab raise NotImplementedError end + # List of columns that are referenced in the `timestamp_projection` expression + # Example timestamp projection: COALESCE(issue_metrics.created_at, issue_metrics.updated_at) + # Expected column list: issue_metrics.created_at, issue_metrics.updated_at + def column_list + [] + end + # Optionally a StageEvent may apply additional filtering or join other tables on the base query. def apply_query_customization(query) query |