2019-05-01 06:16:03 -04:00
|
|
|
# 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-06-20 10:06:18 -04:00
|
|
|
# @param project [Project]
|
|
|
|
# @param user [User]
|
|
|
|
# @param environment [Environment]
|
2019-08-07 12:17:35 -04:00
|
|
|
# @param options - embedded [Boolean] Determines whether the
|
2019-06-20 10:06:18 -04:00
|
|
|
# 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-08-07 12:17:35 -04:00
|
|
|
# @param options - dashboard_path [String] Path at which the
|
|
|
|
# dashboard can be found. Nil values will
|
|
|
|
# default to the system dashboard.
|
|
|
|
# @param options - group [String] Title of the group
|
|
|
|
# to which a panel might belong. Used by
|
|
|
|
# embedded dashboards.
|
|
|
|
# @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-05-01 06:16:03 -04:00
|
|
|
# @return [Hash]
|
2019-08-07 12:17:35 -04:00
|
|
|
def find(project, user, environment, options = {})
|
|
|
|
service_for(options)
|
|
|
|
.new(project, user, options.merge(environment: environment))
|
2019-05-01 06:16:03 -04:00
|
|
|
.get_dashboard
|
|
|
|
end
|
|
|
|
|
2019-08-07 12:17:35 -04:00
|
|
|
# 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-05-01 06:16:03 -04:00
|
|
|
# Summary of all known dashboards.
|
2019-06-20 10:06:18 -04:00
|
|
|
# @return [Array<Hash>] ex) [{ path: String,
|
|
|
|
# display_name: String,
|
|
|
|
# default: Boolean }]
|
2019-05-01 06:16:03 -04:00
|
|
|
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-06-13 12:45:36 -04:00
|
|
|
Gitlab::Metrics::Dashboard::Cache.delete_all!
|
|
|
|
|
2019-05-01 06:16:03 -04:00
|
|
|
system_service.all_dashboard_paths(project)
|
|
|
|
.+ project_service.all_dashboard_paths(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def system_service
|
2019-07-29 19:03:59 -04:00
|
|
|
::Metrics::Dashboard::SystemDashboardService
|
2019-05-01 06:16:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_service
|
2019-07-29 19:03:59 -04:00
|
|
|
::Metrics::Dashboard::ProjectDashboardService
|
2019-05-01 06:16:03 -04:00
|
|
|
end
|
|
|
|
|
2019-08-07 12:17:35 -04:00
|
|
|
def service_for(options)
|
|
|
|
Gitlab::Metrics::Dashboard::ServiceSelector.call(options)
|
2019-05-01 06:16:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|