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]
|
|
|
|
# @param opts - dashboard_path [String] Path at which the
|
|
|
|
# dashboard can be found. Nil values will
|
|
|
|
# default to the system dashboard.
|
|
|
|
# @param opts - embedded [Boolean] Determines whether the
|
|
|
|
# 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-07-31 22:56:46 +05:30
|
|
|
# @return [Hash]
|
2019-09-30 21:07:59 +05:30
|
|
|
def find(project, user, environment, dashboard_path: nil, embedded: false)
|
|
|
|
service_for_path(dashboard_path, embedded: embedded)
|
2019-07-31 22:56:46 +05:30
|
|
|
.new(project, user, environment: environment, dashboard_path: dashboard_path)
|
|
|
|
.get_dashboard
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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!
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
system_service.all_dashboard_paths(project)
|
|
|
|
.+ project_service.all_dashboard_paths(project)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def service_for_path(dashboard_path, embedded:)
|
|
|
|
return dynamic_service if embedded
|
|
|
|
return system_service if system_dashboard?(dashboard_path)
|
|
|
|
|
|
|
|
project_service
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def system_service
|
|
|
|
Gitlab::Metrics::Dashboard::SystemDashboardService
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_service
|
|
|
|
Gitlab::Metrics::Dashboard::ProjectDashboardService
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def dynamic_service
|
|
|
|
Gitlab::Metrics::Dashboard::DynamicDashboardService
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
def system_dashboard?(filepath)
|
|
|
|
!filepath || system_service.system_dashboard?(filepath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|