summaryrefslogtreecommitdiff
path: root/app/models/cycle_analytics
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 11:59:07 +0000
commit8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch)
tree544930fb309b30317ae9797a9683768705d664c4 /app/models/cycle_analytics
parent4b1de649d0168371549608993deac953eb692019 (diff)
downloadgitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/models/cycle_analytics')
-rw-r--r--app/models/cycle_analytics/level_base.rb57
-rw-r--r--app/models/cycle_analytics/project_level.rb9
2 files changed, 61 insertions, 5 deletions
diff --git a/app/models/cycle_analytics/level_base.rb b/app/models/cycle_analytics/level_base.rb
index 967de9a22b4..901636a7263 100644
--- a/app/models/cycle_analytics/level_base.rb
+++ b/app/models/cycle_analytics/level_base.rb
@@ -4,9 +4,52 @@ module CycleAnalytics
module LevelBase
STAGES = %i[issue plan code test review staging].freeze
+ # This is a temporary adapter class which makes the new value stream (cycle analytics)
+ # backend compatible with the old implementation.
+ class StageAdapter
+ def initialize(stage, options)
+ @stage = stage
+ @options = options
+ end
+
+ # rubocop: disable CodeReuse/Presenter
+ def as_json(serializer: AnalyticsStageSerializer)
+ presenter = Analytics::CycleAnalytics::StagePresenter.new(stage)
+
+ serializer.new.represent(OpenStruct.new(
+ title: presenter.title,
+ description: presenter.description,
+ legend: presenter.legend,
+ name: stage.name,
+ project_median: median,
+ group_median: median
+ ))
+ end
+ # rubocop: enable CodeReuse/Presenter
+
+ def events
+ data_collector.records_fetcher.serialized_records
+ end
+
+ def median
+ data_collector.median.seconds
+ end
+
+ alias_method :project_median, :median
+ alias_method :group_median, :median
+
+ private
+
+ attr_reader :stage, :options
+
+ def data_collector
+ @data_collector ||= Gitlab::Analytics::CycleAnalytics::DataCollector.new(stage: stage, params: options)
+ end
+ end
+
def all_medians_by_stage
STAGES.each_with_object({}) do |stage_name, medians_per_stage|
- medians_per_stage[stage_name] = self[stage_name].project_median
+ medians_per_stage[stage_name] = self[stage_name].median
end
end
@@ -16,12 +59,16 @@ module CycleAnalytics
end
end
- def no_stats?
- stats.all? { |hash| hash[:value].nil? }
+ def [](stage_name)
+ if Feature.enabled?(:new_project_level_vsa_backend, resource_parent, default_enabled: true)
+ StageAdapter.new(build_stage(stage_name), options)
+ else
+ Gitlab::CycleAnalytics::Stage[stage_name].new(options: options)
+ end
end
- def [](stage_name)
- Gitlab::CycleAnalytics::Stage[stage_name].new(options: options)
+ def stage_params_by_name(name)
+ Gitlab::Analytics::CycleAnalytics::DefaultStages.find_by_name!(name)
end
end
end
diff --git a/app/models/cycle_analytics/project_level.rb b/app/models/cycle_analytics/project_level.rb
index 591435baf34..26cdcc0db4b 100644
--- a/app/models/cycle_analytics/project_level.rb
+++ b/app/models/cycle_analytics/project_level.rb
@@ -20,5 +20,14 @@ module CycleAnalytics
def permissions(user:)
Gitlab::CycleAnalytics::Permissions.get(user: user, project: project)
end
+
+ def build_stage(stage_name)
+ stage_params = stage_params_by_name(stage_name).merge(project: project)
+ Analytics::CycleAnalytics::ProjectStage.new(stage_params)
+ end
+
+ def resource_parent
+ project
+ end
end
end