diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-11 15:09:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-11 15:09:43 +0300 |
commit | 54f170b69972d46a5bab2a0231510a41e610da31 (patch) | |
tree | 6943aba13e4bdf28045136d0c1a1f26c4d3fb94f /app/models/cycle_analytics | |
parent | 8c59925bbbc05315565cd9eb54c897be69072d65 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/cycle_analytics')
-rw-r--r-- | app/models/cycle_analytics/level_base.rb | 55 | ||||
-rw-r--r-- | app/models/cycle_analytics/project_level.rb | 9 |
2 files changed, 62 insertions, 2 deletions
diff --git a/app/models/cycle_analytics/level_base.rb b/app/models/cycle_analytics/level_base.rb index 967de9a22b4..bc7aa57a0a1 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 @@ -21,7 +64,15 @@ module CycleAnalytics end def [](stage_name) - Gitlab::CycleAnalytics::Stage[stage_name].new(options: options) + if Feature.enabled?(:new_project_level_vsa_backend, resource_parent) + StageAdapter.new(build_stage(stage_name), options) + else + Gitlab::CycleAnalytics::Stage[stage_name].new(options: options) + end + end + + 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 |