WIP - started refactoring cycle analytics median stuff into stages
This commit is contained in:
parent
e7fdb1aae5
commit
3268e37791
|
|
@ -1,17 +1,17 @@
|
||||||
class CycleAnalytics
|
class CycleAnalytics
|
||||||
STAGES = %i[issue plan code test review staging production].freeze
|
STAGES = %i[issue plan code test review staging production].freeze
|
||||||
|
|
||||||
def initialize(project, current_user, from:)
|
def initialize(project, from:)
|
||||||
@project = project
|
@project = project
|
||||||
@current_user = current_user
|
@options = options
|
||||||
@from = from
|
|
||||||
@fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project, from: from, branch: nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def summary
|
def summary
|
||||||
@summary ||= Summary.new(@project, @current_user, from: @from)
|
@summary ||= Summary.new(@project, from: @options[:from])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def method_missing(method_sym, *arguments, &block)
|
||||||
|
classify_stage(method_sym).new(project: @project, options: @options, stage: method_sym)
|
||||||
def permissions(user:)
|
def permissions(user:)
|
||||||
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
|
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
|
||||||
end
|
end
|
||||||
|
|
@ -23,40 +23,7 @@ class CycleAnalytics
|
||||||
Issue::Metrics.arel_table[:first_added_to_board_at]])
|
Issue::Metrics.arel_table[:first_added_to_board_at]])
|
||||||
end
|
end
|
||||||
|
|
||||||
def plan
|
def classify_stage(method_sym)
|
||||||
@fetcher.calculate_metric(:plan,
|
"Gitlab::CycleAnalytics::#{method_sym.to_s.capitalize}Stage".constantize
|
||||||
[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])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ module Gitlab
|
||||||
|
|
||||||
attr_reader :stage, :start_time_attrs, :end_time_attrs, :projections, :query
|
attr_reader :stage, :start_time_attrs, :end_time_attrs, :projections, :query
|
||||||
|
|
||||||
def initialize(project:, options:)
|
def initialize(fetcher:, stage:)
|
||||||
@query = EventsQuery.new(project: project, options: options)
|
@query = EventsQuery.new(fetcher: fetcher)
|
||||||
@project = project
|
@project = fetcher.project
|
||||||
@options = options
|
@stage = stage
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
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
|
include MergeRequestAllowed
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@stage = :code
|
|
||||||
@start_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at]
|
@start_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at]
|
||||||
@end_time_attrs = mr_table[:created_at]
|
@end_time_attrs = mr_table[:created_at]
|
||||||
@projections = [mr_table[:title],
|
@projections = [mr_table[:title],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
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
|
||||||
|
|
@ -1,13 +1,8 @@
|
||||||
module Gitlab
|
module Gitlab
|
||||||
module CycleAnalytics
|
module CycleAnalytics
|
||||||
class EventsQuery
|
class EventsQuery
|
||||||
attr_reader :project
|
def initialize(fetcher:)
|
||||||
|
@fetcher = fetcher
|
||||||
def initialize(project:, options: {})
|
|
||||||
@project = project
|
|
||||||
@from = options[:from]
|
|
||||||
@branch = options[:branch]
|
|
||||||
@fetcher = Gitlab::CycleAnalytics::MetricsFetcher.new(project: project, from: @from, branch: @branch)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(stage_class)
|
def execute(stage_class)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ module Gitlab
|
||||||
include IssueAllowed
|
include IssueAllowed
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@stage = :issue
|
|
||||||
@start_time_attrs = issue_table[:created_at]
|
@start_time_attrs = issue_table[:created_at]
|
||||||
@end_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at],
|
@end_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at],
|
||||||
issue_metrics_table[:first_added_to_board_at]]
|
issue_metrics_table[:first_added_to_board_at]]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
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 Gitlab::Database::DateTime
|
||||||
include MetricsTables
|
include MetricsTables
|
||||||
|
|
||||||
|
attr_reader :project
|
||||||
|
|
||||||
DEPLOYMENT_METRIC_STAGES = %i[production staging]
|
DEPLOYMENT_METRIC_STAGES = %i[production staging]
|
||||||
|
|
||||||
def initialize(project:, from:, branch:)
|
def initialize(project:, from:, branch:)
|
||||||
@project = project
|
|
||||||
@project = project
|
@project = project
|
||||||
@from = from
|
@from = from
|
||||||
@branch = branch
|
@branch = branch
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ module Gitlab
|
||||||
module CycleAnalytics
|
module CycleAnalytics
|
||||||
class PlanEvent < BaseEvent
|
class PlanEvent < BaseEvent
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@stage = :plan
|
|
||||||
@start_time_attrs = issue_metrics_table[:first_associated_with_milestone_at]
|
@start_time_attrs = issue_metrics_table[:first_associated_with_milestone_at]
|
||||||
@end_time_attrs = [issue_metrics_table[:first_added_to_board_at],
|
@end_time_attrs = [issue_metrics_table[:first_added_to_board_at],
|
||||||
issue_metrics_table[:first_mentioned_in_commit_at]]
|
issue_metrics_table[:first_mentioned_in_commit_at]]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
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
|
include IssueAllowed
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@stage = :production
|
|
||||||
@start_time_attrs = issue_table[:created_at]
|
@start_time_attrs = issue_table[:created_at]
|
||||||
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
|
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
|
||||||
@projections = [issue_table[:title],
|
@projections = [issue_table[:title],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
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
|
include MergeRequestAllowed
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@stage = :review
|
|
||||||
@start_time_attrs = mr_table[:created_at]
|
@start_time_attrs = mr_table[:created_at]
|
||||||
@end_time_attrs = mr_metrics_table[:merged_at]
|
@end_time_attrs = mr_metrics_table[:merged_at]
|
||||||
@projections = [mr_table[:title],
|
@projections = [mr_table[:title],
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
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
|
module CycleAnalytics
|
||||||
class StagingEvent < BaseEvent
|
class StagingEvent < BaseEvent
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@stage = :staging
|
|
||||||
@start_time_attrs = mr_metrics_table[:merged_at]
|
@start_time_attrs = mr_metrics_table[:merged_at]
|
||||||
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
|
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
|
||||||
@projections = [build_table[:id]]
|
@projections = [build_table[:id]]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
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)
|
def initialize(*args)
|
||||||
super(*args)
|
super(*args)
|
||||||
|
|
||||||
@stage = :test
|
|
||||||
@start_time_attrs = mr_metrics_table[:latest_build_started_at]
|
@start_time_attrs = mr_metrics_table[:latest_build_started_at]
|
||||||
@end_time_attrs = mr_metrics_table[:latest_build_finished_at]
|
@end_time_attrs = mr_metrics_table[:latest_build_finished_at]
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
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
|
||||||
Loading…
Reference in New Issue