diff options
author | Sarah Yasonik <syasonik@gitlab.com> | 2019-05-01 13:16:03 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-05-01 13:16:03 +0300 |
commit | 552a3d2fd939d3f8a56cfad9fad62227c1d5aa89 (patch) | |
tree | d10ce5f4615b0e9dbeb7543736984b3e3ff10dbb /app | |
parent | d7b75b661f8ed2468a322c4ae55eadcbdb3b2615 (diff) |
Update metrics dashboard API to load yml from repo
Updates the EnvironmentController#metrics_dashboard endpoint
to support a "dashboard" param, which can be used to specify
the filepath of a dashboard configuration from a project
repository. Dashboard configurations are expected to be
stored in .gitlab/dashboards/.
Updates dashboard post-processing steps to exclude custom
metrics, which should only display on the system dashboard.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 26 | ||||
-rw-r--r-- | app/models/repository.rb | 9 |
2 files changed, 30 insertions, 5 deletions
diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index 4aa572ade73..d8812c023ca 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -13,6 +13,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController before_action only: [:metrics, :additional_metrics, :metrics_dashboard] do push_frontend_feature_flag(:metrics_time_window) push_frontend_feature_flag(:environment_metrics_use_prometheus_endpoint) + push_frontend_feature_flag(:environment_metrics_show_multiple_dashboards) end def index @@ -158,15 +159,28 @@ class Projects::EnvironmentsController < Projects::ApplicationController end def metrics_dashboard - return render_403 unless Feature.enabled?(:environment_metrics_use_prometheus_endpoint, @project) + return render_403 unless Feature.enabled?(:environment_metrics_use_prometheus_endpoint, project) - result = Gitlab::Metrics::Dashboard::Service.new(@project, @current_user, environment: environment).get_dashboard + if Feature.enabled?(:environment_metrics_show_multiple_dashboards, project) + result = dashboard_finder.find(project, current_user, environment, params[:dashboard]) + + result[:all_dashboards] = project.repository.metrics_dashboard_paths + else + result = dashboard_finder.find(project, current_user, environment) + end respond_to do |format| if result[:status] == :success - format.json { render status: :ok, json: result } + format.json do + render status: :ok, json: result.slice(:all_dashboards, :dashboard, :status) + end else - format.json { render status: result[:http_status], json: result } + format.json do + render( + status: result[:http_status], + json: result.slice(:all_dashboards, :message, :status) + ) + end end end end @@ -211,6 +225,10 @@ class Projects::EnvironmentsController < Projects::ApplicationController params.require([:start, :end]) end + def dashboard_finder + Gitlab::Metrics::Dashboard::Finder + end + def search_environment_names return [] unless params[:query] diff --git a/app/models/repository.rb b/app/models/repository.rb index 8b728c4f6b2..f495a03ad8e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -39,7 +39,8 @@ class Repository changelog license_blob license_key gitignore gitlab_ci_yml branch_names tag_names branch_count tag_count avatar exists? root_ref has_visible_content? - issue_template_names merge_request_template_names xcode_project?).freeze + issue_template_names merge_request_template_names + metrics_dashboard_paths xcode_project?).freeze # Methods that use cache_method but only memoize the value MEMOIZED_CACHED_METHODS = %i(license).freeze @@ -57,6 +58,7 @@ class Repository avatar: :avatar, issue_template: :issue_template_names, merge_request_template: :merge_request_template_names, + metrics_dashboard: :metrics_dashboard_paths, xcode_config: :xcode_project? }.freeze @@ -602,6 +604,11 @@ class Repository end cache_method :merge_request_template_names, fallback: [] + def metrics_dashboard_paths + Gitlab::Metrics::Dashboard::Finder.find_all_paths_from_source(project) + end + cache_method :metrics_dashboard_paths + def readme head_tree&.readme end |