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 @@
module
Integrations
class
Datadog
<
Integration
DEFAULT_
SITE
=
'datadoghq.com'
URL_TEMPLATE
=
'https://webhooks-http-intake.logs.%{datadog_
site}/v1/input/
'
URL_TEMPLATE_API_KEYS
=
'https://app.%{datadog_
site
}/account/settings#api'
URL_API_KEYS_DOCS
=
"https://docs.
#{
DEFAULT_
SITE
}
/account_management/api-app-keys/"
DEFAULT_
DOMAIN
=
'datadoghq.com'
URL_TEMPLATE
=
'https://webhooks-http-intake.logs.%{datadog_
domain}/api/v2/webhook
'
URL_TEMPLATE_API_KEYS
=
'https://app.%{datadog_
domain
}/account/settings#api'
URL_API_KEYS_DOCS
=
"https://docs.
#{
DEFAULT_
DOMAIN
}
/account_management/api-app-keys/"
SUPPORTED_EVENTS
=
%w[
pipeline job
...
...
@@ -26,7 +26,7 @@ module Integrations
def
initialize_properties
super
self
.
datadog_site
||=
DEFAULT_
SITE
self
.
datadog_site
||=
DEFAULT_
DOMAIN
end
def
self
.
supported_events
...
...
@@ -62,7 +62,7 @@ module Integrations
{
type:
'text'
,
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'
,
required:
false
},
...
...
@@ -105,18 +105,21 @@ module Integrations
end
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
.
path
=
File
.
join
(
url
.
path
||
'/'
,
api_key
)
query
=
{
service:
datadog_service
.
presence
,
env:
datadog_env
.
presence
}.
compact
url
.
query
=
query
.
to_query
unless
query
.
empty?
query
=
{
"dd-api-key"
=>
api_key
,
service:
datadog_service
.
presence
,
env:
datadog_env
.
presence
}.
compact
url
.
query
=
query
.
to_query
url
.
to_s
end
def
api_keys_url
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
def
execute
(
data
)
...
...
@@ -137,5 +140,14 @@ module Integrations
{
success:
true
,
result:
result
[
:message
]
}
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
spec/models/integrations/datadog_spec.rb
View file @
05e7f98c
...
...
@@ -10,13 +10,13 @@ RSpec.describe Integrations::Datadog do
let
(
:active
)
{
true
}
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_key
)
{
SecureRandom
.
hex
(
32
)
}
let
(
:dd_env
)
{
'ci'
}
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
described_class
.
new
(
...
...
@@ -65,7 +65,7 @@ RSpec.describe Integrations::Datadog do
context
'with custom api_url'
do
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
.
to
validate_presence_of
(
:api_url
)
}
...
...
@@ -107,9 +107,9 @@ RSpec.describe Integrations::Datadog do
end
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
let
(
:api_url
)
{
''
}
...
...
@@ -122,7 +122,7 @@ RSpec.describe Integrations::Datadog do
let
(
:dd_service
)
{
''
}
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
...
...
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