2019-10-12 21:52:04 +05:30
|
|
|
# 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`
|
|
|
|
module Metrics
|
|
|
|
module Dashboard
|
|
|
|
class BaseService < ::BaseService
|
|
|
|
include Gitlab::Metrics::Dashboard::Errors
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
STAGES = ::Gitlab::Metrics::Dashboard::Stages
|
|
|
|
SEQUENCE = [
|
|
|
|
STAGES::CommonMetricsInserter,
|
|
|
|
STAGES::EndpointInserter,
|
|
|
|
STAGES::Sorter
|
|
|
|
].freeze
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
def get_dashboard
|
|
|
|
return error('Insufficient permissions.', :unauthorized) unless allowed?
|
|
|
|
|
|
|
|
success(dashboard: process_dashboard)
|
|
|
|
rescue StandardError => e
|
|
|
|
handle_errors(e)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Summary of all known dashboards for the service.
|
|
|
|
# @return [Array<Hash>] ex) [{ path: String, default: Boolean }]
|
|
|
|
def self.all_dashboard_paths(_project)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns an un-processed dashboard from the cache.
|
|
|
|
def raw_dashboard
|
|
|
|
Gitlab::Metrics::Dashboard::Cache.fetch(cache_key) { get_raw_dashboard }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Determines whether users should be able to view
|
|
|
|
# dashboards at all.
|
|
|
|
def allowed?
|
2020-03-09 13:42:32 +05:30
|
|
|
return false unless params[:environment]
|
|
|
|
|
|
|
|
Ability.allowed?(current_user, :read_environment, project)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
# Returns a new dashboard Hash, supplemented with DB info
|
|
|
|
def process_dashboard
|
2019-12-04 20:38:33 +05:30
|
|
|
::Gitlab::Metrics::Dashboard::Processor
|
2020-03-09 13:42:32 +05:30
|
|
|
.new(project, raw_dashboard, sequence, process_params)
|
2019-12-04 20:38:33 +05:30
|
|
|
.process
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
def process_params
|
|
|
|
params
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
# @return [String] Relative filepath of the dashboard yml
|
|
|
|
def dashboard_path
|
|
|
|
params[:dashboard_path]
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [Hash] an unmodified dashboard
|
|
|
|
def get_raw_dashboard
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [String]
|
|
|
|
def cache_key
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
def sequence
|
|
|
|
SEQUENCE
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Metrics::Dashboard::BaseService.prepend_if_ee('EE::Metrics::Dashboard::BaseService')
|