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
305ae13d
Commit
305ae13d
authored
Aug 07, 2020
by
Sarah Yasonik
Committed by
Nick Thomas
Aug 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose runbook in alert GraphQL API
parent
f53bd910
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
75 additions
and
9 deletions
+75
-9
app/graphql/types/alert_management/alert_type.rb
app/graphql/types/alert_management/alert_type.rb
+6
-2
app/models/alert_management/alert.rb
app/models/alert_management/alert.rb
+1
-0
app/presenters/alert_management/alert_presenter.rb
app/presenters/alert_management/alert_presenter.rb
+6
-0
app/presenters/alert_management/prometheus_alert_presenter.rb
...presenters/alert_management/prometheus_alert_presenter.rb
+6
-0
changelogs/unreleased/sy-firing-alert-runbook-be.yml
changelogs/unreleased/sy-firing-alert-runbook-be.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+5
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+14
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/types/alert_management/alert_type_spec.rb
spec/graphql/types/alert_management/alert_type_spec.rb
+1
-0
spec/presenters/alert_management/alert_presenter_spec.rb
spec/presenters/alert_management/alert_presenter_spec.rb
+11
-3
spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
...nters/alert_management/prometheus_alert_presenter_spec.rb
+15
-1
spec/requests/api/graphql/project/alert_management/alerts_spec.rb
...uests/api/graphql/project/alert_management/alerts_spec.rb
+4
-3
No files found.
app/graphql/types/alert_management/alert_type.rb
View file @
305ae13d
...
...
@@ -94,8 +94,12 @@ module Types
field
:metrics_dashboard_url
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'URL for metrics embed for the alert'
,
resolve:
->
(
alert
,
_args
,
_context
)
{
alert
.
present
.
metrics_dashboard_url
}
description:
'URL for metrics embed for the alert'
field
:runbook
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Runbook for the alert as defined in alert details'
field
:todos
,
Types
::
TodoType
.
connection_type
,
...
...
app/models/alert_management/alert.rb
View file @
305ae13d
...
...
@@ -118,6 +118,7 @@ module AlertManagement
end
delegate
:iid
,
to: :issue
,
prefix:
true
,
allow_nil:
true
delegate
:metrics_dashboard_url
,
:runbook
,
to: :present
scope
:for_iid
,
->
(
iid
)
{
where
(
iid:
iid
)
}
scope
:for_status
,
->
(
status
)
{
where
(
status:
status
)
}
...
...
app/presenters/alert_management/alert_presenter.rb
View file @
305ae13d
...
...
@@ -37,6 +37,12 @@ module AlertManagement
MARKDOWN
end
def
runbook
strong_memoize
(
:runbook
)
do
payload
&
.
dig
(
'runbook'
)
end
end
def
metrics_dashboard_url
;
end
private
...
...
app/presenters/alert_management/prometheus_alert_presenter.rb
View file @
305ae13d
...
...
@@ -2,6 +2,12 @@
module
AlertManagement
class
PrometheusAlertPresenter
<
AlertManagement
::
AlertPresenter
def
runbook
strong_memoize
(
:runbook
)
do
payload
&
.
dig
(
'annotations'
,
'runbook'
)
end
end
def
metrics_dashboard_url
alerting_alert
.
metrics_dashboard_url
end
...
...
changelogs/unreleased/sy-firing-alert-runbook-be.yml
0 → 100644
View file @
305ae13d
---
title
:
Expose runbook field in alert_management_alert GraphQL API
merge_request
:
38510
author
:
type
:
added
doc/api/graphql/reference/gitlab_schema.graphql
View file @
305ae13d
...
...
@@ -294,6 +294,11 @@ type AlertManagementAlert implements Noteable {
last
:
Int
):
NoteConnection
!
"""
Runbook
for
the
alert
as
defined
in
alert
details
"""
runbook
:
String
"""
Service
the
alert
came
from
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
305ae13d
...
...
@@ -801,6 +801,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "runbook",
"description": "Runbook for the alert as defined in alert details",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "service",
"description": "Service the alert came from",
doc/api/graphql/reference/index.md
View file @
305ae13d
...
...
@@ -71,6 +71,7 @@ Describes an alert from the project's Alert Management
|
`issueIid`
| ID | Internal ID of the GitLab issue attached to the alert |
|
`metricsDashboardUrl`
| String | URL for metrics embed for the alert |
|
`monitoringTool`
| String | Monitoring tool the alert came from |
|
`runbook`
| String | Runbook for the alert as defined in alert details |
|
`service`
| String | Service the alert came from |
|
`severity`
| AlertManagementSeverity | Severity of the alert |
|
`startedAt`
| Time | Timestamp the alert was raised |
...
...
spec/graphql/types/alert_management/alert_type_spec.rb
View file @
305ae13d
...
...
@@ -28,6 +28,7 @@ RSpec.describe GitlabSchema.types['AlertManagementAlert'] do
notes
discussions
metrics_dashboard_url
runbook
todos
]
...
...
spec/presenters/alert_management/alert_presenter_spec.rb
View file @
305ae13d
...
...
@@ -8,11 +8,12 @@ RSpec.describe AlertManagement::AlertPresenter do
{
'title'
=>
'Alert title'
,
'start_time'
=>
'2020-04-27T10:10:22.265949279Z'
,
'custom'
=>
{
'param'
=>
73
}
'custom'
=>
{
'param'
=>
73
},
'runbook'
=>
'https://runbook.com'
}
end
let_it_be
(
:alert
)
do
create
(
:alert_management_alert
,
:with_description
,
:with_host
,
:with_service
,
:with_monitoring_tool
,
project:
project
,
payload:
generic_payload
)
build
(
:alert_management_alert
,
:with_description
,
:with_host
,
:with_service
,
:with_monitoring_tool
,
project:
project
,
payload:
generic_payload
)
end
subject
(
:presenter
)
{
described_class
.
new
(
alert
)
}
...
...
@@ -34,7 +35,8 @@ RSpec.describe AlertManagement::AlertPresenter do
#### Alert Details
**custom.param:** 73
**custom.param:** 73
#{
markdown_line_break
}
**runbook:** https://runbook.com
MARKDOWN
)
end
...
...
@@ -45,4 +47,10 @@ RSpec.describe AlertManagement::AlertPresenter do
expect
(
presenter
.
metrics_dashboard_url
).
to
be_nil
end
end
describe
'#runbook'
do
it
'shows the runbook from the payload'
do
expect
(
presenter
.
runbook
).
to
eq
(
'https://runbook.com'
)
end
end
end
spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
View file @
305ae13d
...
...
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec
.
describe
AlertManagement
::
PrometheusAlertPresenter
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let
_it_be
(
:payload
)
do
let
(
:payload
)
do
{
'annotations'
=>
{
'title'
=>
'Alert title'
,
...
...
@@ -15,6 +15,7 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do
'generatorURL'
=>
'http://8d467bd4607a:9090/graph?g0.expr=vector%281%29&g0.tab=1'
}
end
let
(
:alert
)
do
create
(
:alert_management_alert
,
:prometheus
,
project:
project
,
payload:
payload
)
end
...
...
@@ -65,4 +66,17 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do
it
{
is_expected
.
to
eq
(
dashboard_url_for_alert
)
}
end
end
describe
'#runbook'
do
subject
{
presenter
.
runbook
}
it
{
is_expected
.
to
be_nil
}
context
'with runbook in payload'
do
let
(
:expected_runbook
)
{
'https://awesome-runbook.com'
}
let
(
:payload
)
{
{
'annotations'
=>
{
'runbook'
=>
expected_runbook
}
}
}
it
{
is_expected
.
to
eq
(
expected_runbook
)
}
end
end
end
spec/requests/api/graphql/project/alert_management/alerts_spec.rb
View file @
305ae13d
...
...
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec
.
describe
'getting Alert Management Alerts'
do
include
GraphqlHelpers
let_it_be
(
:payload
)
{
{
'custom'
=>
{
'alert'
=>
'payload'
}
}
}
let_it_be
(
:payload
)
{
{
'custom'
=>
{
'alert'
=>
'payload'
}
,
'runbook'
=>
'runbook'
}
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:resolved_alert
)
{
create
(
:alert_management_alert
,
:all_fields
,
:resolved
,
project:
project
,
issue:
nil
,
severity: :low
)
}
...
...
@@ -71,10 +71,11 @@ RSpec.describe 'getting Alert Management Alerts' do
'eventCount'
=>
triggered_alert
.
events
,
'startedAt'
=>
triggered_alert
.
started_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
),
'endedAt'
=>
nil
,
'details'
=>
{
'custom.alert'
=>
'payload'
},
'details'
=>
{
'custom.alert'
=>
'payload'
,
'runbook'
=>
'runbook'
},
'createdAt'
=>
triggered_alert
.
created_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
),
'updatedAt'
=>
triggered_alert
.
updated_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
),
'metricsDashboardUrl'
=>
nil
'metricsDashboardUrl'
=>
nil
,
'runbook'
=>
'runbook'
)
expect
(
second_alert
).
to
include
(
...
...
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