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

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

111 lines
4.2 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
# Returns DB-supplmented dashboard info for determining
# the layout of UI. Intended entry-point for the Metrics::Dashboard
# module.
module Gitlab
module Metrics
module Dashboard
class Finder
2021-09-30 23:02:18 +05:30
PREDEFINED_DASHBOARD_LIST = [
::Metrics::Dashboard::PodDashboardService,
::Metrics::Dashboard::SystemDashboardService
2020-07-28 23:09:34 +05:30
].freeze
2019-07-31 22:56:46 +05:30
class << self
# Returns a formatted dashboard packed with DB info.
2019-09-30 21:07:59 +05:30
# @param project [Project]
# @param user [User]
# @param environment [Environment]
2019-12-26 22:10:19 +05:30
# @param options [Hash<Symbol,Any>]
2019-10-12 21:52:04 +05:30
# @param options - embedded [Boolean] Determines whether the
2019-09-30 21:07:59 +05:30
# dashboard is to be rendered as part of an
# issue or location other than the primary
# metrics dashboard UI. Returns only the
# Memory/CPU charts of the system dash.
2019-10-12 21:52:04 +05:30
# @param options - dashboard_path [String] Path at which the
# dashboard can be found. Nil values will
# default to the system dashboard.
2019-12-21 20:55:43 +05:30
# @param options - group [String, Group] Title of the group
2019-10-12 21:52:04 +05:30
# to which a panel might belong. Used by
2019-12-21 20:55:43 +05:30
# embedded dashboards. If cluster dashboard,
# refers to the Group corresponding to the cluster.
2019-10-12 21:52:04 +05:30
# @param options - title [String] Title of the panel.
# Used by embedded dashboards.
# @param options - y_label [String] Y-Axis label of
# a panel. Used by embedded dashboards.
2020-04-08 14:13:33 +05:30
# @param options - cluster [Cluster]. Used by
# embedded and un-embedded dashboards.
2019-12-21 20:55:43 +05:30
# @param options - cluster_type [Symbol] The level of
2020-04-08 14:13:33 +05:30
# cluster, one of [:admin, :project, :group]. Used by
# embedded and un-embedded dashboards.
2019-12-26 22:10:19 +05:30
# @param options - grafana_url [String] URL pointing
# to a grafana dashboard panel
2020-03-13 15:44:24 +05:30
# @param options - prometheus_alert_id [Integer] ID of
# a PrometheusAlert. For dashboard embeds.
2019-07-31 22:56:46 +05:30
# @return [Hash]
2019-12-04 20:38:33 +05:30
def find(project, user, options = {})
2019-10-12 21:52:04 +05:30
service_for(options)
2019-12-04 20:38:33 +05:30
.new(project, user, options)
2019-07-31 22:56:46 +05:30
.get_dashboard
end
2019-10-12 21:52:04 +05:30
# Returns a dashboard without any supplemental info.
# Returns only full, yml-defined dashboards.
# @return [Hash]
def find_raw(project, dashboard_path: nil)
service_for(dashboard_path: dashboard_path)
.new(project, nil, dashboard_path: dashboard_path)
.raw_dashboard
end
2019-07-31 22:56:46 +05:30
# Summary of all known dashboards.
2019-09-30 21:07:59 +05:30
# @return [Array<Hash>] ex) [{ path: String,
# display_name: String,
# default: Boolean }]
2019-07-31 22:56:46 +05:30
def find_all_paths(project)
2020-10-24 23:57:45 +05:30
dashboards = user_facing_dashboard_services(project).flat_map do |service|
2020-07-28 23:09:34 +05:30
service.all_dashboard_paths(project)
end
2020-10-24 23:57:45 +05:30
Gitlab::Utils.stable_sort_by(dashboards) { |dashboard| dashboard[:display_name].downcase }
2019-07-31 22:56:46 +05:30
end
private
2020-07-28 23:09:34 +05:30
def user_facing_dashboard_services(project)
predefined_dashboard_services_for(project) + [project_service]
end
def predefined_dashboard_services_for(project)
# Only list the self monitoring dashboard on the self monitoring project,
# since it is the only dashboard (at time of writing) that shows data
# about GitLab itself.
if project.self_monitoring?
return [self_monitoring_service]
end
2021-09-30 23:02:18 +05:30
PREDEFINED_DASHBOARD_LIST
2020-07-28 23:09:34 +05:30
end
2019-07-31 22:56:46 +05:30
def system_service
2019-10-12 21:52:04 +05:30
::Metrics::Dashboard::SystemDashboardService
2019-07-31 22:56:46 +05:30
end
def project_service
2020-04-22 19:07:51 +05:30
::Metrics::Dashboard::CustomDashboardService
2019-09-30 21:07:59 +05:30
end
2020-03-13 15:44:24 +05:30
def self_monitoring_service
::Metrics::Dashboard::SelfMonitoringDashboardService
end
2019-10-12 21:52:04 +05:30
def service_for(options)
Gitlab::Metrics::Dashboard::ServiceSelector.call(options)
2019-07-31 22:56:46 +05:30
end
end
end
end
end
end