diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/lib/gitlab/alerting | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/lib/gitlab/alerting')
-rw-r--r-- | spec/lib/gitlab/alerting/alert_spec.rb | 24 | ||||
-rw-r--r-- | spec/lib/gitlab/alerting/notification_payload_parser_spec.rb | 29 |
2 files changed, 48 insertions, 5 deletions
diff --git a/spec/lib/gitlab/alerting/alert_spec.rb b/spec/lib/gitlab/alerting/alert_spec.rb index 6d97f08af91..a0582515f3d 100644 --- a/spec/lib/gitlab/alerting/alert_spec.rb +++ b/spec/lib/gitlab/alerting/alert_spec.rb @@ -246,6 +246,30 @@ describe Gitlab::Alerting::Alert do it_behaves_like 'parse payload', 'annotations/gitlab_incident_markdown' end + describe '#gitlab_fingerprint' do + subject { alert.gitlab_fingerprint } + + context 'when the alert is a GitLab managed alert' do + include_context 'gitlab alert' + + it 'returns a fingerprint' do + plain_fingerprint = [alert.metric_id, alert.starts_at].join('/') + + is_expected.to eq(Digest::SHA1.hexdigest(plain_fingerprint)) + end + end + + context 'when the alert is from self managed Prometheus' do + include_context 'full query' + + it 'returns a fingerprint' do + plain_fingerprint = [alert.starts_at, alert.title, alert.full_query].join('/') + + is_expected.to eq(Digest::SHA1.hexdigest(plain_fingerprint)) + end + end + end + describe '#valid?' do before do payload.update( diff --git a/spec/lib/gitlab/alerting/notification_payload_parser_spec.rb b/spec/lib/gitlab/alerting/notification_payload_parser_spec.rb index a38aea7b972..f32095b3c86 100644 --- a/spec/lib/gitlab/alerting/notification_payload_parser_spec.rb +++ b/spec/lib/gitlab/alerting/notification_payload_parser_spec.rb @@ -12,7 +12,8 @@ describe Gitlab::Alerting::NotificationPayloadParser do 'description' => 'Description', 'monitoring_tool' => 'Monitoring tool name', 'service' => 'Service', - 'hosts' => ['gitlab.com'] + 'hosts' => ['gitlab.com'], + 'severity' => 'low' } end @@ -26,7 +27,8 @@ describe Gitlab::Alerting::NotificationPayloadParser do 'description' => 'Description', 'monitoring_tool' => 'Monitoring tool name', 'service' => 'Service', - 'hosts' => ['gitlab.com'] + 'hosts' => ['gitlab.com'], + 'severity' => 'low' }, 'startsAt' => starts_at.rfc3339 } @@ -67,11 +69,24 @@ describe Gitlab::Alerting::NotificationPayloadParser do let(:payload) { {} } it 'returns default parameters' do - is_expected.to eq( - 'annotations' => { 'title' => 'New: Incident' }, + is_expected.to match( + 'annotations' => { + 'title' => described_class::DEFAULT_TITLE, + 'severity' => described_class::DEFAULT_SEVERITY + }, 'startsAt' => starts_at.rfc3339 ) end + + context 'when severity is blank' do + before do + payload[:severity] = '' + end + + it 'sets severity to the default ' do + expect(subject.dig('annotations', 'severity')).to eq(described_class::DEFAULT_SEVERITY) + end + end end context 'when payload attributes have blank lines' do @@ -88,7 +103,10 @@ describe Gitlab::Alerting::NotificationPayloadParser do it 'returns default parameters' do is_expected.to eq( - 'annotations' => { 'title' => 'New: Incident' }, + 'annotations' => { + 'title' => 'New: Incident', + 'severity' => described_class::DEFAULT_SEVERITY + }, 'startsAt' => starts_at.rfc3339 ) end @@ -112,6 +130,7 @@ describe Gitlab::Alerting::NotificationPayloadParser do is_expected.to eq( 'annotations' => { 'title' => 'New: Incident', + 'severity' => described_class::DEFAULT_SEVERITY, 'description' => 'Description', 'additional.params.1' => 'Some value 1', 'additional.params.2' => 'Some value 2' |