Commit 1aa0ceae authored by Douwe Maan's avatar Douwe Maan

Merge branch '60383-change-common-metrics-schema' into 'master'

Change the schema of common_metrics.yml

Closes #60383

See merge request gitlab-org/gitlab-ce!27283
parents 6376f784 e5966e5d
This diff is collapsed.
...@@ -53,7 +53,7 @@ module Importers ...@@ -53,7 +53,7 @@ module Importers
private private
def process_content(&blk) def process_content(&blk)
content.map do |group| content['panel_groups'].map do |group|
process_group(group, &blk) process_group(group, &blk)
end end
end end
...@@ -63,28 +63,28 @@ module Importers ...@@ -63,28 +63,28 @@ module Importers
group: find_group_title_key(group['group']) group: find_group_title_key(group['group'])
} }
group['metrics'].map do |metric| group['panels'].map do |panel|
process_metric(metric, attributes, &blk) process_panel(panel, attributes, &blk)
end end
end end
def process_metric(metric, attributes, &blk) def process_panel(panel, attributes, &blk)
attributes = attributes.merge( attributes = attributes.merge(
title: metric['title'], title: panel['title'],
y_label: metric['y_label']) y_label: panel['y_label'])
metric['queries'].map do |query| panel['metrics'].map do |metric_details|
process_metric_query(query, attributes, &blk) process_metric_details(metric_details, attributes, &blk)
end end
end end
def process_metric_query(query, attributes, &blk) def process_metric_details(metric_details, attributes, &blk)
attributes = attributes.merge( attributes = attributes.merge(
legend: query['label'], legend: metric_details['label'],
query: query['query_range'], query: metric_details['query_range'],
unit: query['unit']) unit: metric_details['unit'])
yield(query['id'], attributes) yield(metric_details['id'], attributes)
end end
def find_or_build_metric!(id) def find_or_build_metric!(id)
......
...@@ -23,10 +23,10 @@ describe Importers::CommonMetricsImporter do ...@@ -23,10 +23,10 @@ describe Importers::CommonMetricsImporter do
subject { described_class.new } subject { described_class.new }
context "does import common_metrics.yml" do context "does import common_metrics.yml" do
let(:groups) { subject.content } let(:groups) { subject.content['panel_groups'] }
let(:metrics) { groups.map { |group| group['metrics'] }.flatten } let(:panels) { groups.map { |group| group['panels'] }.flatten }
let(:queries) { metrics.map { |group| group['queries'] }.flatten } let(:metrics) { panels.map { |group| group['metrics'] }.flatten }
let(:query_ids) { queries.map { |query| query['id'] } } let(:metric_ids) { metrics.map { |metric| metric['id'] } }
before do before do
subject.execute subject.execute
...@@ -36,20 +36,20 @@ describe Importers::CommonMetricsImporter do ...@@ -36,20 +36,20 @@ describe Importers::CommonMetricsImporter do
expect(PrometheusMetric.common.group(:group).count.count).to eq(groups.count) expect(PrometheusMetric.common.group(:group).count.count).to eq(groups.count)
end end
it "has the same amount of metrics" do it "has the same amount of panels" do
expect(PrometheusMetric.common.group(:group, :title).count.count).to eq(metrics.count) expect(PrometheusMetric.common.group(:group, :title).count.count).to eq(panels.count)
end end
it "has the same amount of queries" do it "has the same amount of metrics" do
expect(PrometheusMetric.common.count).to eq(queries.count) expect(PrometheusMetric.common.count).to eq(metrics.count)
end end
it "does not have duplicate IDs" do it "does not have duplicate IDs" do
expect(query_ids).to eq(query_ids.uniq) expect(metric_ids).to eq(metric_ids.uniq)
end end
it "imports all IDs" do it "imports all IDs" do
expect(PrometheusMetric.common.pluck(:identifier)).to contain_exactly(*query_ids) expect(PrometheusMetric.common.pluck(:identifier)).to contain_exactly(*metric_ids)
end end
end end
...@@ -65,24 +65,26 @@ describe Importers::CommonMetricsImporter do ...@@ -65,24 +65,26 @@ describe Importers::CommonMetricsImporter do
context 'does import properly all fields' do context 'does import properly all fields' do
let(:query_identifier) { 'response-metric' } let(:query_identifier) { 'response-metric' }
let(:group) do let(:dashboard) do
{ {
panel_groups: [{
group: 'Response metrics (NGINX Ingress)', group: 'Response metrics (NGINX Ingress)',
metrics: [{ panels: [{
title: "Throughput", title: "Throughput",
y_label: "Requests / Sec", y_label: "Requests / Sec",
queries: [{ metrics: [{
id: query_identifier, id: query_identifier,
query_range: 'my-query', query_range: 'my-query',
unit: 'my-unit', unit: 'my-unit',
label: 'status code' label: 'status code'
}] }]
}] }]
}]
} }
end end
before do before do
expect(subject).to receive(:content) { [group.deep_stringify_keys] } expect(subject).to receive(:content) { dashboard.deep_stringify_keys }
end end
shared_examples 'stores metric' do shared_examples 'stores metric' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment