Move dashboard param to initialize method
This commit is contained in:
parent
8926b37d5b
commit
0e093940e1
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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') }
|
||||
|
|
Loading…
Reference in New Issue