Commit 3268e377 authored by James Lopez's avatar James Lopez

WIP - started refactoring cycle analytics median stuff into stages

parent e7fdb1aa
class CycleAnalytics
STAGES = %i[issue plan code test review staging production].freeze
def initialize(project, current_user, from:)
def initialize(project, from:)
@project = project
@current_user = current_user
@from = from
@fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project, from: from, branch: nil)
@options = options
end
def summary
@summary ||= Summary.new(@project, @current_user, from: @from)
@summary ||= Summary.new(@project, from: @options[:from])
end
def method_missing(method_sym, *arguments, &block)
classify_stage(method_sym).new(project: @project, options: @options, stage: method_sym)
def permissions(user:)
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
end
......@@ -23,40 +23,7 @@ class CycleAnalytics
Issue::Metrics.arel_table[:first_added_to_board_at]])
end
def plan
@fetcher.calculate_metric(:plan,
[Issue::Metrics.arel_table[:first_associated_with_milestone_at],
Issue::Metrics.arel_table[:first_added_to_board_at]],
Issue::Metrics.arel_table[:first_mentioned_in_commit_at])
end
def code
@fetcher.calculate_metric(:code,
Issue::Metrics.arel_table[:first_mentioned_in_commit_at],
MergeRequest.arel_table[:created_at])
end
def test
@fetcher.calculate_metric(:test,
MergeRequest::Metrics.arel_table[:latest_build_started_at],
MergeRequest::Metrics.arel_table[:latest_build_finished_at])
end
def review
@fetcher.calculate_metric(:review,
MergeRequest.arel_table[:created_at],
MergeRequest::Metrics.arel_table[:merged_at])
end
def staging
@fetcher.calculate_metric(:staging,
MergeRequest::Metrics.arel_table[:merged_at],
MergeRequest::Metrics.arel_table[:first_deployed_to_production_at])
end
def production
@fetcher.calculate_metric(:production,
Issue.arel_table[:created_at],
MergeRequest::Metrics.arel_table[:first_deployed_to_production_at])
def classify_stage(method_sym)
"Gitlab::CycleAnalytics::#{method_sym.to_s.capitalize}Stage".constantize
end
end
......@@ -5,10 +5,10 @@ module Gitlab
attr_reader :stage, :start_time_attrs, :end_time_attrs, :projections, :query
def initialize(project:, options:)
@query = EventsQuery.new(project: project, options: options)
@project = project
@options = options
def initialize(fetcher:, stage:)
@query = EventsQuery.new(fetcher: fetcher)
@project = fetcher.project
@stage = stage
end
def fetch
......
module Gitlab
module CycleAnalytics
class BaseStage
def initialize(project:, options:, stage: stage)
@project = project
@options = options
@fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project,
from: options[:from],
branch: options[:branch])
@stage = stage
end
def events
event_class.new(fetcher: @fetcher, stage: @stage).fetch
end
private
def event_class
"Gitlab::CycleAnalytics::#{@stage.to_s.capitalize}Event".constantize
end
end
end
end
......@@ -4,7 +4,6 @@ module Gitlab
include MergeRequestAllowed
def initialize(*args)
@stage = :code
@start_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at]
@end_time_attrs = mr_table[:created_at]
@projections = [mr_table[:title],
......
module Gitlab
module CycleAnalytics
class CodeStage < BaseStage
def median
@fetcher.calculate_metric(:code,
Issue::Metrics.arel_table[:first_mentioned_in_commit_at],
MergeRequest.arel_table[:created_at])
end
end
end
end
module Gitlab
module CycleAnalytics
class EventsQuery
attr_reader :project
def initialize(project:, options: {})
@project = project
@from = options[:from]
@branch = options[:branch]
@fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project, from: @from, branch: @branch)
def initialize(fetcher:)
@fetcher = fetcher
end
def execute(stage_class)
......
......@@ -4,7 +4,6 @@ module Gitlab
include IssueAllowed
def initialize(*args)
@stage = :issue
@start_time_attrs = issue_table[:created_at]
@end_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]]
......
module Gitlab
module CycleAnalytics
class IssueStage < BaseStage
def median
@fetcher.calculate_metric(:issue,
Issue.arel_table[:created_at],
[Issue::Metrics.arel_table[:first_associated_with_milestone_at],
Issue::Metrics.arel_table[:first_added_to_board_at]])
end
end
end
end
......@@ -5,10 +5,11 @@ module Gitlab
include Gitlab::Database::DateTime
include MetricsTables
attr_reader :project
DEPLOYMENT_METRIC_STAGES = %i[production staging]
def initialize(project:, from:, branch:)
@project = project
@project = project
@from = from
@branch = branch
......
......@@ -2,7 +2,6 @@ module Gitlab
module CycleAnalytics
class PlanEvent < BaseEvent
def initialize(*args)
@stage = :plan
@start_time_attrs = issue_metrics_table[:first_associated_with_milestone_at]
@end_time_attrs = [issue_metrics_table[:first_added_to_board_at],
issue_metrics_table[:first_mentioned_in_commit_at]]
......
module Gitlab
module CycleAnalytics
class PlanStage < BaseStage
def median
@fetcher.calculate_metric(:plan,
[Issue::Metrics.arel_table[:first_associated_with_milestone_at],
Issue::Metrics.arel_table[:first_added_to_board_at]],
Issue::Metrics.arel_table[:first_mentioned_in_commit_at])
end
end
end
end
......@@ -4,7 +4,6 @@ module Gitlab
include IssueAllowed
def initialize(*args)
@stage = :production
@start_time_attrs = issue_table[:created_at]
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
@projections = [issue_table[:title],
......
module Gitlab
module CycleAnalytics
class ProductionStage < BaseStage
def median
@fetcher.calculate_metric(:production,
Issue.arel_table[:created_at],
MergeRequest::Metrics.arel_table[:first_deployed_to_production_at])
end
end
end
end
......@@ -4,7 +4,6 @@ module Gitlab
include MergeRequestAllowed
def initialize(*args)
@stage = :review
@start_time_attrs = mr_table[:created_at]
@end_time_attrs = mr_metrics_table[:merged_at]
@projections = [mr_table[:title],
......
module Gitlab
module CycleAnalytics
class ReviewStage < BaseStage
def median
@fetcher.calculate_metric(:review,
MergeRequest.arel_table[:created_at],
MergeRequest::Metrics.arel_table[:merged_at])
end
end
end
end
......@@ -2,7 +2,6 @@ module Gitlab
module CycleAnalytics
class StagingEvent < BaseEvent
def initialize(*args)
@stage = :staging
@start_time_attrs = mr_metrics_table[:merged_at]
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
@projections = [build_table[:id]]
......
module Gitlab
module CycleAnalytics
class StagingStage < BaseStage
def median
@fetcher.calculate_metric(:staging,
MergeRequest::Metrics.arel_table[:merged_at],
MergeRequest::Metrics.arel_table[:first_deployed_to_production_at])
end
end
end
end
......@@ -4,7 +4,6 @@ module Gitlab
def initialize(*args)
super(*args)
@stage = :test
@start_time_attrs = mr_metrics_table[:latest_build_started_at]
@end_time_attrs = mr_metrics_table[:latest_build_finished_at]
end
......
module Gitlab
module CycleAnalytics
class TestStage < BaseStage
def median
@fetcher.calculate_metric(:test,
MergeRequest::Metrics.arel_table[:latest_build_started_at],
MergeRequest::Metrics.arel_table[:latest_build_finished_at])
end
end
end
end
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