diff options
author | syasonik <syasonik@gitlab.com> | 2019-06-05 14:43:50 +0100 |
---|---|---|
committer | syasonik <syasonik@gitlab.com> | 2019-06-06 11:43:50 +0100 |
commit | 54dd44030b052a1456c26e90742b227943d600be (patch) | |
tree | f3e03df0ec7506b8916e1114e30f74052c3f2e73 /lib | |
parent | b46b38ff9fb09692aa02efd377e44756e1caabf2 (diff) | |
download | gitlab-ce-54dd44030b052a1456c26e90742b227943d600be.tar.gz |
Expose prometheus endpoint per metric in dashboard
Adds a new stage to dashboard processesing step for the
EnvironmentsController::metrics_dashboard endpoint.
Allows the front end to avoid generating the endpoint
unitutive string mutations.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics/dashboard/base_service.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/processor.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb | 43 |
3 files changed, 47 insertions, 1 deletions
diff --git a/lib/gitlab/metrics/dashboard/base_service.rb b/lib/gitlab/metrics/dashboard/base_service.rb index 94aabd0466c..ce6ecf933a1 100644 --- a/lib/gitlab/metrics/dashboard/base_service.rb +++ b/lib/gitlab/metrics/dashboard/base_service.rb @@ -7,12 +7,13 @@ module Gitlab module Dashboard class BaseService < ::BaseService DASHBOARD_LAYOUT_ERROR = Gitlab::Metrics::Dashboard::Stages::BaseStage::DashboardLayoutError + MISSING_QUERY_ERROR = Gitlab::Metrics::Dashboard::Stages::EndpointInserter::MissingQueryError def get_dashboard return error("#{dashboard_path} could not be found.", :not_found) unless path_available? success(dashboard: process_dashboard) - rescue DASHBOARD_LAYOUT_ERROR => e + rescue DASHBOARD_LAYOUT_ERROR, MISSING_QUERY_ERROR => e error(e.message, :unprocessable_entity) end diff --git a/lib/gitlab/metrics/dashboard/processor.rb b/lib/gitlab/metrics/dashboard/processor.rb index dd986020693..a33a010ad97 100644 --- a/lib/gitlab/metrics/dashboard/processor.rb +++ b/lib/gitlab/metrics/dashboard/processor.rb @@ -11,11 +11,13 @@ module Gitlab SYSTEM_SEQUENCE = [ Stages::CommonMetricsInserter, Stages::ProjectMetricsInserter, + Stages::EndpointInserter, Stages::Sorter ].freeze PROJECT_SEQUENCE = [ Stages::CommonMetricsInserter, + Stages::EndpointInserter, Stages::Sorter ].freeze diff --git a/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb new file mode 100644 index 00000000000..797df14b0e7 --- /dev/null +++ b/lib/gitlab/metrics/dashboard/stages/endpoint_inserter.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Gitlab + module Metrics + module Dashboard + module Stages + class EndpointInserter < BaseStage + MissingQueryError = Class.new(StandardError) + + def transform! + for_metrics do |metric| + metric[:prometheus_endpoint_path] = endpoint_for_metric(metric) + end + end + + private + + def endpoint_for_metric(metric) + Gitlab::Routing.url_helpers.prometheus_api_namespace_project_environment_path( + project.namespace, + project, + environment, + proxy_path: query_type(metric), + query: query_for_metric(metric) + ) + end + + def query_type(metric) + metric[:query] ? :query : :query_range + end + + def query_for_metric(metric) + query = metric[query_type(metric)] + + raise MissingQueryError.new('Missing required metric key: one of :query or :query_range') unless query + + query + end + end + end + end + end +end |