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
6b3a2158
Commit
6b3a2158
authored
Aug 26, 2020
by
Sarah Yasonik
Committed by
Peter Leitzen
Aug 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support environment for generic alerts in new alert payload class
parent
3d77af80
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
26 deletions
+57
-26
lib/gitlab/alert_management/payload/base.rb
lib/gitlab/alert_management/payload/base.rb
+14
-1
lib/gitlab/alert_management/payload/generic.rb
lib/gitlab/alert_management/payload/generic.rb
+1
-0
lib/gitlab/alert_management/payload/prometheus.rb
lib/gitlab/alert_management/payload/prometheus.rb
+0
-8
spec/lib/gitlab/alert_management/payload/base_spec.rb
spec/lib/gitlab/alert_management/payload/base_spec.rb
+36
-17
spec/lib/gitlab/alert_management/payload/generic_spec.rb
spec/lib/gitlab/alert_management/payload/generic_spec.rb
+6
-0
No files found.
lib/gitlab/alert_management/payload/base.rb
View file @
6b3a2158
...
@@ -104,7 +104,20 @@ module Gitlab
...
@@ -104,7 +104,20 @@ module Gitlab
def
gitlab_fingerprint
def
gitlab_fingerprint
strong_memoize
(
:gitlab_fingerprint
)
do
strong_memoize
(
:gitlab_fingerprint
)
do
Gitlab
::
AlertManagement
::
Fingerprint
.
generate
(
plain_gitlab_fingerprint
)
if
plain_gitlab_fingerprint
next
unless
plain_gitlab_fingerprint
Gitlab
::
AlertManagement
::
Fingerprint
.
generate
(
plain_gitlab_fingerprint
)
end
end
def
environment
strong_memoize
(
:environment
)
do
next
unless
environment_name
EnvironmentsFinder
.
new
(
project
,
nil
,
{
name:
environment_name
})
.
find
.
first
end
end
end
end
...
...
lib/gitlab/alert_management/payload/generic.rb
View file @
6b3a2158
...
@@ -8,6 +8,7 @@ module Gitlab
...
@@ -8,6 +8,7 @@ module Gitlab
DEFAULT_TITLE
=
'New: Incident'
DEFAULT_TITLE
=
'New: Incident'
DEFAULT_SEVERITY
=
'critical'
DEFAULT_SEVERITY
=
'critical'
attribute
:environment_name
,
paths:
'gitlab_environment_name'
attribute
:hosts
,
paths:
'hosts'
attribute
:hosts
,
paths:
'hosts'
attribute
:monitoring_tool
,
paths:
'monitoring_tool'
attribute
:monitoring_tool
,
paths:
'monitoring_tool'
attribute
:runbook
,
paths:
'runbook'
attribute
:runbook
,
paths:
'runbook'
...
...
lib/gitlab/alert_management/payload/prometheus.rb
View file @
6b3a2158
...
@@ -49,14 +49,6 @@ module Gitlab
...
@@ -49,14 +49,6 @@ module Gitlab
rescue
URI
::
InvalidURIError
,
KeyError
rescue
URI
::
InvalidURIError
,
KeyError
end
end
def
environment
return
unless
environment_name
EnvironmentsFinder
.
new
(
project
,
nil
,
{
name:
environment_name
})
.
find
&
.
first
end
def
metrics_dashboard_url
def
metrics_dashboard_url
return
unless
environment
&&
full_query
&&
title
return
unless
environment
&&
full_query
&&
title
...
...
spec/lib/gitlab/alert_management/payload/base_spec.rb
View file @
6b3a2158
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Gitlab
::
AlertManagement
::
Payload
::
Base
do
RSpec
.
describe
Gitlab
::
AlertManagement
::
Payload
::
Base
do
let_it_be
(
:project
)
{
build_stubbed
(
:project
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let
(
:raw_payload
)
{
{}
}
let
(
:raw_payload
)
{
{}
}
let
(
:payload_class
)
{
described_class
}
let
(
:payload_class
)
{
described_class
}
...
@@ -120,16 +120,9 @@ RSpec.describe Gitlab::AlertManagement::Payload::Base do
...
@@ -120,16 +120,9 @@ RSpec.describe Gitlab::AlertManagement::Payload::Base do
end
end
describe
'#alert_params'
do
describe
'#alert_params'
do
let
(
:payload_class
)
do
before
do
Class
.
new
(
described_class
)
do
allow
(
parsed_payload
).
to
receive
(
:title
).
and_return
(
'title'
)
def
title
allow
(
parsed_payload
).
to
receive
(
:description
).
and_return
(
'description'
)
'title'
end
def
description
'description'
end
end
end
end
subject
{
parsed_payload
.
alert_params
}
subject
{
parsed_payload
.
alert_params
}
...
@@ -143,12 +136,10 @@ RSpec.describe Gitlab::AlertManagement::Payload::Base do
...
@@ -143,12 +136,10 @@ RSpec.describe Gitlab::AlertManagement::Payload::Base do
it
{
is_expected
.
to
be_nil
}
it
{
is_expected
.
to
be_nil
}
context
'when plain_gitlab_fingerprint is defined'
do
context
'when plain_gitlab_fingerprint is defined'
do
let
(
:payload_class
)
do
before
do
Class
.
new
(
described_class
)
do
allow
(
parsed_payload
)
def
plain_gitlab_fingerprint
.
to
receive
(
:plain_gitlab_fingerprint
)
'fingerprint'
.
and_return
(
'fingerprint'
)
end
end
end
end
it
'returns a fingerprint'
do
it
'returns a fingerprint'
do
...
@@ -156,4 +147,32 @@ RSpec.describe Gitlab::AlertManagement::Payload::Base do
...
@@ -156,4 +147,32 @@ RSpec.describe Gitlab::AlertManagement::Payload::Base do
end
end
end
end
end
end
describe
'#environment'
do
let_it_be
(
:environment
)
{
create
(
:environment
,
project:
project
,
name:
'production'
)
}
subject
{
parsed_payload
.
environment
}
before
do
allow
(
parsed_payload
).
to
receive
(
:environment_name
).
and_return
(
environment_name
)
end
context
'without an environment name'
do
let
(
:environment_name
)
{
nil
}
it
{
is_expected
.
to
be_nil
}
end
context
'with a non-matching environment name'
do
let
(
:environment_name
)
{
'other_environment'
}
it
{
is_expected
.
to
be_nil
}
end
context
'with a matching environment name'
do
let
(
:environment_name
)
{
'production'
}
it
{
is_expected
.
to
eq
(
environment
)
}
end
end
end
end
spec/lib/gitlab/alert_management/payload/generic_spec.rb
View file @
6b3a2158
...
@@ -80,4 +80,10 @@ RSpec.describe Gitlab::AlertManagement::Payload::Generic do
...
@@ -80,4 +80,10 @@ RSpec.describe Gitlab::AlertManagement::Payload::Generic do
is_expected
.
to
eq
(
Digest
::
SHA1
.
hexdigest
(
plain_fingerprint
))
is_expected
.
to
eq
(
Digest
::
SHA1
.
hexdigest
(
plain_fingerprint
))
end
end
end
end
describe
'#environment_name'
do
subject
{
parsed_payload
.
environment_name
}
it_behaves_like
'parsable alert payload field'
,
'gitlab_environment_name'
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