2019-07-29 19:03:59 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Searches a projects repository for a metrics dashboard and formats the output.
|
|
|
|
# Expects any custom dashboards will be located in `.gitlab/dashboards`
|
|
|
|
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
|
|
|
|
module Metrics
|
|
|
|
module Dashboard
|
2020-03-23 11:09:36 -04:00
|
|
|
class CustomDashboardService < ::Metrics::Dashboard::BaseService
|
2019-07-29 19:03:59 -04:00
|
|
|
class << self
|
2020-01-30 04:08:55 -05:00
|
|
|
def valid_params?(params)
|
|
|
|
params[:dashboard_path].present?
|
|
|
|
end
|
|
|
|
|
2019-07-29 19:03:59 -04:00
|
|
|
def all_dashboard_paths(project)
|
2020-07-30 20:09:37 -04:00
|
|
|
project.repository.user_defined_metrics_dashboard_paths
|
2019-07-29 19:03:59 -04:00
|
|
|
.map do |filepath|
|
|
|
|
{
|
|
|
|
path: filepath,
|
|
|
|
display_name: name_for_path(filepath),
|
2019-11-12 19:06:18 -05:00
|
|
|
default: false,
|
2020-07-01 05:09:30 -04:00
|
|
|
system_dashboard: false,
|
|
|
|
out_of_the_box_dashboard: out_of_the_box_dashboard?
|
2019-07-29 19:03:59 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Grabs the filepath after the base directory.
|
|
|
|
def name_for_path(filepath)
|
2020-07-30 20:09:37 -04:00
|
|
|
filepath.delete_prefix("#{Gitlab::Metrics::Dashboard::RepoDashboardFinder::DASHBOARD_ROOT}/")
|
2019-07-29 19:03:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Searches the project repo for a custom-defined dashboard.
|
|
|
|
def get_raw_dashboard
|
2020-07-30 20:09:37 -04:00
|
|
|
yml = Gitlab::Metrics::Dashboard::RepoDashboardFinder.read_dashboard(project, dashboard_path)
|
2019-07-29 19:03:59 -04:00
|
|
|
|
2020-06-26 20:09:17 -04:00
|
|
|
load_yaml(yml)
|
2019-07-29 19:03:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def cache_key
|
|
|
|
"project_#{project.id}_metrics_dashboard_#{dashboard_path}"
|
|
|
|
end
|
2020-10-02 14:08:56 -04:00
|
|
|
|
|
|
|
def sequence
|
|
|
|
[
|
|
|
|
::Gitlab::Metrics::Dashboard::Stages::CustomDashboardMetricsInserter
|
|
|
|
] + super
|
|
|
|
end
|
2019-07-29 19:03:59 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|