diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 15:09:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 15:09:50 +0000 |
commit | de2fb5b82c92c90f90ed67ced45143c04e934fb8 (patch) | |
tree | ff8e5e642580de7bb596d90dd0e7f739f44ca540 /lib | |
parent | c6a33b298229f9e04933be43d6176c476ef03012 (diff) | |
download | gitlab-ce-de2fb5b82c92c90f90ed67ced45143c04e934fb8.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics/dashboard/stages/base_stage.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/metrics/dashboard/stages/panel_ids_inserter.rb | 58 |
2 files changed, 74 insertions, 4 deletions
diff --git a/lib/gitlab/metrics/dashboard/stages/base_stage.rb b/lib/gitlab/metrics/dashboard/stages/base_stage.rb index f9e4ae4b4b5..622d5aa8cdb 100644 --- a/lib/gitlab/metrics/dashboard/stages/base_stage.rb +++ b/lib/gitlab/metrics/dashboard/stages/base_stage.rb @@ -37,10 +37,8 @@ module Gitlab def for_metrics missing_panel_groups! unless dashboard[:panel_groups].is_a?(Array) - dashboard[:panel_groups].each do |panel_group| - missing_panels! unless panel_group[:panels].is_a?(Array) - - panel_group[:panels].each do |panel| + for_panel_groups do |panel_group| + for_panels_in(panel_group) do |panel| missing_metrics! unless panel[:metrics].is_a?(Array) panel[:metrics].each do |metric| @@ -49,6 +47,20 @@ module Gitlab end end end + + def for_panel_groups + dashboard[:panel_groups].each do |panel_group| + yield panel_group + end + end + + def for_panels_in(panel_group) + missing_panels! unless panel_group[:panels].is_a?(Array) + + panel_group[:panels].each do |panel| + yield panel + end + end end end end diff --git a/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter.rb b/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter.rb new file mode 100644 index 00000000000..301c54b9f23 --- /dev/null +++ b/lib/gitlab/metrics/dashboard/stages/panel_ids_inserter.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Gitlab + module Metrics + module Dashboard + module Stages + class PanelIdsInserter < BaseStage + # For each panel within given dashboard inserts panel_id unique in scope of the dashboard + def transform! + missing_panel_groups! unless dashboard[:panel_groups] + + for_panels_group_with_panels do |panel_group, panel| + id = generate_panel_id(panel_group, panel) + remove_panel_ids! && break if duplicated_panel_id?(id) + + insert_panel_id(id, panel) + end + end + + private + + def generate_panel_id(group, panel) + ::PerformanceMonitoring::PrometheusPanel.new(panel.with_indifferent_access).id(group[:group]) + end + + def insert_panel_id(id, panel) + track_inserted_panel_ids(id, panel) + panel[:id] = id + end + + def track_inserted_panel_ids(id, panel) + panel_ids[id] = panel + end + + def duplicated_panel_id?(id) + panel_ids.key?(id) + end + + def remove_panel_ids! + panel_ids.each_value { |panel| panel.delete(:id) } + end + + def panel_ids + @_panel_ids ||= {} + end + + def for_panels_group_with_panels + for_panel_groups do |panel_group| + for_panels_in(panel_group) do |panel| + yield panel_group, panel + end + end + end + end + end + end + end +end |