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
05e7f98c
Commit
05e7f98c
authored
Jul 13, 2021
by
Adrian Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update datadog webhook URLs for v2 API
parent
58713a68
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
17 deletions
+29
-17
app/models/integrations/datadog.rb
app/models/integrations/datadog.rb
+23
-11
spec/models/integrations/datadog_spec.rb
spec/models/integrations/datadog_spec.rb
+6
-6
No files found.
app/models/integrations/datadog.rb
View file @
05e7f98c
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
module
Integrations
module
Integrations
class
Datadog
<
Integration
class
Datadog
<
Integration
DEFAULT_
SITE
=
'datadoghq.com'
DEFAULT_
DOMAIN
=
'datadoghq.com'
URL_TEMPLATE
=
'https://webhooks-http-intake.logs.%{datadog_
site}/v1/input/
'
URL_TEMPLATE
=
'https://webhooks-http-intake.logs.%{datadog_
domain}/api/v2/webhook
'
URL_TEMPLATE_API_KEYS
=
'https://app.%{datadog_
site
}/account/settings#api'
URL_TEMPLATE_API_KEYS
=
'https://app.%{datadog_
domain
}/account/settings#api'
URL_API_KEYS_DOCS
=
"https://docs.
#{
DEFAULT_
SITE
}
/account_management/api-app-keys/"
URL_API_KEYS_DOCS
=
"https://docs.
#{
DEFAULT_
DOMAIN
}
/account_management/api-app-keys/"
SUPPORTED_EVENTS
=
%w[
SUPPORTED_EVENTS
=
%w[
pipeline job
pipeline job
...
@@ -26,7 +26,7 @@ module Integrations
...
@@ -26,7 +26,7 @@ module Integrations
def
initialize_properties
def
initialize_properties
super
super
self
.
datadog_site
||=
DEFAULT_
SITE
self
.
datadog_site
||=
DEFAULT_
DOMAIN
end
end
def
self
.
supported_events
def
self
.
supported_events
...
@@ -62,7 +62,7 @@ module Integrations
...
@@ -62,7 +62,7 @@ module Integrations
{
{
type:
'text'
,
type:
'text'
,
name:
'datadog_site'
,
name:
'datadog_site'
,
placeholder:
DEFAULT_
SITE
,
placeholder:
DEFAULT_
DOMAIN
,
help:
'Choose the Datadog site to send data to. Set to "datadoghq.eu" to send data to the EU site'
,
help:
'Choose the Datadog site to send data to. Set to "datadoghq.eu" to send data to the EU site'
,
required:
false
required:
false
},
},
...
@@ -105,18 +105,21 @@ module Integrations
...
@@ -105,18 +105,21 @@ module Integrations
end
end
def
hook_url
def
hook_url
url
=
api_url
.
presence
||
sprintf
(
URL_TEMPLATE
,
datadog_
site:
datadog_site
)
url
=
api_url
.
presence
||
sprintf
(
URL_TEMPLATE
,
datadog_
domain:
datadog_domain
)
url
=
URI
.
parse
(
url
)
url
=
URI
.
parse
(
url
)
url
.
path
=
File
.
join
(
url
.
path
||
'/'
,
api_key
)
query
=
{
query
=
{
service:
datadog_service
.
presence
,
env:
datadog_env
.
presence
}.
compact
"dd-api-key"
=>
api_key
,
url
.
query
=
query
.
to_query
unless
query
.
empty?
service:
datadog_service
.
presence
,
env:
datadog_env
.
presence
}.
compact
url
.
query
=
query
.
to_query
url
.
to_s
url
.
to_s
end
end
def
api_keys_url
def
api_keys_url
return
URL_API_KEYS_DOCS
unless
datadog_site
.
presence
return
URL_API_KEYS_DOCS
unless
datadog_site
.
presence
sprintf
(
URL_TEMPLATE_API_KEYS
,
datadog_
site:
datadog_site
)
sprintf
(
URL_TEMPLATE_API_KEYS
,
datadog_
domain:
datadog_domain
)
end
end
def
execute
(
data
)
def
execute
(
data
)
...
@@ -137,5 +140,14 @@ module Integrations
...
@@ -137,5 +140,14 @@ module Integrations
{
success:
true
,
result:
result
[
:message
]
}
{
success:
true
,
result:
result
[
:message
]
}
end
end
private
def
datadog_domain
# Transparently ignore "app" prefix from datadog_site as the official docs table in
# https://docs.datadoghq.com/getting_started/site/ is confusing for internal URLs.
# US3 needs to keep a prefix but other datacenters cannot have the listed "app" prefix
datadog_site
.
delete_prefix
(
"app."
)
end
end
end
end
end
spec/models/integrations/datadog_spec.rb
View file @
05e7f98c
...
@@ -10,13 +10,13 @@ RSpec.describe Integrations::Datadog do
...
@@ -10,13 +10,13 @@ RSpec.describe Integrations::Datadog do
let
(
:active
)
{
true
}
let
(
:active
)
{
true
}
let
(
:dd_site
)
{
'datadoghq.com'
}
let
(
:dd_site
)
{
'datadoghq.com'
}
let
(
:default_url
)
{
'https://webhooks-http-intake.logs.datadoghq.com/
v1/input/
'
}
let
(
:default_url
)
{
'https://webhooks-http-intake.logs.datadoghq.com/
api/v2/webhook
'
}
let
(
:api_url
)
{
''
}
let
(
:api_url
)
{
''
}
let
(
:api_key
)
{
SecureRandom
.
hex
(
32
)
}
let
(
:api_key
)
{
SecureRandom
.
hex
(
32
)
}
let
(
:dd_env
)
{
'ci'
}
let
(
:dd_env
)
{
'ci'
}
let
(
:dd_service
)
{
'awesome-gitlab'
}
let
(
:dd_service
)
{
'awesome-gitlab'
}
let
(
:expected_hook_url
)
{
default_url
+
api_key
+
"?
env=
#{
dd_env
}
&service=
#{
dd_service
}
"
}
let
(
:expected_hook_url
)
{
default_url
+
"?dd-api-key=
#{
api_key
}
&
env=
#{
dd_env
}
&service=
#{
dd_service
}
"
}
let
(
:instance
)
do
let
(
:instance
)
do
described_class
.
new
(
described_class
.
new
(
...
@@ -65,7 +65,7 @@ RSpec.describe Integrations::Datadog do
...
@@ -65,7 +65,7 @@ RSpec.describe Integrations::Datadog do
context
'with custom api_url'
do
context
'with custom api_url'
do
let
(
:dd_site
)
{
''
}
let
(
:dd_site
)
{
''
}
let
(
:api_url
)
{
'https://webhooks-http-intake.logs.datad0g.com/
v1/input/
'
}
let
(
:api_url
)
{
'https://webhooks-http-intake.logs.datad0g.com/
api/v2/webhook
'
}
it
{
is_expected
.
not_to
validate_presence_of
(
:datadog_site
)
}
it
{
is_expected
.
not_to
validate_presence_of
(
:datadog_site
)
}
it
{
is_expected
.
to
validate_presence_of
(
:api_url
)
}
it
{
is_expected
.
to
validate_presence_of
(
:api_url
)
}
...
@@ -107,9 +107,9 @@ RSpec.describe Integrations::Datadog do
...
@@ -107,9 +107,9 @@ RSpec.describe Integrations::Datadog do
end
end
context
'with custom URL'
do
context
'with custom URL'
do
let
(
:api_url
)
{
'https://webhooks-http-intake.logs.datad0g.com/
v1/input/
'
}
let
(
:api_url
)
{
'https://webhooks-http-intake.logs.datad0g.com/
api/v2/webhook
'
}
it
{
is_expected
.
to
eq
(
api_url
+
api_key
+
"?
env=
#{
dd_env
}
&service=
#{
dd_service
}
"
)
}
it
{
is_expected
.
to
eq
(
api_url
+
"?dd-api-key=
#{
api_key
}
&
env=
#{
dd_env
}
&service=
#{
dd_service
}
"
)
}
context
'blank'
do
context
'blank'
do
let
(
:api_url
)
{
''
}
let
(
:api_url
)
{
''
}
...
@@ -122,7 +122,7 @@ RSpec.describe Integrations::Datadog do
...
@@ -122,7 +122,7 @@ RSpec.describe Integrations::Datadog do
let
(
:dd_service
)
{
''
}
let
(
:dd_service
)
{
''
}
let
(
:dd_env
)
{
''
}
let
(
:dd_env
)
{
''
}
it
{
is_expected
.
to
eq
(
default_url
+
api_key
)
}
it
{
is_expected
.
to
eq
(
default_url
+
"?dd-api-key=
#{
api_key
}
"
)
}
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