debian-mirror-gitlab/app/services/metrics/dashboard/predefined_dashboard_service.rb

64 lines
1.5 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# 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 = [
2020-07-28 23:09:34 +05:30
STAGES::MetricEndpointInserter,
STAGES::VariableEndpointInserter,
2020-10-24 23:57:45 +05:30
STAGES::PanelIdsInserter
2020-01-01 13:55:28 +05:30
].freeze
class << self
2020-03-13 15:44:24 +05:30
def valid_params?(params)
matching_dashboard?(params[:dashboard_path])
end
2020-01-01 13:55:28 +05:30
def matching_dashboard?(filepath)
filepath == self::DASHBOARD_PATH
end
2020-07-28 23:09:34 +05:30
def out_of_the_box_dashboard?
true
end
2020-01-01 13:55:28 +05:30
end
2020-10-24 23:57:45 +05:30
# Returns an un-processed dashboard from the cache.
def raw_dashboard
Gitlab::Metrics::Dashboard::Cache.fetch(cache_key) { get_raw_dashboard }
end
2020-01-01 13:55:28 +05:30
private
2020-07-28 23:09:34 +05:30
def dashboard_version
raise NotImplementedError
end
2020-01-01 13:55:28 +05:30
def cache_key
2020-07-28 23:09:34 +05:30
"metrics_dashboard_#{dashboard_path}_#{dashboard_version}"
2020-01-01 13:55:28 +05:30
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))
2020-07-28 23:09:34 +05:30
load_yaml(yml)
2020-01-01 13:55:28 +05:30
end
def sequence
self.class::SEQUENCE
end
end
end
end