2018-09-04 05:42:58 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-31 12:53:50 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Prometheus::MetricGroup do
|
|
|
|
describe '.common_metrics' do
|
2018-09-05 10:52:32 -04:00
|
|
|
let!(:project_metric) { create(:prometheus_metric) }
|
|
|
|
let!(:common_metric_group_a) { create(:prometheus_metric, :common, group: :aws_elb) }
|
|
|
|
let!(:common_metric_group_b_q1) { create(:prometheus_metric, :common, group: :kubernetes) }
|
|
|
|
let!(:common_metric_group_b_q2) { create(:prometheus_metric, :common, group: :kubernetes) }
|
2018-08-31 12:53:50 -04:00
|
|
|
|
|
|
|
subject { described_class.common_metrics }
|
|
|
|
|
|
|
|
it 'returns exactly two groups' do
|
2018-09-05 11:02:23 -04:00
|
|
|
expect(subject.map(&:name)).to contain_exactly(
|
|
|
|
'Response metrics (AWS ELB)', 'System metrics (Kubernetes)')
|
2018-08-31 12:53:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns exactly three metric queries' do
|
2018-09-05 10:52:32 -04:00
|
|
|
expect(subject.map(&:metrics).flatten.map(&:id)).to contain_exactly(
|
|
|
|
common_metric_group_a.id, common_metric_group_b_q1.id,
|
|
|
|
common_metric_group_b_q2.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.for_project' do
|
|
|
|
let!(:other_project) { create(:project) }
|
|
|
|
let!(:project_metric) { create(:prometheus_metric) }
|
|
|
|
let!(:common_metric) { create(:prometheus_metric, :common, group: :aws_elb) }
|
|
|
|
|
2018-09-05 11:02:23 -04:00
|
|
|
subject do
|
|
|
|
described_class.for_project(other_project)
|
|
|
|
.map(&:metrics).flatten
|
|
|
|
.map(&:id)
|
|
|
|
end
|
2018-09-05 10:52:32 -04:00
|
|
|
|
|
|
|
it 'returns exactly one common metric' do
|
2018-09-05 11:02:23 -04:00
|
|
|
is_expected.to contain_exactly(common_metric.id)
|
2018-08-31 12:53:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|