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
272e47d5
Commit
272e47d5
authored
Oct 06, 2020
by
Vitali Tatarintev
Committed by
Peter Leitzen
Oct 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of AlertManagement::Alert::STATUS_EVENTS constant
parent
dce382cc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
9 deletions
+61
-9
app/models/alert_management/alert.rb
app/models/alert_management/alert.rb
+9
-7
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
+51
-1
No files found.
app/models/alert_management/alert.rb
View file @
272e47d5
...
...
@@ -21,13 +21,6 @@ module AlertManagement
ignored:
3
}.
freeze
STATUS_EVENTS
=
{
triggered: :trigger
,
acknowledged: :acknowledge
,
resolved: :resolve
,
ignored: :ignore
}.
freeze
OPEN_STATUSES
=
[
:triggered
,
:acknowledged
...
...
@@ -190,6 +183,15 @@ module AlertManagement
reference
.
to_i
>
0
&&
reference
.
to_i
<=
Gitlab
::
Database
::
MAX_INT_VALUE
end
def
status_event_for
(
status
)
self
.
class
.
state_machines
[
:status
].
events
.
transitions_for
(
self
,
to:
status
.
to_s
.
to_sym
).
first
&
.
event
end
def
change_status_to
(
new_status
)
event
=
status_event_for
(
new_status
)
event
&&
fire_status_event
(
event
)
end
def
prometheus?
monitoring_tool
==
Gitlab
::
AlertManagement
::
Payload
::
MONITORING_TOOLS
[
:prometheus
]
end
...
...
app/services/alert_management/alerts/update_service.rb
View file @
272e47d5
...
...
@@ -112,7 +112,7 @@ module AlertManagement
def
filter_status
return
unless
params
[
:status
]
status_event
=
AlertManagement
::
Alert
::
STATUS_EVENTS
[
status_key
]
status_event
=
alert
.
status_event_for
(
status_key
)
unless
status_event
param_errors
<<
_
(
'Invalid status'
)
...
...
spec/models/alert_management/alert_spec.rb
View file @
272e47d5
...
...
@@ -133,7 +133,7 @@ RSpec.describe AlertManagement::Alert do
let
(
:new_alert
)
{
build
(
:alert_management_alert
,
new_status
,
fingerprint:
fingerprint
,
project:
project
)
}
before
do
existing_alert
.
public_send
(
described_class
::
STATUS_EVENTS
[
existing_status
]
)
existing_alert
.
change_status_to
(
existing_status
)
end
if
params
[
:valid
]
...
...
@@ -453,4 +453,54 @@ RSpec.describe AlertManagement::Alert do
expect
{
subject
}.
to
change
{
alert
.
events
}.
by
(
1
)
end
end
describe
'#status_event_for'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:for_status
,
:event
)
do
:triggered
|
:trigger
'triggered'
|
:trigger
:acknowledged
|
:acknowledge
'acknowledged'
|
:acknowledge
:resolved
|
:resolve
'resolved'
|
:resolve
:ignored
|
:ignore
'ignored'
|
:ignore
:unknown
|
nil
nil
|
nil
''
|
nil
1
|
nil
end
with_them
do
let
(
:alert
)
{
build
(
:alert_management_alert
,
project:
project
)
}
it
'returns event by status name'
do
expect
(
alert
.
status_event_for
(
for_status
)).
to
eq
(
event
)
end
end
end
describe
'#change_status_to'
do
let_it_be_with_reload
(
:alert
)
{
create
(
:alert_management_alert
,
project:
project
)
}
context
'with valid statuses'
do
it
'changes the status to triggered'
do
alert
.
acknowledge!
# change to non-triggered status
expect
{
alert
.
change_status_to
(
:triggered
)
}.
to
change
{
alert
.
triggered?
}.
to
(
true
)
end
%i(acknowledged resolved ignored)
.
each
do
|
status
|
it
"changes the status to
#{
status
}
"
do
expect
{
alert
.
change_status_to
(
status
)
}.
to
change
{
alert
.
public_send
(
:"
#{
status
}
?"
)
}.
to
(
true
)
end
end
end
context
'with invalid status'
do
it
'does not change the current status'
do
expect
{
alert
.
change_status_to
(
nil
)
}.
not_to
change
{
alert
.
status
}
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