diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /app/models/cycle_analytics | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'app/models/cycle_analytics')
-rw-r--r-- | app/models/cycle_analytics/level_base.rb | 74 | ||||
-rw-r--r-- | app/models/cycle_analytics/project_level.rb | 21 | ||||
-rw-r--r-- | app/models/cycle_analytics/project_level_stage_adapter.rb | 44 |
3 files changed, 62 insertions, 77 deletions
diff --git a/app/models/cycle_analytics/level_base.rb b/app/models/cycle_analytics/level_base.rb deleted file mode 100644 index 901636a7263..00000000000 --- a/app/models/cycle_analytics/level_base.rb +++ /dev/null @@ -1,74 +0,0 @@ -# frozen_string_literal: true - -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].median - end - end - - def stats - @stats ||= STAGES.map do |stage_name| - self[stage_name].as_json - end - end - - 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_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 26cdcc0db4b..5bd07b3f6c3 100644 --- a/app/models/cycle_analytics/project_level.rb +++ b/app/models/cycle_analytics/project_level.rb @@ -2,7 +2,6 @@ module CycleAnalytics class ProjectLevel - include LevelBase attr_reader :project, :options def initialize(project, options:) @@ -21,13 +20,29 @@ module CycleAnalytics Gitlab::CycleAnalytics::Permissions.get(user: user, project: project) end + def stats + @stats ||= default_stage_names.map do |stage_name| + self[stage_name].as_json + end + end + + def [](stage_name) + CycleAnalytics::ProjectLevelStageAdapter.new(build_stage(stage_name), options) + end + + private + 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 + def stage_params_by_name(name) + Gitlab::Analytics::CycleAnalytics::DefaultStages.find_by_name!(name) + end + + def default_stage_names + Gitlab::Analytics::CycleAnalytics::DefaultStages.symbolized_stage_names end end end diff --git a/app/models/cycle_analytics/project_level_stage_adapter.rb b/app/models/cycle_analytics/project_level_stage_adapter.rb new file mode 100644 index 00000000000..dd4afa9b809 --- /dev/null +++ b/app/models/cycle_analytics/project_level_stage_adapter.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +# This adapter class makes the new value stream (cycle analytics) backend +# compatible with the old value stream controller actions. +module CycleAnalytics + class ProjectLevelStageAdapter + 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 + )) + 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 + + private + + attr_reader :stage, :options + + def data_collector + @data_collector ||= Gitlab::Analytics::CycleAnalytics::DataCollector.new(stage: stage, params: options) + end + end +end |