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

predefined_dashboard_service.rb « dashboard « metrics « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c21083475f0ebd2dde472b23cd83f65fde5f3b00 (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
59
# frozen_string_literal: true

module Metrics
  module Dashboard
    class PredefinedDashboardService < ::Metrics::Dashboard::BaseService
      # These constants should be overridden in the inheriting class. For Ex:
      # DASHBOARD_PATH = 'config/prometheus/common_metrics.yml'
      # DASHBOARD_NAME = 'Default'
      DASHBOARD_PATH = nil
      DASHBOARD_NAME = nil

      SEQUENCE = [
        STAGES::MetricEndpointInserter,
        STAGES::VariableEndpointInserter,
        STAGES::PanelIdsInserter,
        STAGES::Sorter
      ].freeze

      class << self
        def valid_params?(params)
          matching_dashboard?(params[:dashboard_path])
        end

        def matching_dashboard?(filepath)
          filepath == self::DASHBOARD_PATH
        end

        def out_of_the_box_dashboard?
          true
        end
      end

      private

      def dashboard_version
        raise NotImplementedError
      end

      def cache_key
        "metrics_dashboard_#{dashboard_path}_#{dashboard_version}"
      end

      def dashboard_path
        self.class::DASHBOARD_PATH
      end

      # Returns the base metrics shipped with every GitLab service.
      def get_raw_dashboard
        yml = File.read(Rails.root.join(dashboard_path))

        load_yaml(yml)
      end

      def sequence
        self.class::SEQUENCE
      end
    end
  end
end