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

102 lines
3.8 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
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.
2019-12-21 20:55:43 +05:30
# @param options - cluster [Cluster]
# @param options - cluster_type [Symbol] The level of
# cluster, one of [:admin, :project, :group]
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)
project.repository.metrics_dashboard_paths
end
# Summary of all known dashboards. Used to populate repo cache.
# Prefer #find_all_paths.
def find_all_paths_from_source(project)
2019-09-04 21:01:54 +05:30
Gitlab::Metrics::Dashboard::Cache.delete_all!
2020-03-13 15:44:24 +05:30
default_dashboard_path(project)
2019-07-31 22:56:46 +05:30
.+ project_service.all_dashboard_paths(project)
end
private
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
2019-10-12 21:52:04 +05:30
::Metrics::Dashboard::ProjectDashboardService
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
def default_dashboard_path(project)
if project.self_monitoring?
self_monitoring_service.all_dashboard_paths(project)
else
system_service.all_dashboard_paths(project)
end
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