1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
require 'spec_helper'
describe MetricsDashboardProcessingService do
let(:project) { build(:project) }
let(:dashboard_yml) { YAML.load_file('spec/fixtures/services/metrics_dashboard_processing_service.yml') }
describe 'process' do
let(:dashboard) { JSON.parse(described_class.new(dashboard_yml, project).process, symbolize_names: true) }
context 'when dashboard config corresponds to common metrics' do
let!(:common_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') }
it 'inserts metric ids into the config' do
target_metric = all_metrics.find { |metric| metric[:id] == 'metric_a1' }
expect(target_metric).to include(:metric_id)
end
end
context 'when the project has associated metrics' do
let!(:project_metric) { create(:prometheus_metric, project: project) }
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
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] }
expect(actual_metrics_order).to eq expected_metrics_order
end
end
it 'orders groups by priority and panels by weight' do
expected_metrics_order = ['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
def all_metrics
dashboard[:panel_groups].map do |group|
group[:panels].map { |panel| panel[:metrics] }
end.flatten
end
end
|