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
97e49725
Commit
97e49725
authored
Oct 08, 2019
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display Generic Alert params in issue summary
parent
34d7984b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
3 deletions
+81
-3
ee/app/presenters/projects/prometheus/alert_presenter.rb
ee/app/presenters/projects/prometheus/alert_presenter.rb
+23
-1
ee/spec/presenters/projects/prometheus/alert_presenter_spec.rb
...ec/presenters/projects/prometheus/alert_presenter_spec.rb
+58
-2
No files found.
ee/app/presenters/projects/prometheus/alert_presenter.rb
View file @
97e49725
...
...
@@ -4,6 +4,7 @@ module Projects
module
Prometheus
class
AlertPresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
RESERVED_ANNOTATIONS
=
%w(gitlab_incident_markdown)
.
freeze
GENERIC_ALERT_SUMMARY_ANNOTATIONS
=
%w(monitoring_tool service hosts)
.
freeze
MARKDOWN_LINE_BREAK
=
"
\n
"
.
freeze
def
full_title
...
...
@@ -60,6 +61,9 @@ module Projects
metadata
<<
list_item
(
'Start time'
,
starts_at
)
if
starts_at
metadata
<<
list_item
(
'full_query'
,
backtick
(
full_query
))
if
full_query
metadata
<<
list_item
(
'Service'
,
service
)
if
service
metadata
<<
list_item
(
'Monitoring Tool'
,
monitoring_tool
)
if
monitoring_tool
metadata
<<
list_item
(
'Hosts'
,
hosts
.
join
(
' '
))
if
hosts
metadata
.
join
(
MARKDOWN_LINE_BREAK
)
end
...
...
@@ -78,7 +82,7 @@ module Projects
def
annotation_list
strong_memoize
(
:annotation_list
)
do
annotations
.
reject
{
|
annotation
|
RESERVED_ANNOTATIONS
.
include?
(
annotation
.
label
)
}
.
reject
{
|
annotation
|
annotation
.
label
.
in?
(
RESERVED_ANNOTATIONS
|
GENERIC_ALERT_SUMMARY_ANNOTATIONS
)
}
.
map
{
|
annotation
|
list_item
(
annotation
.
label
,
annotation
.
value
)
}
.
join
(
MARKDOWN_LINE_BREAK
)
end
...
...
@@ -91,6 +95,24 @@ module Projects
def
backtick
(
value
)
"`
#{
value
}
`"
end
def
markdown_link
(
title
,
url
)
"[
#{
title
}
](
#{
url
}
)"
end
def
service
annotations
.
find
{
|
a
|
a
.
label
==
'service'
}.
try
(
:value
)
end
def
monitoring_tool
annotations
.
find
{
|
a
|
a
.
label
==
'monitoring_tool'
}.
try
(
:value
)
end
def
hosts
if
value
=
annotations
.
find
{
|
a
|
a
.
label
==
'hosts'
}.
try
(
:value
)
Array
(
value
).
map
{
|
host
|
markdown_link
(
host
,
host
)
}
end
end
end
end
end
ee/spec/presenters/projects/prometheus/alert_presenter_spec.rb
View file @
97e49725
...
...
@@ -37,6 +37,8 @@ describe Projects::Prometheus::AlertPresenter do
end
describe
'#issue_summary_markdown'
do
let
(
:markdown_line_break
)
{
' '
}
subject
{
presenter
.
issue_summary_markdown
}
context
'without default payload'
do
...
...
@@ -66,7 +68,8 @@ describe Projects::Prometheus::AlertPresenter do
#### Alert Details
**foo:** value1
\n
**bar:** value2
**foo:** value1
#{
markdown_line_break
}
**bar:** value2
MARKDOWN
)
end
...
...
@@ -82,11 +85,64 @@ describe Projects::Prometheus::AlertPresenter do
<<~
MARKDOWN
.
chomp
#### Summary
**Start time:**
#{
presenter
.
starts_at
}
\n
**full_query:** `query`
**Start time:**
#{
presenter
.
starts_at
}#{
markdown_line_break
}
**full_query:** `query`
MARKDOWN
)
end
end
context
'with the Generic Alert parameters'
do
let
(
:generic_alert_params
)
do
{
'title'
=>
'The Generic Alert Title'
,
'description'
=>
'The Generic Alert Description'
,
'monitoring_tool'
=>
'monitoring_tool_name'
,
'service'
=>
'service_name'
,
'hosts'
=>
[
'http://localhost:3000'
,
'http://localhost:3001'
]
}
end
before
do
payload
[
'annotations'
]
=
generic_alert_params
end
it
do
is_expected
.
to
eq
(
<<~
MARKDOWN
.
chomp
#### Summary
**Start time:**
#{
presenter
.
starts_at
}#{
markdown_line_break
}
**Service:** service_name
#{
markdown_line_break
}
**Monitoring Tool:** monitoring_tool_name
#{
markdown_line_break
}
**Hosts:** [http://localhost:3000](http://localhost:3000) [http://localhost:3001](http://localhost:3001)
#### Alert Details
**title:** The Generic Alert Title
#{
markdown_line_break
}
**description:** The Generic Alert Description
MARKDOWN
)
end
context
'when hosts is a string'
do
before
do
payload
[
'annotations'
]
=
{
'hosts'
=>
'http://localhost:3000'
}
end
it
do
is_expected
.
to
eq
(
<<~
MARKDOWN
.
chomp
#### Summary
**Start time:**
#{
presenter
.
starts_at
}#{
markdown_line_break
}
**Hosts:** [http://localhost:3000](http://localhost:3000)
MARKDOWN
)
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