summaryrefslogtreecommitdiff
path: root/lib/gitlab/metrics/dashboard/processor.rb
blob: 46fd2f9440d9999e11b4e886dd4a244b79d97890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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
        SEQUENCE = [
          Stages::CommonMetricsInserter,
          Stages::ProjectMetricsInserter,
          Stages::Sorter
        ].freeze

        def initialize(project, environment)
          @project = project
          @environment = environment
        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|
            sequence.each do |stage|
              stage.new(@project, @environment).transform!(dashboard)
            end
          end
        end

        private

        def sequence
          SEQUENCE
        end
      end
    end
  end
end