From c52b81f45762cb7f05a950689dfc6d51b197ea73 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 10 Apr 2020 09:09:39 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../dashboard/custom_metric_embed_service.rb | 47 ++++++++++------------ 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'app/services') diff --git a/app/services/metrics/dashboard/custom_metric_embed_service.rb b/app/services/metrics/dashboard/custom_metric_embed_service.rb index 456074ae6ad..22b592c7aa5 100644 --- a/app/services/metrics/dashboard/custom_metric_embed_service.rb +++ b/app/services/metrics/dashboard/custom_metric_embed_service.rb @@ -57,7 +57,7 @@ module Metrics # @return [Hash] override :raw_dashboard def raw_dashboard - panels_not_found!(identifiers) if panels.empty? + panels_not_found!(identifiers) if metrics.empty? { 'panel_groups' => [{ 'panels' => panels }] } end @@ -66,11 +66,20 @@ module Metrics # Generated dashboard panels for each metric which # matches the provided input. + # + # As the panel is generated + # on the fly, we're using default values for info + # not represented in the DB. + # # @return [Array] def panels - strong_memoize(:panels) do - metrics.map { |metric| panel_for_metric(metric) } - end + [{ + type: DEFAULT_PANEL_TYPE, + weight: DEFAULT_PANEL_WEIGHT, + title: title, + y_label: y_label, + metrics: metrics.map(&:to_metric_hash) + }] end # Metrics which match the provided inputs. @@ -78,12 +87,14 @@ module Metrics # displayed in a single panel/chart. # @return [ActiveRecord::AssociationRelation] def metrics - PrometheusMetricsFinder.new( - project: project, - group: group_key, - title: title, - y_label: y_label - ).execute + strong_memoize(:metrics) do + PrometheusMetricsFinder.new( + project: project, + group: group_key, + title: title, + y_label: y_label + ).execute + end end # Returns a symbol representing the group that @@ -101,22 +112,6 @@ module Metrics .to_s end end - - # Returns a representation of a PromtheusMetric - # as a dashboard panel. As the panel is generated - # on the fly, we're using default values for info - # not represented in the DB. - # - # @return [Hash] - def panel_for_metric(metric) - { - type: DEFAULT_PANEL_TYPE, - weight: DEFAULT_PANEL_WEIGHT, - title: metric.title, - y_label: metric.y_label, - metrics: [metric.to_metric_hash] - } - end end end end -- cgit v1.2.3