Class: Integrations::Datadog
Constant Summary
collapse
- DEFAULT_DOMAIN =
'datadoghq.com'
- URL_TEMPLATE =
'https://webhook-intake.%{datadog_domain}/api/v2/webhook'
- URL_API_KEYS_DOCS =
"https://docs.#{DEFAULT_DOMAIN}/account_management/api-app-keys/"
- CI_LOGS_DOCS =
"https://docs.#{DEFAULT_DOMAIN}/continuous_integration/pipelines/gitlab/?tab=gitlabcom#collect-job-logs"
- CI_VISIBILITY_PRICING =
"https://www.#{DEFAULT_DOMAIN}/pricing/?product=ci-pipeline-visibility#products"
- SITES_DOCS =
"https://docs.#{DEFAULT_DOMAIN}/getting_started/site/"
- SUPPORTED_EVENTS =
%w[
pipeline build archive_trace push merge_request note tag_push subgroup project
].freeze
- TAG_KEY_VALUE_RE =
%r{\A [\w-]+ : .*\S.* \z}x
Base::Integration::BASE_ATTRIBUTES, Base::Integration::BASE_CLASSES, Base::Integration::DEV_INTEGRATION_NAMES, Base::Integration::ENCRYPTED_PROPERTIES_MAX_SIZE, Base::Integration::INSTANCE_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::INTEGRATION_NAMES, Base::Integration::PROJECT_AND_GROUP_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::PROJECT_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::SECTION_TYPE_CONFIGURATION, Base::Integration::SECTION_TYPE_CONNECTION, Base::Integration::SECTION_TYPE_TRIGGER, Base::Integration::SNOWPLOW_EVENT_ACTION, Base::Integration::SNOWPLOW_EVENT_LABEL, Base::Integration::UnknownType
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from HasAvatar
#avatar_url
Methods included from HasWebHook
#execute_web_hook!, #hook_ssl_verification, #update_web_hook!
#activate!, #activate_disabled_reason, #activated?, #after_build_from_integration, #api_field_names, #async_execute, #attributes, #attribution_notice, #category, #chat?, #ci?, #deactivate!, #default_test_event, #description, #dup, #editable?, #event_channel_names, #event_names, #fields, #form_fields, #group_level?, #help, #inheritable?, #instance_level?, #json_fields, #manual_activation?, #operating?, #organization_id_from_parent, #parent, #project_level?, #reencrypt_properties, #reset_updated_properties, #secret_fields, #supported_events, #supports_data_fields?, #testable?, #title, #to_database_hash, #to_param, #toggle!, #updated_properties, #validate_encrypted_properties_size_limit
#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#sharding_organization
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.default_test_event ⇒ Object
179
180
181
|
# File 'app/models/integrations/datadog.rb', line 179
def self.default_test_event
'push'
end
|
.description ⇒ Object
192
193
194
|
# File 'app/models/integrations/datadog.rb', line 192
def self.description
s_('DatadogIntegration|Connect your projects to Datadog and trace your GitLab pipelines.')
end
|
.help ⇒ Object
196
197
198
199
200
201
202
|
# File 'app/models/integrations/datadog.rb', line 196
def self.help
build_help_page_url(
'integration/datadog.md',
s_('DatadogIntegration|Connect your GitLab projects to your Datadog account to synchronize repository metadata and enrich telemetry on your Datadog account.'),
link_text: _('How do I set up this integration?')
)
end
|
.supported_events ⇒ Object
175
176
177
|
# File 'app/models/integrations/datadog.rb', line 175
def self.supported_events
SUPPORTED_EVENTS
end
|
.title ⇒ Object
188
189
190
|
# File 'app/models/integrations/datadog.rb', line 188
def self.title
'Datadog'
end
|
.to_param ⇒ Object
204
205
206
|
# File 'app/models/integrations/datadog.rb', line 204
def self.to_param
'datadog'
end
|
Instance Method Details
#configurable_events ⇒ Object
183
184
185
186
|
# File 'app/models/integrations/datadog.rb', line 183
def configurable_events
[] end
|
#execute(data) ⇒ Object
226
227
228
229
230
231
232
233
|
# File 'app/models/integrations/datadog.rb', line 226
def execute(data)
return unless supported_events.include?(data[:object_kind])
object_kind = data[:object_kind]
object_kind = 'job' if object_kind == 'build'
data = hook_data(data, object_kind)
execute_web_hook!(data, "#{object_kind} hook")
end
|
#hook_url ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'app/models/integrations/datadog.rb', line 209
def hook_url
url = api_url.presence || sprintf(URL_TEMPLATE, datadog_domain: datadog_domain)
url = URI.parse(url)
query = {
"dd-api-key" => 'THIS_VALUE_WILL_BE_REPLACED',
service: datadog_service.presence,
env: datadog_env.presence,
tags: datadog_tags_query_param.presence
}.compact
url.query = query.to_query
url.to_s.gsub('THIS_VALUE_WILL_BE_REPLACED', '{api_key}')
end
|
#initialize_properties ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'app/models/integrations/datadog.rb', line 150
def initialize_properties
super
self.datadog_site ||= DEFAULT_DOMAIN
if datadog_ci_visibility.nil?
self.datadog_ci_visibility = active
end
end
|
#sections ⇒ Object
The config is divided in two sections:
-
General account configuration, which allows setting up a Datadog site and API key
-
CI Visibility configuration, which is specific to job & pipeline events
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/models/integrations/datadog.rb', line 24
def sections
[
{
type: SECTION_TYPE_CONNECTION,
title: s_('DatadogIntegration|Datadog account'),
description: help
},
{
type: SECTION_TYPE_CONFIGURATION,
title: s_('DatadogIntegration|CI Visibility'),
description: s_('DatadogIntegration|Additionally, enable CI Visibility to send pipeline information to Datadog to monitor for job failures and troubleshoot performance issues.')
}
]
end
|
#test(data) ⇒ Object
235
236
237
238
239
240
241
242
|
# File 'app/models/integrations/datadog.rb', line 235
def test(data)
result = execute(data)
{
success: (200..299).cover?(result.payload[:http_status]),
result: result.message
}
end
|
#update_pipeline_events ⇒ Object
167
168
169
170
171
172
173
|
# File 'app/models/integrations/datadog.rb', line 167
def update_pipeline_events
unless datadog_ci_visibility.nil?
self.job_events = datadog_ci_visibility
self.pipeline_events = datadog_ci_visibility
end
end
|
#url_variables ⇒ Object
222
223
224
|
# File 'app/models/integrations/datadog.rb', line 222
def url_variables
{ 'api_key' => api_key }
end
|