Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base_stage.rb « stages « metrics_dashboard « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df49126a07be40a469570b74c28b97c285ad9b1f (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

module Gitlab
  module MetricsDashboard
    module Stages
      class BaseStage
        DashboardLayoutError = Class.new(StandardError)

        DEFAULT_PANEL_TYPE = 'area-chart'

        attr_reader :project, :environment

        def initialize(project, environment)
          @project = project
          @environment = environment
        end

        # Entry-point to the stage
        # @param dashboard [Hash]
        # @param project [Project]
        # @param environment [Environment]
        def transform!(_dashboard)
          raise NotImplementedError
        end

        protected

        def missing_panel_groups!
          raise DashboardLayoutError.new('Top-level key :panel_groups must be an array')
        end

        def missing_panels!
          raise DashboardLayoutError.new('Each "panel_group" must define an array :panels')
        end

        def missing_metrics!
          raise DashboardLayoutError.new('Each "panel" must define an array :metrics')
        end

        def for_metrics(dashboard)
          missing_panel_groups! unless dashboard[:panel_groups].is_a?(Array)

          dashboard[:panel_groups].each do |panel_group|
            missing_panels! unless panel_group[:panels].is_a?(Array)

            panel_group[:panels].each do |panel|
              missing_metrics! unless panel[:metrics].is_a?(Array)

              panel[:metrics].each do |metric|
                yield metric
              end
            end
          end
        end
      end
    end
  end
end