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
56f7bd67
Commit
56f7bd67
authored
May 06, 2020
by
Vitali Tatarintev
Committed by
Peter Leitzen
May 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add AlertManagement::Alert#details method
Renders the alert payload as inline hash, and skips alert attributes
parent
d1618331
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
183 additions
and
2 deletions
+183
-2
app/graphql/types/alert_management/alert_type.rb
app/graphql/types/alert_management/alert_type.rb
+25
-0
app/models/alert_management/alert.rb
app/models/alert_management/alert.rb
+6
-0
changelogs/unreleased/expose-more-fields-in-alert-management-alert-graphql.yml
.../expose-more-fields-in-alert-management-alert-graphql.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+25
-0
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+78
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+5
-0
spec/graphql/types/alert_management/alert_type_spec.rb
spec/graphql/types/alert_management/alert_type_spec.rb
+5
-0
spec/models/alert_management/alert_spec.rb
spec/models/alert_management/alert_spec.rb
+26
-0
spec/requests/api/graphql/project/alert_management/alerts_spec.rb
...uests/api/graphql/project/alert_management/alerts_spec.rb
+8
-2
No files found.
app/graphql/types/alert_management/alert_type.rb
View file @
56f7bd67
...
@@ -18,6 +18,11 @@ module Types
...
@@ -18,6 +18,11 @@ module Types
null:
true
,
null:
true
,
description:
'Title of the alert'
description:
'Title of the alert'
field
:description
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
'Description of the alert'
field
:severity
,
field
:severity
,
AlertManagement
::
SeverityEnum
,
AlertManagement
::
SeverityEnum
,
null:
true
,
null:
true
,
...
@@ -38,6 +43,11 @@ module Types
...
@@ -38,6 +43,11 @@ module Types
null:
true
,
null:
true
,
description:
'Monitoring tool the alert came from'
description:
'Monitoring tool the alert came from'
field
:hosts
,
[
GraphQL
::
STRING_TYPE
],
null:
true
,
description:
'List of hosts the alert came from'
field
:started_at
,
field
:started_at
,
Types
::
TimeType
,
Types
::
TimeType
,
null:
true
,
null:
true
,
...
@@ -53,6 +63,21 @@ module Types
...
@@ -53,6 +63,21 @@ module Types
null:
true
,
null:
true
,
description:
'Number of events of this alert'
,
description:
'Number of events of this alert'
,
method: :events
method: :events
field
:details
,
GraphQL
::
Types
::
JSON
,
null:
true
,
description:
'Alert details'
field
:created_at
,
Types
::
TimeType
,
null:
true
,
description:
'Timestamp the alert was created'
field
:updated_at
,
Types
::
TimeType
,
null:
true
,
description:
'Timestamp the alert was last updated'
end
end
end
end
end
end
app/models/alert_management/alert.rb
View file @
56f7bd67
...
@@ -53,6 +53,12 @@ module AlertManagement
...
@@ -53,6 +53,12 @@ module AlertManagement
end
end
end
end
def
details
details_payload
=
payload
.
except
(
*
attributes
.
keys
)
Gitlab
::
Utils
::
InlineHash
.
merge_keys
(
details_payload
)
end
private
private
def
hosts_length
def
hosts_length
...
...
changelogs/unreleased/expose-more-fields-in-alert-management-alert-graphql.yml
0 → 100644
View file @
56f7bd67
---
title
:
Exposes description, hosts, details, and timestamps for Alert Management Alert GraphQL
merge_request
:
31091
author
:
type
:
changed
doc/api/graphql/reference/gitlab_schema.graphql
View file @
56f7bd67
...
@@ -142,6 +142,21 @@ type AdminSidekiqQueuesDeleteJobsPayload {
...
@@ -142,6 +142,21 @@ type AdminSidekiqQueuesDeleteJobsPayload {
Describes an alert from the project's Alert Management
Describes an alert from the project's Alert Management
"""
"""
type
AlertManagementAlert
{
type
AlertManagementAlert
{
"""
Timestamp
the
alert
was
created
"""
createdAt
:
Time
"""
Description
of
the
alert
"""
description
:
String
"""
Alert
details
"""
details
:
JSON
"""
"""
Timestamp
the
alert
ended
Timestamp
the
alert
ended
"""
"""
...
@@ -152,6 +167,11 @@ type AlertManagementAlert {
...
@@ -152,6 +167,11 @@ type AlertManagementAlert {
"""
"""
eventCount
:
Int
eventCount
:
Int
"""
List
of
hosts
the
alert
came
from
"""
hosts
:
[
String
!]
"""
"""
Internal
ID
of
the
alert
Internal
ID
of
the
alert
"""
"""
...
@@ -186,6 +206,11 @@ type AlertManagementAlert {
...
@@ -186,6 +206,11 @@ type AlertManagementAlert {
Title
of
the
alert
Title
of
the
alert
"""
"""
title
:
String
title
:
String
"""
Timestamp
the
alert
was
last
updated
"""
updatedAt
:
Time
}
}
"""
"""
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
56f7bd67
...
@@ -394,6 +394,48 @@
...
@@ -394,6 +394,48 @@
"name"
:
"AlertManagementAlert"
,
"name"
:
"AlertManagementAlert"
,
"description"
:
"Describes an alert from the project's Alert Management"
,
"description"
:
"Describes an alert from the project's Alert Management"
,
"fields"
:
[
"fields"
:
[
{
"name"
:
"createdAt"
,
"description"
:
"Timestamp the alert was created"
,
"args"
:
[
],
"type"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"Time"
,
"ofType"
:
null
},
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
"name"
:
"description"
,
"description"
:
"Description of the alert"
,
"args"
:
[
],
"type"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"String"
,
"ofType"
:
null
},
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
"name"
:
"details"
,
"description"
:
"Alert details"
,
"args"
:
[
],
"type"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"JSON"
,
"ofType"
:
null
},
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
{
"name"
:
"endedAt"
,
"name"
:
"endedAt"
,
"description"
:
"Timestamp the alert ended"
,
"description"
:
"Timestamp the alert ended"
,
...
@@ -422,6 +464,28 @@
...
@@ -422,6 +464,28 @@
"isDeprecated"
:
false
,
"isDeprecated"
:
false
,
"deprecationReason"
:
null
"deprecationReason"
:
null
},
},
{
"name"
:
"hosts"
,
"description"
:
"List of hosts the alert came from"
,
"args"
:
[
],
"type"
:
{
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"String"
,
"ofType"
:
null
}
}
},
"isDeprecated"
:
false
,
"deprecationReason"
:
null
},
{
{
"name"
:
"iid"
,
"name"
:
"iid"
,
"description"
:
"Internal ID of the alert"
,
"description"
:
"Internal ID of the alert"
,
...
@@ -523,6 +587,20 @@
...
@@ -523,6 +587,20 @@
},
},
"isDeprecated"
:
false
,
"isDeprecated"
:
false
,
"deprecationReason"
:
null
"deprecationReason"
:
null
},
{
"name"
:
"updatedAt"
,
"description"
:
"Timestamp the alert was last updated"
,
"args"
:
[
],
"type"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"Time"
,
"ofType"
:
null
},
"isDeprecated"
:
false
,
"deprecationReason"
:
null
}
}
],
],
"inputFields"
:
null
,
"inputFields"
:
null
,
...
...
doc/api/graphql/reference/index.md
View file @
56f7bd67
...
@@ -52,8 +52,12 @@ Describes an alert from the project's Alert Management
...
@@ -52,8 +52,12 @@ Describes an alert from the project's Alert Management
| Name | Type | Description |
| Name | Type | Description |
| --- | ---- | ---------- |
| --- | ---- | ---------- |
|
`createdAt`
| Time | Timestamp the alert was created |
|
`description`
| String | Description of the alert |
|
`details`
| JSON | Alert details |
|
`endedAt`
| Time | Timestamp the alert ended |
|
`endedAt`
| Time | Timestamp the alert ended |
|
`eventCount`
| Int | Number of events of this alert |
|
`eventCount`
| Int | Number of events of this alert |
|
`hosts`
| String! => Array | List of hosts the alert came from |
|
`iid`
| ID! | Internal ID of the alert |
|
`iid`
| ID! | Internal ID of the alert |
|
`monitoringTool`
| String | Monitoring tool the alert came from |
|
`monitoringTool`
| String | Monitoring tool the alert came from |
|
`service`
| String | Service the alert came from |
|
`service`
| String | Service the alert came from |
...
@@ -61,6 +65,7 @@ Describes an alert from the project's Alert Management
...
@@ -61,6 +65,7 @@ Describes an alert from the project's Alert Management
|
`startedAt`
| Time | Timestamp the alert was raised |
|
`startedAt`
| Time | Timestamp the alert was raised |
|
`status`
| AlertManagementStatus | Status of the alert |
|
`status`
| AlertManagementStatus | Status of the alert |
|
`title`
| String | Title of the alert |
|
`title`
| String | Title of the alert |
|
`updatedAt`
| Time | Timestamp the alert was last updated |
## AwardEmoji
## AwardEmoji
...
...
spec/graphql/types/alert_management/alert_type_spec.rb
View file @
56f7bd67
...
@@ -11,13 +11,18 @@ describe GitlabSchema.types['AlertManagementAlert'] do
...
@@ -11,13 +11,18 @@ describe GitlabSchema.types['AlertManagementAlert'] do
expected_fields
=
%i[
expected_fields
=
%i[
iid
iid
title
title
description
severity
severity
status
status
service
service
monitoring_tool
monitoring_tool
hosts
started_at
started_at
ended_at
ended_at
event_count
event_count
details
created_at
updated_at
]
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
...
...
spec/models/alert_management/alert_spec.rb
View file @
56f7bd67
...
@@ -126,4 +126,30 @@ describe AlertManagement::Alert do
...
@@ -126,4 +126,30 @@ describe AlertManagement::Alert do
it
{
is_expected
.
to
match_array
(
alert_1
)
}
it
{
is_expected
.
to
match_array
(
alert_1
)
}
end
end
describe
'.details'
do
let
(
:payload
)
do
{
'title'
=>
'Details title'
,
'custom'
=>
{
'alert'
=>
{
'fields'
=>
%w[one two]
}
},
'yet'
=>
{
'another'
=>
'field'
}
}
end
let
(
:alert
)
{
build
(
:alert_management_alert
,
title:
'Details title'
,
payload:
payload
)
}
subject
{
alert
.
details
}
it
'renders the payload as inline hash'
do
is_expected
.
to
eq
(
'custom.alert.fields'
=>
%w[one two]
,
'yet.another'
=>
'field'
)
end
end
end
end
spec/requests/api/graphql/project/alert_management/alerts_spec.rb
View file @
56f7bd67
...
@@ -4,10 +4,11 @@ require 'spec_helper'
...
@@ -4,10 +4,11 @@ require 'spec_helper'
describe
'getting Alert Management Alerts'
do
describe
'getting Alert Management Alerts'
do
include
GraphqlHelpers
include
GraphqlHelpers
let_it_be
(
:payload
)
{
{
'custom'
=>
{
'alert'
=>
'payload'
}
}
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:alert_1
)
{
create
(
:alert_management_alert
,
:all_fields
,
project:
project
)
}
let_it_be
(
:alert_1
)
{
create
(
:alert_management_alert
,
:all_fields
,
project:
project
)
}
let_it_be
(
:alert_2
)
{
create
(
:alert_management_alert
,
:all_fields
,
project:
project
)
}
let_it_be
(
:alert_2
)
{
create
(
:alert_management_alert
,
:all_fields
,
project:
project
,
payload:
payload
)
}
let
(
:fields
)
do
let
(
:fields
)
do
<<~
QUERY
<<~
QUERY
...
@@ -55,13 +56,18 @@ describe 'getting Alert Management Alerts' do
...
@@ -55,13 +56,18 @@ describe 'getting Alert Management Alerts' do
expect
(
first_alert
).
to
include
(
expect
(
first_alert
).
to
include
(
'iid'
=>
alert_2
.
iid
.
to_s
,
'iid'
=>
alert_2
.
iid
.
to_s
,
'title'
=>
alert_2
.
title
,
'title'
=>
alert_2
.
title
,
'description'
=>
alert_2
.
description
,
'severity'
=>
alert_2
.
severity
.
upcase
,
'severity'
=>
alert_2
.
severity
.
upcase
,
'status'
=>
alert_2
.
status
.
upcase
,
'status'
=>
alert_2
.
status
.
upcase
,
'monitoringTool'
=>
alert_2
.
monitoring_tool
,
'monitoringTool'
=>
alert_2
.
monitoring_tool
,
'service'
=>
alert_2
.
service
,
'service'
=>
alert_2
.
service
,
'hosts'
=>
alert_2
.
hosts
,
'eventCount'
=>
alert_2
.
events
,
'eventCount'
=>
alert_2
.
events
,
'startedAt'
=>
alert_2
.
started_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
),
'startedAt'
=>
alert_2
.
started_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
),
'endedAt'
=>
alert_2
.
ended_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
)
'endedAt'
=>
alert_2
.
ended_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
),
'details'
=>
{
'custom.alert'
=>
'payload'
},
'createdAt'
=>
alert_2
.
created_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
),
'updatedAt'
=>
alert_2
.
updated_at
.
strftime
(
'%Y-%m-%dT%H:%M:%SZ'
)
)
)
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