Commit 185ec807 authored by syasonik's avatar syasonik

Save multi-dashboard logic for another MR

parent a2920682
......@@ -163,7 +163,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
respond_to do |format|
format.json do
dashboard = MetricsDashboardService.new(@project).find(params[:dashboard])
dashboard = MetricsDashboardService.new.get_dashboard
render json: dashboard, status: :ok
end
......
# 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`
# Fetches the metrics dashboard layout and supplemented the output with DB info.
class MetricsDashboardService
DASHBOARD_ROOT = ".gitlab/dashboards"
DASHBOARD_EXTENSION = '.yml'
SYSTEM_DASHBOARD_NAME = 'system_dashboard'
SYSTEM_DASHBOARD_ROOT = "config/prometheus"
SYSTEM_DASHBOARD_PATH = Rails.root.join(SYSTEM_DASHBOARD_ROOT, "#{SYSTEM_DASHBOARD_NAME}#{DASHBOARD_EXTENSION}")
def initialize(project)
@project = project
end
SYSTEM_DASHBOARD_PATH = Rails.root.join("config/prometheus", "#{SYSTEM_DASHBOARD_NAME}.yml")
# Returns a DB-supplemented json representation of a dashboard config file.
#
# param: dashboard_name [String] Filename of dashboard w/o an extension.
# If not provided, the system dashboard will be returned.
def find(dashboard_name = nil)
unless Feature.enabled?(:environment_metrics_show_multiple_dashboards, @project)
return process_dashboard(system_dashboard)
end
dashboard = Rails.cache.fetch(cache_key(dashboard_name)) do
dashboard_name ? project_dashboard(dashboard) : system_dashboard
end
def get_dashboard
dashboard = Rails.cache.fetch(cache_key) { system_dashboard }
process_dashboard(dashboard)
end
......@@ -37,19 +19,8 @@ class MetricsDashboardService
YAML.load_file(SYSTEM_DASHBOARD_PATH)
end
# Searches the project repo for a custom-defined dashboard.
def project_dashboard(dashboard_name)
Gitlab::Template::Finders::RepoTemplateFinder.new(
project,
DASHBOARD_ROOT,
DASHBOARD_EXTENSION
).find(dashboard_name).read
end
def cache_key(dashboard_name)
return "metrics_dashboard_#{SYSTEM_DASHBOARD_NAME}" unless dashboard_name
"project_#{@project.id}_metrics_dashboard_#{dashboard_name}"
def cache_key
"metrics_dashboard_#{SYSTEM_DASHBOARD_NAME}"
end
# TODO: "Processing" the dashboard needs to include several steps such as
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment