2019-04-24 23:03:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Metrics
|
|
|
|
module Dashboard
|
|
|
|
# Responsible for processesing a dashboard hash, inserting
|
|
|
|
# relevant DB records & sorting for proper rendering in
|
|
|
|
# the UI. These includes shared metric info, custom metrics
|
|
|
|
# info, and alerts (only in EE).
|
|
|
|
class Processor
|
2019-05-01 06:16:03 -04:00
|
|
|
SYSTEM_SEQUENCE = [
|
2019-04-24 23:03:50 -04:00
|
|
|
Stages::CommonMetricsInserter,
|
|
|
|
Stages::ProjectMetricsInserter,
|
2019-06-05 09:43:50 -04:00
|
|
|
Stages::EndpointInserter,
|
2019-04-24 23:03:50 -04:00
|
|
|
Stages::Sorter
|
|
|
|
].freeze
|
|
|
|
|
2019-05-01 06:16:03 -04:00
|
|
|
PROJECT_SEQUENCE = [
|
|
|
|
Stages::CommonMetricsInserter,
|
2019-06-05 09:43:50 -04:00
|
|
|
Stages::EndpointInserter,
|
2019-05-01 06:16:03 -04:00
|
|
|
Stages::Sorter
|
|
|
|
].freeze
|
|
|
|
|
2019-04-25 02:13:43 -04:00
|
|
|
def initialize(project, environment, dashboard)
|
2019-04-24 23:03:50 -04:00
|
|
|
@project = project
|
|
|
|
@environment = environment
|
2019-04-25 02:13:43 -04:00
|
|
|
@dashboard = dashboard
|
2019-04-24 23:03:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Returns a new dashboard hash with the results of
|
|
|
|
# running transforms on the dashboard.
|
2019-05-01 06:16:03 -04:00
|
|
|
def process(insert_project_metrics:)
|
2019-04-25 02:13:43 -04:00
|
|
|
@dashboard.deep_symbolize_keys.tap do |dashboard|
|
2019-05-01 06:16:03 -04:00
|
|
|
sequence(insert_project_metrics).each do |stage|
|
2019-04-25 02:13:43 -04:00
|
|
|
stage.new(@project, @environment, dashboard).transform!
|
2019-04-25 02:00:51 -04:00
|
|
|
end
|
|
|
|
end
|
2019-04-24 23:03:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-05-01 06:16:03 -04:00
|
|
|
def sequence(insert_project_metrics)
|
|
|
|
insert_project_metrics ? SYSTEM_SEQUENCE : PROJECT_SEQUENCE
|
2019-04-24 23:03:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Gitlab::Metrics::Dashboard::Processor.prepend_if_ee('EE::Gitlab::Metrics::Dashboard::Processor')
|