Commit 6eef6957 authored by Peter Leitzen's avatar Peter Leitzen Committed by Sean McGivern

Show threshold in incident title for gitlab alerts

Rename `#email_subject` to `#full_title`
parent d0d318ff
...@@ -26,7 +26,7 @@ module EE ...@@ -26,7 +26,7 @@ module EE
.present .present
return unless @alert.valid? return unless @alert.valid?
subject_text = "Alert: #{@alert.email_subject}" subject_text = "Alert: #{@alert.full_title}"
mail(to: recipient(user_id, @project.group), subject: subject(subject_text)) mail(to: recipient(user_id, @project.group), subject: subject(subject_text))
end end
end end
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
module Projects module Projects
module Prometheus module Prometheus
class AlertPresenter < Gitlab::View::Presenter::Delegated class AlertPresenter < Gitlab::View::Presenter::Delegated
def email_subject def full_title
[environment_name, alert_title].compact.join(' ') [environment_name, alert_title].compact.join(': ')
end end
def project_full_path def project_full_path
......
...@@ -29,7 +29,7 @@ module IncidentManagement ...@@ -29,7 +29,7 @@ module IncidentManagement
end end
def issue_title def issue_title
alert.title alert.full_title
end end
def issue_description def issue_description
......
---
title: Show threshold in incident title for gitlab alerts
merge_request: 14688
author:
type: changed
...@@ -46,7 +46,7 @@ describe EE::Emails::Projects do ...@@ -46,7 +46,7 @@ describe EE::Emails::Projects do
it_behaves_like 'a user cannot unsubscribe through footer link' it_behaves_like 'a user cannot unsubscribe through footer link'
it 'has expected subject' do it 'has expected subject' do
is_expected.to have_subject("#{project.name} | Alert: #{environment.name} #{title} for 5 minutes") is_expected.to have_subject("#{project.name} | Alert: #{environment.name}: #{title} for 5 minutes")
end end
it 'has expected content' do it 'has expected content' do
......
...@@ -75,16 +75,16 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -75,16 +75,16 @@ describe Projects::Prometheus::AlertPresenter do
create(:alerting_alert, project: project, metric_id: metric_id) create(:alerting_alert, project: project, metric_id: metric_id)
end end
describe '#email_subject' do describe '#full_title' do
let(:query_title) do let(:query_title) do
"#{gitlab_alert.title} #{gitlab_alert.computed_operator} #{gitlab_alert.threshold} for 5 minutes" "#{gitlab_alert.title} #{gitlab_alert.computed_operator} #{gitlab_alert.threshold} for 5 minutes"
end end
let(:expected_subject) do let(:expected_subject) do
"#{alert.environment.name} #{query_title}" "#{alert.environment.name}: #{query_title}"
end end
subject { presenter.email_subject } subject { presenter.full_title }
it { is_expected.to eq(expected_subject) } it { is_expected.to eq(expected_subject) }
end end
...@@ -114,11 +114,23 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -114,11 +114,23 @@ describe Projects::Prometheus::AlertPresenter do
end end
context 'without gitlab alert' do context 'without gitlab alert' do
describe '#email_subject' do describe '#full_title' do
subject { presenter.email_subject } subject { presenter.full_title }
context 'with title' do
let(:title) { 'some title' }
before do
expect(alert).to receive(:title).and_return(title)
end
it { is_expected.to eq(title) }
end
context 'without title' do
it { is_expected.to eq('') } it { is_expected.to eq('') }
end end
end
describe '#metric_query' do describe '#metric_query' do
subject { presenter.metric_query } subject { presenter.metric_query }
......
...@@ -101,6 +101,30 @@ describe IncidentManagement::CreateIssueService do ...@@ -101,6 +101,30 @@ describe IncidentManagement::CreateIssueService do
end end
end end
context 'with gitlab alert' do
let(:gitlab_alert) { create(:prometheus_alert, project: project) }
before do
alert_payload['labels'] = {
'gitlab_alert_id' => gitlab_alert.prometheus_metric_id.to_s
}
end
it 'creates an issue' do
query_title = "#{gitlab_alert.title} #{gitlab_alert.computed_operator} #{gitlab_alert.threshold}"
expect(subject).to include(status: :success)
expect(issue.author).to eq(User.alert_bot)
expect(issue.title).to eq(alert_presenter.full_title)
expect(issue.title).to include(gitlab_alert.environment.name)
expect(issue.title).to include(query_title)
expect(issue.title).to include('for 5 minutes')
expect(issue.description).to include(alert_presenter.issue_summary_markdown)
expect(issue.description).not_to include(summary_separator)
end
end
describe 'with invalid alert payload' do describe 'with invalid alert payload' do
shared_examples 'invalid alert' do shared_examples 'invalid alert' do
it 'does not create an issue' do it 'does not create an issue' 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