summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyasonik <syasonik@gitlab.com>2019-04-25 14:13:43 +0800
committersyasonik <syasonik@gitlab.com>2019-04-25 14:13:43 +0800
commit0e093940e1135897b996a5f16239eca62cc6089e (patch)
tree9a2a30ba88d9b5ed1ca8020897890c7d516c17d4
parent8926b37d5b0c48b9ef89e4769e622563a9b11e9f (diff)
downloadgitlab-ce-0e093940e1135897b996a5f16239eca62cc6089e.tar.gz
Move dashboard param to initialize method60383-setup-dashboard-endpoint
-rw-r--r--lib/gitlab/metrics/dashboard/processor.rb9
-rw-r--r--lib/gitlab/metrics/dashboard/service.rb2
-rw-r--r--lib/gitlab/metrics/dashboard/stages/base_stage.rb10
-rw-r--r--lib/gitlab/metrics/dashboard/stages/common_metrics_inserter.rb2
-rw-r--r--lib/gitlab/metrics/dashboard/stages/project_metrics_inserter.rb2
-rw-r--r--lib/gitlab/metrics/dashboard/stages/sorter.rb10
-rw-r--r--spec/lib/gitlab/metrics/dashboard/processor_spec.rb4
7 files changed, 19 insertions, 20 deletions
diff --git a/lib/gitlab/metrics/dashboard/processor.rb b/lib/gitlab/metrics/dashboard/processor.rb
index 46fd2f9440d..cc34ac53051 100644
--- a/lib/gitlab/metrics/dashboard/processor.rb
+++ b/lib/gitlab/metrics/dashboard/processor.rb
@@ -14,17 +14,18 @@ module Gitlab
Stages::Sorter
].freeze
- def initialize(project, environment)
+ def initialize(project, environment, dashboard)
@project = project
@environment = environment
+ @dashboard = dashboard
end
# Returns a new dashboard hash with the results of
# running transforms on the dashboard.
- def process(raw_dashboard)
- raw_dashboard.deep_symbolize_keys.tap do |dashboard|
+ def process
+ @dashboard.deep_symbolize_keys.tap do |dashboard|
sequence.each do |stage|
- stage.new(@project, @environment).transform!(dashboard)
+ stage.new(@project, @environment, dashboard).transform!
end
end
end
diff --git a/lib/gitlab/metrics/dashboard/service.rb b/lib/gitlab/metrics/dashboard/service.rb
index b8f144a7222..79d563cce4f 100644
--- a/lib/gitlab/metrics/dashboard/service.rb
+++ b/lib/gitlab/metrics/dashboard/service.rb
@@ -32,7 +32,7 @@ module Gitlab
# Returns a new dashboard Hash, supplemented with DB info
def process_dashboard(dashboard)
- Gitlab::Metrics::Dashboard::Processor.new(project, params[:environment]).process(dashboard)
+ Gitlab::Metrics::Dashboard::Processor.new(project, params[:environment], dashboard).process
end
end
end
diff --git a/lib/gitlab/metrics/dashboard/stages/base_stage.rb b/lib/gitlab/metrics/dashboard/stages/base_stage.rb
index daecb2698ae..dd4aae6c115 100644
--- a/lib/gitlab/metrics/dashboard/stages/base_stage.rb
+++ b/lib/gitlab/metrics/dashboard/stages/base_stage.rb
@@ -9,18 +9,16 @@ module Gitlab
DEFAULT_PANEL_TYPE = 'area-chart'
- attr_reader :project, :environment
+ attr_reader :project, :environment, :dashboard
- def initialize(project, environment)
+ def initialize(project, environment, dashboard)
@project = project
@environment = environment
+ @dashboard = dashboard
end
# Entry-point to the stage
- # @param dashboard [Hash]
- # @param project [Project]
- # @param environment [Environment]
- def transform!(_dashboard)
+ def transform!
raise NotImplementedError
end
diff --git a/lib/gitlab/metrics/dashboard/stages/common_metrics_inserter.rb b/lib/gitlab/metrics/dashboard/stages/common_metrics_inserter.rb
index 20e6b98e20b..3406021bbea 100644
--- a/lib/gitlab/metrics/dashboard/stages/common_metrics_inserter.rb
+++ b/lib/gitlab/metrics/dashboard/stages/common_metrics_inserter.rb
@@ -8,7 +8,7 @@ module Gitlab
# For each metric in the dashboard config, attempts to
# find a corresponding database record. If found,
# includes the record's id in the dashboard config.
- def transform!(dashboard)
+ def transform!
common_metrics = ::PrometheusMetric.common
for_metrics(dashboard) do |metric|
diff --git a/lib/gitlab/metrics/dashboard/stages/project_metrics_inserter.rb b/lib/gitlab/metrics/dashboard/stages/project_metrics_inserter.rb
index 0dc87f1ec16..221610a14d1 100644
--- a/lib/gitlab/metrics/dashboard/stages/project_metrics_inserter.rb
+++ b/lib/gitlab/metrics/dashboard/stages/project_metrics_inserter.rb
@@ -8,7 +8,7 @@ module Gitlab
# Inserts project-specific metrics into the dashboard
# config. If there are no project-specific metrics,
# this will have no effect.
- def transform!(dashboard)
+ def transform!
project.prometheus_metrics.each do |project_metric|
group = find_or_create_panel_group(dashboard[:panel_groups], project_metric)
panel = find_or_create_panel(group[:panels], project_metric)
diff --git a/lib/gitlab/metrics/dashboard/stages/sorter.rb b/lib/gitlab/metrics/dashboard/stages/sorter.rb
index 9c4183fff99..ba5aa78059c 100644
--- a/lib/gitlab/metrics/dashboard/stages/sorter.rb
+++ b/lib/gitlab/metrics/dashboard/stages/sorter.rb
@@ -5,22 +5,22 @@ module Gitlab
module Dashboard
module Stages
class Sorter < BaseStage
- def transform!(dashboard)
+ def transform!
missing_panel_groups! unless dashboard[:panel_groups].is_a? Array
- sort_groups!(dashboard)
- sort_panels!(dashboard)
+ sort_groups!
+ sort_panels!
end
private
# Sorts the groups in the dashboard by the :priority key
- def sort_groups!(dashboard)
+ def sort_groups!
dashboard[:panel_groups] = dashboard[:panel_groups].sort_by { |group| -group[:priority].to_i }
end
# Sorts the panels in the dashboard by the :weight key
- def sort_panels!(dashboard)
+ def sort_panels!
dashboard[:panel_groups].each do |group|
missing_panels! unless group[:panels].is_a? Array
diff --git a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
index e27ba2f1f4e..ee7c93fce8d 100644
--- a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
+++ b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb
@@ -8,8 +8,8 @@ describe Gitlab::Metrics::Dashboard::Processor do
let(:dashboard_yml) { YAML.load_file('spec/fixtures/lib/gitlab/metrics/dashboard/sample_dashboard.yml') }
describe 'process' do
- let(:process_params) { [project, environment] }
- let(:dashboard) { described_class.new(*process_params).process(dashboard_yml) }
+ let(:process_params) { [project, environment, dashboard_yml] }
+ let(:dashboard) { described_class.new(*process_params).process }
context 'when dashboard config corresponds to common metrics' do
let!(:common_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') }