diff options
author | syasonik <syasonik@gitlab.com> | 2019-04-11 10:04:22 +0300 |
---|---|---|
committer | syasonik <syasonik@gitlab.com> | 2019-04-24 13:23:03 +0300 |
commit | 185ec80751c665bdde6f5494d7cb51acbb2784a4 (patch) | |
tree | 5e103619785dbd7126eb0eb9029f4369c201feda | |
parent | a2920682ec307b9aa830903014139948cdbb9b1f (diff) |
Save multi-dashboard logic for another MR
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 2 | ||||
-rw-r--r-- | app/services/metrics_dashboard_service.rb | 41 |
2 files changed, 7 insertions, 36 deletions
diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 41fe70052ce..ea25ae22bcf 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -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 diff --git a/app/services/metrics_dashboard_service.rb b/app/services/metrics_dashboard_service.rb index 532f5697be8..2f5c6cb4532 100644 --- a/app/services/metrics_dashboard_service.rb +++ b/app/services/metrics_dashboard_service.rb @@ -1,31 +1,13 @@ # 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 |