diff options
Diffstat (limited to 'lib/gitlab/metrics')
-rw-r--r-- | lib/gitlab/metrics/dashboard/errors.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/finder.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/processor.rb | 32 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/service_selector.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/stages/base_stage.rb | 15 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb | 8 |
6 files changed, 24 insertions, 43 deletions
diff --git a/lib/gitlab/metrics/dashboard/errors.rb b/lib/gitlab/metrics/dashboard/errors.rb index 1739a4e6738..d41bd2c43c7 100644 --- a/lib/gitlab/metrics/dashboard/errors.rb +++ b/lib/gitlab/metrics/dashboard/errors.rb @@ -7,14 +7,16 @@ module Gitlab module Metrics module Dashboard module Errors + DashboardProcessingError = Class.new(StandardError) PanelNotFoundError = Class.new(StandardError) + LayoutError = Class.new(DashboardProcessingError) + MissingQueryError = Class.new(DashboardProcessingError) - PROCESSING_ERROR = Gitlab::Metrics::Dashboard::Stages::BaseStage::DashboardProcessingError NOT_FOUND_ERROR = Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError def handle_errors(error) case error - when PROCESSING_ERROR + when DashboardProcessingError error(error.message, :unprocessable_entity) when NOT_FOUND_ERROR error("#{dashboard_path} could not be found.", :not_found) diff --git a/lib/gitlab/metrics/dashboard/finder.rb b/lib/gitlab/metrics/dashboard/finder.rb index 66c4d662a6c..c3169418371 100644 --- a/lib/gitlab/metrics/dashboard/finder.rb +++ b/lib/gitlab/metrics/dashboard/finder.rb @@ -28,9 +28,9 @@ module Gitlab # @param options - y_label [String] Y-Axis label of # a panel. Used by embedded dashboards. # @return [Hash] - def find(project, user, environment, options = {}) + def find(project, user, options = {}) service_for(options) - .new(project, user, options.merge(environment: environment)) + .new(project, user, options) .get_dashboard end diff --git a/lib/gitlab/metrics/dashboard/processor.rb b/lib/gitlab/metrics/dashboard/processor.rb index c0fa3bb2f3a..bfdee76a818 100644 --- a/lib/gitlab/metrics/dashboard/processor.rb +++ b/lib/gitlab/metrics/dashboard/processor.rb @@ -8,43 +8,23 @@ module Gitlab # the UI. These includes shared metric info, custom metrics # info, and alerts (only in EE). class Processor - SYSTEM_SEQUENCE = [ - Stages::CommonMetricsInserter, - Stages::ProjectMetricsInserter, - Stages::EndpointInserter, - Stages::Sorter - ].freeze - - PROJECT_SEQUENCE = [ - Stages::CommonMetricsInserter, - Stages::EndpointInserter, - Stages::Sorter - ].freeze - - def initialize(project, environment, dashboard) + def initialize(project, dashboard, sequence, params) @project = project - @environment = environment @dashboard = dashboard + @sequence = sequence + @params = params end # Returns a new dashboard hash with the results of # running transforms on the dashboard. - def process(insert_project_metrics:) + def process @dashboard.deep_symbolize_keys.tap do |dashboard| - sequence(insert_project_metrics).each do |stage| - stage.new(@project, @environment, dashboard).transform! + @sequence.each do |stage| + stage.new(@project, dashboard, @params).transform! end end end - - private - - def sequence(insert_project_metrics) - insert_project_metrics ? SYSTEM_SEQUENCE : PROJECT_SEQUENCE - end end end end end - -Gitlab::Metrics::Dashboard::Processor.prepend_if_ee('EE::Gitlab::Metrics::Dashboard::Processor') diff --git a/lib/gitlab/metrics/dashboard/service_selector.rb b/lib/gitlab/metrics/dashboard/service_selector.rb index 934ba9145a2..10b686fbb81 100644 --- a/lib/gitlab/metrics/dashboard/service_selector.rb +++ b/lib/gitlab/metrics/dashboard/service_selector.rb @@ -48,3 +48,5 @@ module Gitlab end end end + +Gitlab::Metrics::Dashboard::ServiceSelector.prepend_if_ee('EE::Gitlab::Metrics::Dashboard::ServiceSelector') diff --git a/lib/gitlab/metrics/dashboard/stages/base_stage.rb b/lib/gitlab/metrics/dashboard/stages/base_stage.rb index 514ed50e58d..f9e4ae4b4b5 100644 --- a/lib/gitlab/metrics/dashboard/stages/base_stage.rb +++ b/lib/gitlab/metrics/dashboard/stages/base_stage.rb @@ -7,15 +7,12 @@ module Gitlab class BaseStage include Gitlab::Metrics::Dashboard::Defaults - DashboardProcessingError = Class.new(StandardError) - LayoutError = Class.new(DashboardProcessingError) + attr_reader :project, :dashboard, :params - attr_reader :project, :environment, :dashboard - - def initialize(project, environment, dashboard) + def initialize(project, dashboard, params) @project = project - @environment = environment @dashboard = dashboard + @params = params end # Entry-point to the stage @@ -26,15 +23,15 @@ module Gitlab protected def missing_panel_groups! - raise LayoutError.new('Top-level key :panel_groups must be an array') + raise Errors::LayoutError.new('Top-level key :panel_groups must be an array') end def missing_panels! - raise LayoutError.new('Each "panel_group" must define an array :panels') + raise Errors::LayoutError.new('Each "panel_group" must define an array :panels') end def missing_metrics! - raise LayoutError.new('Each "panel" must define an array :metrics') + raise Errors::LayoutError.new('Each "panel" must define an array :metrics') end def for_metrics diff --git a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb index 2a959854be0..c00ef208848 100644 --- a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb +++ b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb @@ -5,9 +5,9 @@ module Gitlab module Dashboard module Stages class EndpointInserter < BaseStage - MissingQueryError = Class.new(DashboardProcessingError) - def transform! + raise Errors::DashboardProcessingError.new('Environment is required for Stages::EndpointInserter') unless params[:environment] + for_metrics do |metric| metric[:prometheus_endpoint_path] = endpoint_for_metric(metric) end @@ -18,7 +18,7 @@ module Gitlab def endpoint_for_metric(metric) Gitlab::Routing.url_helpers.prometheus_api_project_environment_path( project, - environment, + params[:environment], proxy_path: query_type(metric), query: query_for_metric(metric) ) @@ -31,7 +31,7 @@ module Gitlab def query_for_metric(metric) query = metric[query_type(metric)] - raise MissingQueryError.new('Each "metric" must define one of :query or :query_range') unless query + raise Errors::MissingQueryError.new('Each "metric" must define one of :query or :query_range') unless query query end |