diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /app/models/integrations/datadog.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'app/models/integrations/datadog.rb')
-rw-r--r-- | app/models/integrations/datadog.rb | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/app/models/integrations/datadog.rb b/app/models/integrations/datadog.rb index dd4b0664d52..27c2fcf266b 100644 --- a/app/models/integrations/datadog.rb +++ b/app/models/integrations/datadog.rb @@ -2,10 +2,13 @@ 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/" + include HasWebHook + extend Gitlab::Utils::Override + + 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 @@ -21,12 +24,10 @@ module Integrations validates :api_url, presence: true, unless: -> (obj) { obj.datadog_site.present? } end - after_save :compose_service_hook, if: :activated? - def initialize_properties super - self.datadog_site ||= DEFAULT_SITE + self.datadog_site ||= DEFAULT_DOMAIN end def self.supported_events @@ -62,7 +63,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 }, @@ -98,35 +99,31 @@ module Integrations ] end - def compose_service_hook - hook = service_hook || build_service_hook - hook.url = hook_url - hook.save - end - + override :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.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) - return if project.disabled_services.include?(to_param) - object_kind = data[:object_kind] object_kind = 'job' if object_kind == 'build' return unless supported_events.include?(object_kind) - service_hook.execute(data, "#{object_kind} hook") + execute_web_hook!(data, "#{object_kind} hook") end def test(data) @@ -139,5 +136,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 |