diff options
author | rpereira2 <rpereira@gitlab.com> | 2019-04-16 21:07:47 +0530 |
---|---|---|
committer | syasonik <syasonik@gitlab.com> | 2019-04-24 18:23:03 +0800 |
commit | 0007a42a7bcc7bcee3dd10a3132dc96478b77e80 (patch) | |
tree | ad3c60001843faba84d56d329bdb1b5671263dab | |
parent | b1773bf8b741ffc52e2699848e42aa0a054c9e6e (diff) | |
download | gitlab-ce-0007a42a7bcc7bcee3dd10a3132dc96478b77e80.tar.gz |
Correct the order of groups and panels
- Order groups by descending order of priority.
- Order panels by descending order of weight.
- Perform sorting after adding project/custom metrics.
4 files changed, 25 insertions, 24 deletions
diff --git a/lib/gitlab/metrics_dashboard/processor.rb b/lib/gitlab/metrics_dashboard/processor.rb index cfeb0ddb468..518e0123220 100644 --- a/lib/gitlab/metrics_dashboard/processor.rb +++ b/lib/gitlab/metrics_dashboard/processor.rb @@ -3,7 +3,7 @@ module Gitlab module MetricsDashboard class Processor - STAGES = [CommonMetricsInserter, Sorter, ProjectMetricsInserter].freeze + STAGES = [CommonMetricsInserter, ProjectMetricsInserter, Sorter].freeze def initialize(dashboard, project) @dashboard = dashboard.deep_transform_keys(&:to_sym) diff --git a/lib/gitlab/metrics_dashboard/sorter.rb b/lib/gitlab/metrics_dashboard/sorter.rb index 1d28fc8bd3a..9a8f87fcb6e 100644 --- a/lib/gitlab/metrics_dashboard/sorter.rb +++ b/lib/gitlab/metrics_dashboard/sorter.rb @@ -13,13 +13,13 @@ module Gitlab # Sorts the groups in the dashboard by the :priority key def sort_groups!(dashboard) - dashboard[:panel_groups] = dashboard[:panel_groups].sort_by { |group| group[:priority] } + dashboard[:panel_groups] = dashboard[:panel_groups].sort_by { |group| group[:priority] }.reverse end # Sorts the panels in the dashboard by the :weight key def sort_panels!(dashboard) dashboard[:panel_groups].each do |group| - group[:panels] = group[:panels].sort_by { |panel| panel[:weight] } + group[:panels] = group[:panels].sort_by { |panel| panel[:weight] }.reverse end end end diff --git a/spec/fixtures/lib/gitlab/metrics_dashboard/sample_dashboard.yml b/spec/fixtures/lib/gitlab/metrics_dashboard/sample_dashboard.yml index ebfe06da6db..7b6527ea715 100644 --- a/spec/fixtures/lib/gitlab/metrics_dashboard/sample_dashboard.yml +++ b/spec/fixtures/lib/gitlab/metrics_dashboard/sample_dashboard.yml @@ -7,7 +7,7 @@ panel_groups: - title: "Super Chart A1" type: "area-chart" y_label: "y_label" - weight: 2 + weight: 1 metrics: - id: metric_a1 query_range: 'query' @@ -16,7 +16,7 @@ panel_groups: - title: "Super Chart A2" type: "area-chart" y_label: "y_label" - weight: 1 + weight: 2 metrics: - id: metric_a2 query_range: 'query' diff --git a/spec/lib/gitlab/metrics_dashboard/processor_spec.rb b/spec/lib/gitlab/metrics_dashboard/processor_spec.rb index 0b3ee90d3e8..973b3e2e13a 100644 --- a/spec/lib/gitlab/metrics_dashboard/processor_spec.rb +++ b/spec/lib/gitlab/metrics_dashboard/processor_spec.rb @@ -18,38 +18,39 @@ describe Gitlab::MetricsDashboard::Processor do end context 'when the project has associated metrics' do - let!(:project_metric) { create(:prometheus_metric, project: project) } + let!(:project_response_metric) { create(:prometheus_metric, project: project, group: :response) } + let!(:project_system_metric) { create(:prometheus_metric, project: project, group: :system) } + let!(:project_business_metric) { create(:prometheus_metric, project: project, group: :business) } it 'includes project-specific metrics' do - project_metric_details = { - query_range: project_metric.query, - unit: project_metric.unit, - label: project_metric.legend, - metric_id: project_metric.id - } - - expect(all_metrics).to include project_metric_details + expect(all_metrics).to include get_metric_details(project_system_metric) + expect(all_metrics).to include get_metric_details(project_response_metric) + expect(all_metrics).to include get_metric_details(project_business_metric) end - it 'includes project metrics at the end of the config' do - expected_metrics_order = ['metric_b', 'metric_a2', 'metric_a1', nil] - actual_metrics_order = all_metrics.map { |m| m[:id] } + it 'orders groups by priority and panels by weight' do + expected_metrics_order = ['metric_a2', 'metric_a1', 'metric_b', project_business_metric.id, project_response_metric.id, project_system_metric.id] + actual_metrics_order = all_metrics.map { |m| m[:id] || m[:metric_id] } expect(actual_metrics_order).to eq expected_metrics_order end end - - it 'orders groups by priority and panels by weight' do - expected_metrics_order = %w(metric_b metric_a2 metric_a1) - actual_metrics_order = all_metrics.map { |m| m[:id] } - - expect(actual_metrics_order).to eq expected_metrics_order - end end + private + def all_metrics dashboard[:panel_groups].map do |group| group[:panels].map { |panel| panel[:metrics] } end.flatten end + + def get_metric_details(metric) + { + query_range: metric.query, + unit: metric.unit, + label: metric.legend, + metric_id: metric.id + } + end end |