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
b9e9e998
Commit
b9e9e998
authored
Oct 06, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide Alert's open statuses inside a method
parent
d5c8479f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
7 deletions
+28
-7
app/models/alert_management/alert.rb
app/models/alert_management/alert.rb
+9
-6
app/services/alert_management/alerts/update_service.rb
app/services/alert_management/alerts/update_service.rb
+1
-1
spec/models/alert_management/alert_spec.rb
spec/models/alert_management/alert_spec.rb
+18
-0
No files found.
app/models/alert_management/alert.rb
View file @
b9e9e998
...
...
@@ -21,11 +21,6 @@ module AlertManagement
ignored:
3
}.
freeze
OPEN_STATUSES
=
[
:triggered
,
:acknowledged
].
freeze
belongs_to
:project
belongs_to
:issue
,
optional:
true
belongs_to
:prometheus_alert
,
optional:
true
...
...
@@ -118,7 +113,7 @@ module AlertManagement
scope
:for_fingerprint
,
->
(
project
,
fingerprint
)
{
where
(
project:
project
,
fingerprint:
fingerprint
)
}
scope
:for_environment
,
->
(
environment
)
{
where
(
environment:
environment
)
}
scope
:search
,
->
(
query
)
{
fuzzy_search
(
query
,
[
:title
,
:description
,
:monitoring_tool
,
:service
])
}
scope
:open
,
->
{
with_status
(
OPEN_STATUSES
)
}
scope
:open
,
->
{
with_status
(
open_statuses
)
}
scope
:not_resolved
,
->
{
without_status
(
:resolved
)
}
scope
:with_prometheus_alert
,
->
{
includes
(
:prometheus_alert
)
}
...
...
@@ -183,6 +178,14 @@ module AlertManagement
reference
.
to_i
>
0
&&
reference
.
to_i
<=
Gitlab
::
Database
::
MAX_INT_VALUE
end
def
self
.
open_statuses
[
:triggered
,
:acknowledged
]
end
def
self
.
open_status?
(
status
)
open_statuses
.
include?
(
status
)
end
def
status_event_for
(
status
)
self
.
class
.
state_machines
[
:status
].
events
.
transitions_for
(
self
,
to:
status
.
to_s
.
to_sym
).
first
&
.
event
end
...
...
app/services/alert_management/alerts/update_service.rb
View file @
b9e9e998
...
...
@@ -144,7 +144,7 @@ module AlertManagement
def
filter_duplicate
# Only need to check if changing to an open status
return
unless
params
[
:status_event
]
&&
AlertManagement
::
Alert
::
OPEN_STATUSES
.
include
?
(
status_key
)
return
unless
params
[
:status_event
]
&&
AlertManagement
::
Alert
.
open_status
?
(
status_key
)
param_errors
<<
unresolved_alert_error
if
duplicate_alert?
end
...
...
spec/models/alert_management/alert_spec.rb
View file @
b9e9e998
...
...
@@ -363,6 +363,24 @@ RSpec.describe AlertManagement::Alert do
end
end
describe
'.open_status?'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:status
,
:is_open_status
)
do
:triggered
|
true
:acknowledged
|
true
:resolved
|
false
:ignored
|
false
nil
|
false
end
with_them
do
it
'returns true when the status is open status'
do
expect
(
described_class
.
open_status?
(
status
)).
to
eq
(
is_open_status
)
end
end
end
describe
'#to_reference'
do
it
{
expect
(
triggered_alert
.
to_reference
).
to
eq
(
"^alert#
#{
triggered_alert
.
iid
}
"
)
}
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