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
f0bce4cb
Commit
f0bce4cb
authored
May 13, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add alert management alert search
- Scope & specs - Finder & specs
parent
08d5d350
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
4 deletions
+85
-4
app/finders/alert_management/alerts_finder.rb
app/finders/alert_management/alerts_finder.rb
+5
-0
app/models/alert_management/alert.rb
app/models/alert_management/alert.rb
+2
-0
spec/factories/alert_management/alerts.rb
spec/factories/alert_management/alerts.rb
+5
-0
spec/finders/alert_management/alerts_finder_spec.rb
spec/finders/alert_management/alerts_finder_spec.rb
+35
-3
spec/models/alert_management/alert_spec.rb
spec/models/alert_management/alert_spec.rb
+38
-1
No files found.
app/finders/alert_management/alerts_finder.rb
View file @
f0bce4cb
...
...
@@ -13,6 +13,7 @@ module AlertManagement
collection
=
project
.
alert_management_alerts
collection
=
by_status
(
collection
)
collection
=
by_search
(
collection
)
collection
=
by_iid
(
collection
)
sort
(
collection
)
end
...
...
@@ -33,6 +34,10 @@ module AlertManagement
values
.
present?
?
collection
.
for_status
(
values
)
:
collection
end
def
by_search
(
collection
)
params
[
:search
]
?
collection
.
search
(
params
[
:search
])
:
collection
end
def
sort
(
collection
)
params
[
:sort
]
?
collection
.
sort_by_attribute
(
params
[
:sort
])
:
collection
end
...
...
app/models/alert_management/alert.rb
View file @
f0bce4cb
...
...
@@ -5,6 +5,7 @@ module AlertManagement
include
AtomicInternalId
include
ShaAttribute
include
Sortable
include
Gitlab
::
SQL
::
Pattern
STATUSES
=
{
triggered:
0
,
...
...
@@ -97,6 +98,7 @@ module AlertManagement
scope
:for_iid
,
->
(
iid
)
{
where
(
iid:
iid
)
}
scope
:for_status
,
->
(
status
)
{
where
(
status:
status
)
}
scope
:for_fingerprint
,
->
(
project
,
fingerprint
)
{
where
(
project:
project
,
fingerprint:
fingerprint
)
}
scope
:search
,
->
(
query
)
{
fuzzy_search
(
query
,
[
:title
,
:description
,
:monitoring_tool
,
:service
])
}
scope
:order_start_time
,
->
(
sort_order
)
{
order
(
started_at:
sort_order
)
}
scope
:order_end_time
,
->
(
sort_order
)
{
order
(
ended_at:
sort_order
)
}
...
...
spec/factories/alert_management/alerts.rb
View file @
f0bce4cb
...
...
@@ -24,6 +24,10 @@ FactoryBot.define do
monitoring_tool
{
FFaker
::
AWS
.
product_description
}
end
trait
:with_description
do
description
{
FFaker
::
Lorem
.
sentence
}
end
trait
:with_host
do
hosts
{
[
FFaker
::
Internet
.
ip_v4_address
]
}
end
...
...
@@ -66,6 +70,7 @@ FactoryBot.define do
with_service
with_monitoring_tool
with_host
with_description
low_severity
end
end
...
...
spec/finders/alert_management/alerts_finder_spec.rb
View file @
f0bce4cb
...
...
@@ -5,9 +5,9 @@ require 'spec_helper'
describe
AlertManagement
::
AlertsFinder
,
'#execute'
do
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:alert_1
)
{
create
(
:alert_management_alert
,
:resolved
,
project:
project
,
ended_at:
1
.
year
.
ago
,
events:
2
,
severity: :high
)
}
let_it_be
(
:alert_2
)
{
create
(
:alert_management_alert
,
:ignored
,
project:
project
,
events:
1
,
severity: :critical
)
}
let_it_be
(
:alert_3
)
{
create
(
:alert_management_alert
)
}
let_it_be
(
:alert_1
)
{
create
(
:alert_management_alert
,
:
all_fields
,
:
resolved
,
project:
project
,
ended_at:
1
.
year
.
ago
,
events:
2
,
severity: :high
)
}
let_it_be
(
:alert_2
)
{
create
(
:alert_management_alert
,
:
all_fields
,
:
ignored
,
project:
project
,
events:
1
,
severity: :critical
)
}
let_it_be
(
:alert_3
)
{
create
(
:alert_management_alert
,
:all_fields
)
}
let
(
:params
)
{
{}
}
subject
{
described_class
.
new
(
current_user
,
project
,
params
).
execute
}
...
...
@@ -222,5 +222,37 @@ describe AlertManagement::AlertsFinder, '#execute' do
end
end
end
context
'search query given'
do
context
'searching title'
do
let
(
:params
)
{
{
search:
alert_1
.
title
}
}
it
{
is_expected
.
to
match_array
([
alert_1
])
}
end
context
'searching description'
do
let
(
:params
)
{
{
search:
alert_1
.
description
}
}
it
{
is_expected
.
to
match_array
([
alert_1
])
}
end
context
'searching service'
do
let
(
:params
)
{
{
search:
alert_1
.
service
}
}
it
{
is_expected
.
to
match_array
([
alert_1
])
}
end
context
'searching monitoring tool'
do
let
(
:params
)
{
{
search:
alert_1
.
monitoring_tool
}
}
it
{
is_expected
.
to
match_array
([
alert_1
])
}
end
context
'searching something else'
do
let
(
:params
)
{
{
search:
alert_1
.
fingerprint
}
}
it
{
is_expected
.
to
be_empty
}
end
end
end
end
spec/models/alert_management/alert_spec.rb
View file @
f0bce4cb
...
...
@@ -162,7 +162,44 @@ describe AlertManagement::Alert do
it
{
is_expected
.
to
contain_exactly
(
alert_1
)
}
end
describe
'.details'
do
describe
'.search'
do
let
(
:query
)
{
'rspec'
}
let
(
:attribute_data
)
{
'RSPEC data'
}
subject
{
AlertManagement
::
Alert
.
search
(
query
)
}
context
'does not contain search string'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
)
}
it
{
is_expected
.
to
be_empty
}
end
context
'title includes query'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
title:
attribute_data
)
}
it
{
is_expected
.
to
contain_exactly
(
alert
)
}
end
context
'description includes query'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
description:
attribute_data
)
}
it
{
is_expected
.
to
contain_exactly
(
alert
)
}
end
context
'service includes query'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
service:
attribute_data
)
}
it
{
is_expected
.
to
contain_exactly
(
alert
)
}
end
context
'monitoring tool includes query'
do
let!
(
:alert
)
{
create
(
:alert_management_alert
,
monitoring_tool:
attribute_data
)
}
it
{
is_expected
.
to
contain_exactly
(
alert
)
}
end
end
describe
'#details'
do
let
(
:payload
)
do
{
'title'
=>
'Details title'
,
...
...
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