Commit c833bf01 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'pl-full-title-incident-issues' into 'master'

Show alert's threshold in incident title for GitLab alerts

See merge request gitlab-org/gitlab-ee!14688
parents d0d318ff 6eef6957
......@@ -26,7 +26,7 @@ module EE
.present
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))
end
end
......
......@@ -3,8 +3,8 @@
module Projects
module Prometheus
class AlertPresenter < Gitlab::View::Presenter::Delegated
def email_subject
[environment_name, alert_title].compact.join(' ')
def full_title
[environment_name, alert_title].compact.join(': ')
end
def project_full_path
......
......@@ -29,7 +29,7 @@ module IncidentManagement
end
def issue_title
alert.title
alert.full_title
end
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
it_behaves_like 'a user cannot unsubscribe through footer link'
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
it 'has expected content' do
......
......@@ -75,16 +75,16 @@ describe Projects::Prometheus::AlertPresenter do
create(:alerting_alert, project: project, metric_id: metric_id)
end
describe '#email_subject' do
describe '#full_title' do
let(:query_title) do
"#{gitlab_alert.title} #{gitlab_alert.computed_operator} #{gitlab_alert.threshold} for 5 minutes"
end
let(:expected_subject) do
"#{alert.environment.name} #{query_title}"
"#{alert.environment.name}: #{query_title}"
end
subject { presenter.email_subject }
subject { presenter.full_title }
it { is_expected.to eq(expected_subject) }
end
......@@ -114,10 +114,22 @@ describe Projects::Prometheus::AlertPresenter do
end
context 'without gitlab alert' do
describe '#email_subject' do
subject { presenter.email_subject }
describe '#full_title' do
subject { presenter.full_title }
it { is_expected.to eq('') }
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('') }
end
end
describe '#metric_query' do
......
......@@ -101,6 +101,30 @@ describe IncidentManagement::CreateIssueService do
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
shared_examples 'invalid alert' 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