Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
0f8c7e9e
Commit
0f8c7e9e
authored
Feb 07, 2019
by
Peter Leitzen
Committed by
Douglas Barbosa Alexandre
Feb 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send notification mails for external alerts
parent
c51917fe
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
3 deletions
+94
-3
ee/app/presenters/projects/prometheus/alert_presenter.rb
ee/app/presenters/projects/prometheus/alert_presenter.rb
+5
-1
ee/app/views/notify/prometheus_alert_fired_email.html.haml
ee/app/views/notify/prometheus_alert_fired_email.html.haml
+4
-0
ee/app/views/notify/prometheus_alert_fired_email.text.erb
ee/app/views/notify/prometheus_alert_fired_email.text.erb
+4
-0
ee/changelogs/unreleased/pl-mail-external-alerts.yml
ee/changelogs/unreleased/pl-mail-external-alerts.yml
+5
-0
ee/lib/gitlab/alerting/alert.rb
ee/lib/gitlab/alerting/alert.rb
+23
-1
ee/spec/lib/gitlab/alerting/alert_spec.rb
ee/spec/lib/gitlab/alerting/alert_spec.rb
+6
-0
ee/spec/mailers/ee/emails/projects_spec.rb
ee/spec/mailers/ee/emails/projects_spec.rb
+47
-1
No files found.
ee/app/presenters/projects/prometheus/alert_presenter.rb
View file @
0f8c7e9e
...
...
@@ -4,7 +4,7 @@ module Projects
module
Prometheus
class
AlertPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
def
email_subject
[
environment_name
,
query
_title
].
compact
.
join
(
' '
)
[
environment_name
,
alert
_title
].
compact
.
join
(
' '
)
end
def
project_full_path
...
...
@@ -29,6 +29,10 @@ module Projects
private
def
alert_title
query_title
||
title
end
def
query_title
return
unless
gitlab_alert
...
...
ee/app/views/notify/prometheus_alert_fired_email.html.haml
View file @
0f8c7e9e
%p
An alert has been triggered in
#{
@alert
.
project_full_path
}
.
-
if
description
=
@alert
.
description
%p
Description:
#{
description
}
-
if
env_name
=
@alert
.
environment_name
%p
Environment:
#{
env_name
}
...
...
ee/app/views/notify/prometheus_alert_fired_email.text.erb
View file @
0f8c7e9e
An alert has been triggered in
<%=
@alert
.
project_full_path
%>
.
<%
if
description
=
@alert
.
description
%>
Description:
<%=
description
%>
<%
end
%>
<%
if
env_name
=
@alert
.
environment_name
%>
Environment:
<%=
env_name
%>
<%
end
%>
...
...
ee/changelogs/unreleased/pl-mail-external-alerts.yml
0 → 100644
View file @
0f8c7e9e
---
title
:
Enable mails for external alerts
merge_request
:
9457
author
:
type
:
added
ee/lib/gitlab/alerting/alert.rb
View file @
0f8c7e9e
...
...
@@ -15,12 +15,24 @@ module Gitlab
end
end
def
title
strong_memoize
(
:title
)
do
parse_title_from_payload
end
end
def
description
strong_memoize
(
:description
)
do
parse_description_from_payload
end
end
def
environment
gitlab_alert
&
.
environment
end
def
valid?
project
&&
gitlab_alert
project
&&
title
end
def
present
...
...
@@ -35,6 +47,16 @@ module Gitlab
project
.
prometheus_alerts
.
for_metric
(
metric_id
).
first
end
def
parse_title_from_payload
gitlab_alert
&
.
title
||
payload
&
.
dig
(
'annotations'
,
'title'
)
||
payload
&
.
dig
(
'annotations'
,
'summary'
)
end
def
parse_description_from_payload
payload
&
.
dig
(
'annotations'
,
'description'
)
end
end
end
end
ee/spec/lib/gitlab/alerting/alert_spec.rb
View file @
0f8c7e9e
...
...
@@ -28,6 +28,12 @@ describe Gitlab::Alerting::Alert do
expect
(
alert
.
environment
).
to
eq
(
gitlab_alert
.
environment
)
end
it
'prefers gitlab_alert\'s title over annotated title'
do
payload
[
'annontations'
]
=
{
'title'
=>
'other title'
}
expect
(
alert
.
title
).
to
eq
(
gitlab_alert
.
title
)
end
it
'is valid'
do
expect
(
alert
).
to
be_valid
end
...
...
ee/spec/mailers/ee/emails/projects_spec.rb
View file @
0f8c7e9e
...
...
@@ -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
(
/Alert:
#{
environment
.
name
}
#{
title
}
/
)
is_expected
.
to
have_subject
(
"
#{
project
.
name
}
| Alert:
#{
environment
.
name
}
#{
title
}
for 5 minutes"
)
end
it
'has expected content'
do
...
...
@@ -77,5 +77,51 @@ describe EE::Emails::Projects do
it_behaves_like
'no email'
end
context
'with an external alert'
do
let
(
:title
)
{
'alert title'
}
let
(
:metrics_url
)
do
metrics_project_environments_url
(
project
)
end
let
(
:alert_params
)
do
{
'annotations'
=>
{
'title'
=>
title
}
}
end
it_behaves_like
'an email sent from GitLab'
it_behaves_like
'it should not have Gmail Actions links'
it_behaves_like
'a user cannot unsubscribe through footer link'
it
'has expected subject'
do
is_expected
.
to
have_subject
(
"
#{
project
.
name
}
| Alert:
#{
title
}
"
)
end
it
'has expected content'
do
is_expected
.
to
have_body_text
(
'An alert has been triggered'
)
is_expected
.
to
have_body_text
(
project
.
full_path
)
is_expected
.
not_to
have_body_text
(
'Description:'
)
is_expected
.
not_to
have_body_text
(
'Environment:'
)
is_expected
.
not_to
have_body_text
(
'Metric:'
)
is_expected
.
to
have_body_text
(
metrics_url
)
end
context
'with annotated description'
do
let
(
:description
)
{
'description'
}
before
do
alert_params
[
'annotations'
][
'description'
]
=
description
end
it
'shows the description'
do
is_expected
.
to
have_body_text
(
'Description:'
)
is_expected
.
to
have_body_text
(
description
)
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment