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
private
def process_content(&blk)
content.map do |group|
content['panel_groups'].map do |group|
process_group(group, &blk)
end
end
......@@ -63,28 +63,28 @@ module Importers
group: find_group_title_key(group['group'])
}
group['metrics'].map do |metric|
process_metric(metric, attributes, &blk)
group['panels'].map do |panel|
process_panel(panel, attributes, &blk)
end
end
def process_metric(metric, attributes, &blk)
def process_panel(panel, attributes, &blk)
attributes = attributes.merge(
title: metric['title'],
y_label: metric['y_label'])
title: panel['title'],
y_label: panel['y_label'])
metric['queries'].map do |query|
process_metric_query(query, attributes, &blk)
panel['metrics'].map do |metric_details|
process_metric_details(metric_details, attributes, &blk)
end
end
def process_metric_query(query, attributes, &blk)
def process_metric_details(metric_details, attributes, &blk)
attributes = attributes.merge(
legend: query['label'],
query: query['query_range'],
unit: query['unit'])
legend: metric_details['label'],
query: metric_details['query_range'],
unit: metric_details['unit'])
yield(query['id'], attributes)
yield(metric_details['id'], attributes)
end
def find_or_build_metric!(id)
......
......@@ -23,10 +23,10 @@ describe Importers::CommonMetricsImporter do
subject { described_class.new }
context "does import common_metrics.yml" do
let(:groups) { subject.content }
let(:metrics) { groups.map { |group| group['metrics'] }.flatten }
let(:queries) { metrics.map { |group| group['queries'] }.flatten }
let(:query_ids) { queries.map { |query| query['id'] } }
let(:groups) { subject.content['panel_groups'] }
let(:panels) { groups.map { |group| group['panels'] }.flatten }
let(:metrics) { panels.map { |group| group['metrics'] }.flatten }
let(:metric_ids) { metrics.map { |metric| metric['id'] } }
before do
subject.execute
......@@ -36,20 +36,20 @@ describe Importers::CommonMetricsImporter do
expect(PrometheusMetric.common.group(:group).count.count).to eq(groups.count)
end
it "has the same amount of metrics" do
expect(PrometheusMetric.common.group(:group, :title).count.count).to eq(metrics.count)
it "has the same amount of panels" do
expect(PrometheusMetric.common.group(:group, :title).count.count).to eq(panels.count)
end
it "has the same amount of queries" do
expect(PrometheusMetric.common.count).to eq(queries.count)
it "has the same amount of metrics" do
expect(PrometheusMetric.common.count).to eq(metrics.count)
end
it "does not have duplicate IDs" do
expect(query_ids).to eq(query_ids.uniq)
expect(metric_ids).to eq(metric_ids.uniq)
end
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
......@@ -65,24 +65,26 @@ describe Importers::CommonMetricsImporter do
context 'does import properly all fields' do
let(:query_identifier) { 'response-metric' }
let(:group) do
let(:dashboard) do
{
group: 'Response metrics (NGINX Ingress)',
metrics: [{
title: "Throughput",
y_label: "Requests / Sec",
queries: [{
id: query_identifier,
query_range: 'my-query',
unit: 'my-unit',
label: 'status code'
panel_groups: [{
group: 'Response metrics (NGINX Ingress)',
panels: [{
title: "Throughput",
y_label: "Requests / Sec",
metrics: [{
id: query_identifier,
query_range: 'my-query',
unit: 'my-unit',
label: 'status code'
}]
}]
}]
}
end
before do
expect(subject).to receive(:content) { [group.deep_stringify_keys] }
expect(subject).to receive(:content) { dashboard.deep_stringify_keys }
end
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