diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-13 15:10:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-13 15:10:03 +0300 |
commit | 75ee59f7a108cf0c57e1e66e3ef5e439bae24fcd (patch) | |
tree | b2f1ec89e16c6b27041f608c9fb12b7586e5ce94 /spec/lib/gitlab/metrics | |
parent | e79918ce90dc31527be1ef0140a99cfe450d931e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r-- | spec/lib/gitlab/metrics/dashboard/processor_spec.rb | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb index d957b1c992f..3cb02a8bcb3 100644 --- a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb @@ -14,9 +14,11 @@ describe Gitlab::Metrics::Dashboard::Processor do Gitlab::Metrics::Dashboard::Stages::CustomMetricsInserter, Gitlab::Metrics::Dashboard::Stages::CustomMetricsDetailsInserter, Gitlab::Metrics::Dashboard::Stages::EndpointInserter, - Gitlab::Metrics::Dashboard::Stages::Sorter + Gitlab::Metrics::Dashboard::Stages::Sorter, + Gitlab::Metrics::Dashboard::Stages::AlertsInserter ] end + let(:process_params) { [project, dashboard_yml, sequence, { environment: environment }] } let(:dashboard) { described_class.new(*process_params).process } @@ -113,6 +115,54 @@ describe Gitlab::Metrics::Dashboard::Processor do end end + context 'when the dashboard references persisted metrics with alerts' do + let!(:alert) do + create( + :prometheus_alert, + environment: environment, + project: project, + prometheus_metric: persisted_metric + ) + end + + shared_examples_for 'has saved alerts' do + it 'includes an alert path' do + target_metric = all_metrics.find { |metric| metric[:metric_id] == persisted_metric.id } + + expect(target_metric).to be_a Hash + expect(target_metric).to include(:alert_path) + expect(target_metric[:alert_path]).to include( + project.path, + persisted_metric.id.to_s, + environment.id.to_s + ) + end + end + + context 'that are shared across projects' do + let!(:persisted_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') } + + it_behaves_like 'has saved alerts' + end + + context 'when the project has associated metrics' do + let!(:persisted_metric) { create(:prometheus_metric, project: project, group: :business) } + + it_behaves_like 'has saved alerts' + end + end + + context 'when there are no alerts' do + let!(:persisted_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') } + + it 'does not insert an alert_path' do + target_metric = all_metrics.find { |metric| metric[:metric_id] == persisted_metric.id } + + expect(target_metric).to be_a Hash + expect(target_metric).not_to include(:alert_path) + end + end + shared_examples_for 'errors with message' do |expected_message| it 'raises a DashboardLayoutError' do error_class = Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError |