debian-mirror-gitlab/lib/gitlab/metrics/dashboard/service_selector.rb

53 lines
1.6 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
# Responsible for determining which dashboard service should
# be used to fetch or generate a dashboard hash.
# The services can be considered in two categories - embeds
# and dashboards. Embeds are all portions of dashboards.
module Gitlab
module Metrics
module Dashboard
class ServiceSelector
class << self
include Gitlab::Utils::StrongMemoize
2020-03-13 15:44:24 +05:30
SERVICES = [
::Metrics::Dashboard::CustomMetricEmbedService,
::Metrics::Dashboard::GrafanaMetricEmbedService,
::Metrics::Dashboard::DynamicEmbedService,
::Metrics::Dashboard::DefaultEmbedService,
::Metrics::Dashboard::SystemDashboardService,
::Metrics::Dashboard::PodDashboardService,
::Metrics::Dashboard::SelfMonitoringDashboardService,
::Metrics::Dashboard::ProjectDashboardService
].freeze
2019-10-12 21:52:04 +05:30
# Returns a class which inherits from the BaseService
2020-03-13 15:44:24 +05:30
# class that can be used to obtain a dashboard for
# the provided params.
2019-10-12 21:52:04 +05:30
# @return [Gitlab::Metrics::Dashboard::Services::BaseService]
def call(params)
2020-03-13 15:44:24 +05:30
service = services.find do |service_class|
service_class.valid_params?(params)
end
2019-10-12 21:52:04 +05:30
2020-03-13 15:44:24 +05:30
service || default_service
2019-10-12 21:52:04 +05:30
end
2020-03-13 15:44:24 +05:30
private
2019-10-12 21:52:04 +05:30
2020-03-13 15:44:24 +05:30
def services
SERVICES
2019-12-26 22:10:19 +05:30
end
2020-03-13 15:44:24 +05:30
def default_service
::Metrics::Dashboard::SystemDashboardService
2019-10-12 21:52:04 +05:30
end
end
end
end
end
end
2019-12-04 20:38:33 +05:30
Gitlab::Metrics::Dashboard::ServiceSelector.prepend_if_ee('EE::Gitlab::Metrics::Dashboard::ServiceSelector')