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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.8 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
2020-04-08 14:13:33 +05:30
# and dashboards. Embed hashes are identical to dashboard hashes except
# that they contain a subset of panels.
2019-10-12 21:52:04 +05:30
module Gitlab
module Metrics
module Dashboard
class ServiceSelector
class << self
include Gitlab::Utils::StrongMemoize
2020-03-13 15:44:24 +05:30
SERVICES = [
2020-07-28 23:09:34 +05:30
::Metrics::Dashboard::ClusterMetricsEmbedService,
::Metrics::Dashboard::ClusterDashboardService,
2020-04-22 19:07:51 +05:30
::Metrics::Dashboard::GitlabAlertEmbedService,
2020-03-13 15:44:24 +05:30
::Metrics::Dashboard::CustomMetricEmbedService,
::Metrics::Dashboard::GrafanaMetricEmbedService,
2020-04-22 19:07:51 +05:30
::Metrics::Dashboard::TransientEmbedService,
2020-03-13 15:44:24 +05:30
::Metrics::Dashboard::DynamicEmbedService,
::Metrics::Dashboard::DefaultEmbedService,
::Metrics::Dashboard::SystemDashboardService,
::Metrics::Dashboard::PodDashboardService,
::Metrics::Dashboard::SelfMonitoringDashboardService,
2020-04-22 19:07:51 +05:30
::Metrics::Dashboard::CustomDashboardService
2020-03-13 15:44:24 +05:30
].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.
2021-11-18 22:05:49 +05:30
# @return [Metrics::Dashboard::BaseService]
2019-10-12 21:52:04 +05:30
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