datadog-ci 1.42.0 → 1.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -2
- data/README.md +45 -0
- data/lib/datadog/ci/async_writer.rb +1 -4
- data/lib/datadog/ci/concurrent_span.rb +20 -0
- data/lib/datadog/ci/configuration/settings.rb +3 -2
- data/lib/datadog/ci/contrib/cucumber/formatter.rb +27 -8
- data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +11 -3
- data/lib/datadog/ci/contrib/cuprite/driver.rb +5 -5
- data/lib/datadog/ci/contrib/knapsack/runner.rb +1 -1
- data/lib/datadog/ci/contrib/minitest/helpers.rb +59 -0
- data/lib/datadog/ci/contrib/minitest/reporter.rb +2 -2
- data/lib/datadog/ci/contrib/minitest/test.rb +4 -1
- data/lib/datadog/ci/contrib/rspec/example.rb +12 -2
- data/lib/datadog/ci/contrib/rspec/example_group.rb +3 -2
- data/lib/datadog/ci/contrib/rspec/runner.rb +2 -2
- data/lib/datadog/ci/contrib/selenium/navigation.rb +5 -5
- data/lib/datadog/ci/ext/metadata.rb +168 -0
- data/lib/datadog/ci/ext/settings.rb +1 -0
- data/lib/datadog/ci/ext/test.rb +11 -0
- data/lib/datadog/ci/impacted_tests_detection/component.rb +1 -1
- data/lib/datadog/ci/readonly_test_module.rb +16 -0
- data/lib/datadog/ci/readonly_test_session.rb +16 -0
- data/lib/datadog/ci/remote/library_settings_client.rb +1 -1
- data/lib/datadog/ci/remote/slow_test_retries.rb +3 -2
- data/lib/datadog/ci/span.rb +46 -10
- data/lib/datadog/ci/test.rb +75 -18
- data/lib/datadog/ci/test_impact_analysis/component.rb +11 -11
- data/lib/datadog/ci/test_impact_analysis/skippable.rb +1 -1
- data/lib/datadog/ci/test_management/component.rb +4 -4
- data/lib/datadog/ci/test_management/tests_properties.rb +1 -1
- data/lib/datadog/ci/test_retries/component.rb +34 -18
- data/lib/datadog/ci/test_retries/driver/base.rb +2 -2
- data/lib/datadog/ci/test_retries/driver/retry_flake_detection.rb +12 -4
- data/lib/datadog/ci/test_retries/strategy/retry_flake_detection.rb +2 -2
- data/lib/datadog/ci/test_retries/strategy/retry_flaky_fixed.rb +6 -3
- data/lib/datadog/ci/test_tracing/component.rb +17 -7
- data/lib/datadog/ci/test_tracing/context.rb +24 -7
- data/lib/datadog/ci/test_tracing/deprecated_total_coverage_metric.rb +1 -1
- data/lib/datadog/ci/test_tracing/known_tests.rb +1 -1
- data/lib/datadog/ci/test_tracing/null_component.rb +6 -1
- data/lib/datadog/ci/test_tracing/transport.rb +3 -22
- data/lib/datadog/ci/transport/adapters/net.rb +24 -4
- data/lib/datadog/ci/transport/adapters/net_http_client.rb +31 -0
- data/lib/datadog/ci/transport/api/evp_proxy.rb +2 -1
- data/lib/datadog/ci/transport/http.rb +20 -4
- data/lib/datadog/ci/utils/protected_tags.rb +27 -0
- data/lib/datadog/ci/utils/rum.rb +1 -1
- data/lib/datadog/ci/version.rb +1 -1
- metadata +3 -1
|
@@ -38,7 +38,7 @@ module Datadog
|
|
|
38
38
|
|
|
39
39
|
return unless @enabled
|
|
40
40
|
|
|
41
|
-
test_session.
|
|
41
|
+
test_session.set_internal_tag(Ext::Test::TAG_TEST_MANAGEMENT_ENABLED, "true")
|
|
42
42
|
|
|
43
43
|
return if load_component_state
|
|
44
44
|
|
|
@@ -64,9 +64,9 @@ module Datadog
|
|
|
64
64
|
|
|
65
65
|
Datadog.logger.debug { "Test properties for test #{datadog_test_id} are: [#{test_properties}]" }
|
|
66
66
|
|
|
67
|
-
test_span.
|
|
68
|
-
test_span.
|
|
69
|
-
test_span.
|
|
67
|
+
test_span.set_internal_tag(Ext::Test::TAG_IS_QUARANTINED, "true") if test_properties["quarantined"]
|
|
68
|
+
test_span.set_internal_tag(Ext::Test::TAG_IS_TEST_DISABLED, "true") if test_properties["disabled"]
|
|
69
|
+
test_span.set_internal_tag(Ext::Test::TAG_IS_ATTEMPT_TO_FIX, "true") if test_properties["attempt_to_fix"]
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def attempt_to_fix?(datadog_fqn_test_id)
|
|
@@ -116,7 +116,7 @@ module Datadog
|
|
|
116
116
|
|
|
117
117
|
# mark the test session so that all events emitted in this session are tagged
|
|
118
118
|
# with the hidden _dd.ci.library_configuration_error.test_management_tests tag
|
|
119
|
-
test_session.
|
|
119
|
+
test_session.set_internal_tag(Ext::Test::LibraryConfigurationError::TAG_TEST_MANAGEMENT_TESTS, "true")
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
Response.from_http_response(http_response).tests
|
|
@@ -60,12 +60,15 @@ module Datadog
|
|
|
60
60
|
]
|
|
61
61
|
@mutex = Mutex.new
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
end
|
|
63
|
+
@dynamic_atr_enabled = dynamic_atr_enabled
|
|
64
|
+
@dynamic_atr_has_custom_buckets = !dynamic_atr_buckets.nil?
|
|
66
65
|
end
|
|
67
66
|
|
|
68
67
|
def configure(library_settings, test_session)
|
|
68
|
+
if @dynamic_atr_enabled
|
|
69
|
+
Utils::Telemetry.record_dynamic_atr_retries(has_custom_buckets: @dynamic_atr_has_custom_buckets)
|
|
70
|
+
end
|
|
71
|
+
|
|
69
72
|
# let all strategies configure themselves
|
|
70
73
|
@retry_strategies.each do |strategy|
|
|
71
74
|
strategy.configure(library_settings, test_session)
|
|
@@ -85,6 +88,8 @@ module Datadog
|
|
|
85
88
|
end
|
|
86
89
|
|
|
87
90
|
def build_driver(test_span)
|
|
91
|
+
return Driver::NoRetry.new if test_span.no_auto_retry?
|
|
92
|
+
|
|
88
93
|
@mutex.synchronize do
|
|
89
94
|
# find the first strategy that covers the test span and let it build the driver
|
|
90
95
|
strategy = @retry_strategies.find { |strategy| strategy.covers?(test_span) }
|
|
@@ -105,27 +110,19 @@ module Datadog
|
|
|
105
110
|
if current_retry_driver.nil?
|
|
106
111
|
# We always run test at least once and after the first pass create a correct retry driver
|
|
107
112
|
self.current_retry_driver = build_driver(test_span)
|
|
108
|
-
|
|
109
|
-
# When the driver decides no retries are needed after the first execution
|
|
110
|
-
# (e.g., attempt-to-fix test that failed immediately), we still need to tag
|
|
111
|
-
# the outcome for strategies that track retry results.
|
|
112
|
-
if !should_retry? && current_retry_driver&.tracks_retry_results?
|
|
113
|
-
tag_last_retry(test_span)
|
|
114
|
-
end
|
|
115
113
|
else
|
|
116
|
-
# After each retry we let the driver to record the result.
|
|
117
|
-
# Then the driver will decide if we should retry again.
|
|
118
114
|
current_retry_driver&.record_retry(test_span)
|
|
119
|
-
|
|
120
|
-
# We know that the test was already retried at least once so if we should not retry anymore, then this
|
|
121
|
-
# is the last retry.
|
|
122
|
-
tag_last_retry(test_span) unless should_retry?
|
|
123
115
|
end
|
|
124
116
|
|
|
125
117
|
# Some retry strategies such as Early Flake Detection change the number of retries based on
|
|
126
118
|
# how long the test was.
|
|
127
119
|
current_retry_driver&.record_duration(test_span.peek_duration)
|
|
128
120
|
|
|
121
|
+
if !should_retry? && current_retry_driver&.tracks_retry_results?
|
|
122
|
+
tag_last_retry(test_span)
|
|
123
|
+
end
|
|
124
|
+
record_failure_suppression(test_span)
|
|
125
|
+
|
|
129
126
|
# We need to set the final status of the test (what will be reported to the test framework) on the last execution
|
|
130
127
|
# no matter if test was retried or not
|
|
131
128
|
#
|
|
@@ -139,11 +136,13 @@ module Datadog
|
|
|
139
136
|
end
|
|
140
137
|
|
|
141
138
|
def tag_last_retry(test_span)
|
|
142
|
-
|
|
139
|
+
return if test_span&.no_auto_retry?
|
|
140
|
+
|
|
141
|
+
test_span&.set_internal_tag(Ext::Test::TAG_HAS_FAILED_ALL_RETRIES, "true") if test_span&.all_executions_failed?
|
|
143
142
|
|
|
144
143
|
# if we are attempting to fix the test and all retries passed, we indicate that the fix might have worked
|
|
145
144
|
# otherwise we send "false" to show that it didn't work
|
|
146
|
-
test_span&.
|
|
145
|
+
test_span&.set_internal_tag(Ext::Test::TAG_ATTEMPT_TO_FIX_PASSED, test_span&.all_executions_passed?.to_s) if test_span&.should_retry_attempt_to_fix?
|
|
147
146
|
end
|
|
148
147
|
|
|
149
148
|
def should_retry?
|
|
@@ -154,6 +153,23 @@ module Datadog
|
|
|
154
153
|
|
|
155
154
|
private
|
|
156
155
|
|
|
156
|
+
def record_failure_suppression(test_span)
|
|
157
|
+
return unless test_span.failed?
|
|
158
|
+
|
|
159
|
+
reason = if test_span.should_quarantine? && !test_span.should_retry_attempt_to_fix?
|
|
160
|
+
Ext::Test::FailureSuppressionReason::QUARANTINE
|
|
161
|
+
else
|
|
162
|
+
retry_reason = current_retry_driver&.retry_reason
|
|
163
|
+
if retry_reason == Ext::Test::RetryReason::RETRY_FAILED && should_retry?
|
|
164
|
+
retry_reason
|
|
165
|
+
elsif retry_reason == Ext::Test::RetryReason::RETRY_DETECT_FLAKY && (should_retry? || test_span.any_retry_passed?)
|
|
166
|
+
retry_reason
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
test_span.set_internal_tag(Ext::Test::TAG_FAILURE_SUPPRESSION_REASON, reason) if reason
|
|
171
|
+
end
|
|
172
|
+
|
|
157
173
|
def test_tracing
|
|
158
174
|
Datadog.send(:components).test_tracing
|
|
159
175
|
end
|
|
@@ -16,8 +16,8 @@ module Datadog
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def mark_as_retry(test_span)
|
|
19
|
-
test_span&.
|
|
20
|
-
test_span&.
|
|
19
|
+
test_span&.set_internal_tag(Ext::Test::TAG_IS_RETRY, "true")
|
|
20
|
+
test_span&.set_internal_tag(Ext::Test::TAG_RETRY_REASON, retry_reason)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def record_retry(test_span)
|
|
@@ -8,14 +8,15 @@ module Datadog
|
|
|
8
8
|
module CI
|
|
9
9
|
module TestRetries
|
|
10
10
|
module Driver
|
|
11
|
-
#
|
|
11
|
+
# repeat new tests within the configured total execution budget (early flake detection)
|
|
12
12
|
# stop early once both a pass and a fail have been observed (flakiness confirmed)
|
|
13
13
|
class RetryFlakeDetection < Base
|
|
14
14
|
def initialize(test_span, max_attempts_thresholds:)
|
|
15
15
|
@max_attempts_thresholds = max_attempts_thresholds
|
|
16
16
|
@attempts = 0
|
|
17
|
-
|
|
18
|
-
@
|
|
17
|
+
@max_attempts = 0
|
|
18
|
+
@duration_recorded = false
|
|
19
|
+
@test_span = test_span
|
|
19
20
|
|
|
20
21
|
# track outcomes to stop early once flakiness is confirmed
|
|
21
22
|
@passed_once = !!test_span&.passed?
|
|
@@ -37,7 +38,14 @@ module Datadog
|
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def record_duration(duration)
|
|
40
|
-
|
|
41
|
+
return if @duration_recorded
|
|
42
|
+
|
|
43
|
+
total_executions = @max_attempts_thresholds.max_attempts_for_duration(duration)
|
|
44
|
+
@max_attempts = [total_executions - 1, 0].max
|
|
45
|
+
@duration_recorded = true
|
|
46
|
+
if total_executions.zero?
|
|
47
|
+
@test_span.set_internal_tag(Ext::Test::TAG_EARLY_FLAKE_ABORT_REASON, Ext::Test::EARLY_FLAKE_SLOW)
|
|
48
|
+
end
|
|
41
49
|
|
|
42
50
|
Datadog.logger.debug { "Recorded test duration of [#{duration}], new Max Attempts value is [#{@max_attempts}]" }
|
|
43
51
|
end
|
|
@@ -40,7 +40,7 @@ module Datadog
|
|
|
40
40
|
return unless @enabled
|
|
41
41
|
|
|
42
42
|
# mark early flake detection enabled for test session
|
|
43
|
-
test_session.
|
|
43
|
+
test_session.set_internal_tag(Ext::Test::TAG_EARLY_FLAKE_ENABLED, "true")
|
|
44
44
|
|
|
45
45
|
set_max_attempts_thresholds(library_settings)
|
|
46
46
|
calculate_total_retries_limit(library_settings, test_session)
|
|
@@ -58,7 +58,7 @@ module Datadog
|
|
|
58
58
|
private
|
|
59
59
|
|
|
60
60
|
def mark_test_session_faulty(test_session)
|
|
61
|
-
test_session&.
|
|
61
|
+
test_session&.set_internal_tag(Ext::Test::TAG_EARLY_FLAKE_ABORT_REASON, Ext::Test::EARLY_FLAKE_FAULTY)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def set_max_attempts_thresholds(library_settings)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative "base"
|
|
4
4
|
|
|
5
5
|
require_relative "../driver/retry_flaky_fixed"
|
|
6
|
+
require_relative "../../ext/settings"
|
|
6
7
|
|
|
7
8
|
module Datadog
|
|
8
9
|
module CI
|
|
@@ -17,18 +18,20 @@ module Datadog
|
|
|
17
18
|
max_attempts:
|
|
18
19
|
)
|
|
19
20
|
@enabled = enabled
|
|
20
|
-
@
|
|
21
|
+
@configured_max_attempts = max_attempts
|
|
22
|
+
@max_attempts = max_attempts || Ext::Settings::DEFAULT_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def configure(library_settings, test_session)
|
|
24
26
|
@enabled &&= library_settings.test_management_enabled?
|
|
25
|
-
@max_attempts = library_settings.attempt_to_fix_retries_count ||
|
|
27
|
+
@max_attempts = @configured_max_attempts || library_settings.attempt_to_fix_retries_count ||
|
|
28
|
+
Ext::Settings::DEFAULT_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES
|
|
26
29
|
end
|
|
27
30
|
|
|
28
31
|
def covers?(test_span)
|
|
29
32
|
return false unless @enabled
|
|
30
33
|
|
|
31
|
-
!!test_span&.
|
|
34
|
+
!!test_span&.should_retry_attempt_to_fix?
|
|
32
35
|
end
|
|
33
36
|
|
|
34
37
|
def build_driver(test_span)
|
|
@@ -84,6 +84,10 @@ module Datadog
|
|
|
84
84
|
@local_test_suites_mode = true
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
def shared_tags
|
|
88
|
+
@context.shared_tags
|
|
89
|
+
end
|
|
90
|
+
|
|
87
91
|
def configure(library_configuration, test_session)
|
|
88
92
|
return unless library_configuration.known_tests_enabled?
|
|
89
93
|
|
|
@@ -126,7 +130,10 @@ module Datadog
|
|
|
126
130
|
test_suite
|
|
127
131
|
end
|
|
128
132
|
|
|
129
|
-
|
|
133
|
+
# Exclusion keywords are for framework instrumentation only; the public
|
|
134
|
+
# Datadog::CI.trace_test and .start_test APIs do not expose them.
|
|
135
|
+
# @internal_api
|
|
136
|
+
def trace_test(test_name, test_suite_name, service: nil, tags: {}, prevent_failure_suppression: false, no_auto_retry: false, &block)
|
|
130
137
|
test_name = Utils::TestName.normalize(test_name)
|
|
131
138
|
test_suite_name = Utils::TestName.normalize(test_suite_name)
|
|
132
139
|
|
|
@@ -135,6 +142,7 @@ module Datadog
|
|
|
135
142
|
|
|
136
143
|
if block
|
|
137
144
|
@context.trace_test(test_name, test_suite, service: service, tags: tags) do |test|
|
|
145
|
+
test.apply_automation_exclusions(prevent_failure_suppression: prevent_failure_suppression, no_auto_retry: no_auto_retry)
|
|
138
146
|
on_test_started(test)
|
|
139
147
|
res = block.call(test)
|
|
140
148
|
on_test_finished(test)
|
|
@@ -142,6 +150,7 @@ module Datadog
|
|
|
142
150
|
end
|
|
143
151
|
else
|
|
144
152
|
test = @context.trace_test(test_name, test_suite, service: service, tags: tags)
|
|
153
|
+
test.apply_automation_exclusions(prevent_failure_suppression: prevent_failure_suppression, no_auto_retry: no_auto_retry)
|
|
145
154
|
on_test_started(test)
|
|
146
155
|
test
|
|
147
156
|
end
|
|
@@ -289,6 +298,7 @@ module Datadog
|
|
|
289
298
|
|
|
290
299
|
# sets logical test session name if none provided by the user
|
|
291
300
|
override_logical_test_session_name!(test_session) if logical_test_session_name.nil?
|
|
301
|
+
@context.finalize_shared_tags
|
|
292
302
|
|
|
293
303
|
# Signal Remote::Component to configure the library.
|
|
294
304
|
# Note that it will call this component back (unfortunate circular dependency).
|
|
@@ -371,7 +381,7 @@ module Datadog
|
|
|
371
381
|
def set_codeowners(span)
|
|
372
382
|
source = span.source_file
|
|
373
383
|
owners = @codeowners.list_owners(source) if source
|
|
374
|
-
span.
|
|
384
|
+
span.set_internal_tag(Ext::Test::TAG_CODEOWNERS, owners) unless owners.nil?
|
|
375
385
|
end
|
|
376
386
|
|
|
377
387
|
def validate_source_location(test)
|
|
@@ -391,7 +401,7 @@ module Datadog
|
|
|
391
401
|
"end line (#{end_line}) is before the start line (#{start_line}). " \
|
|
392
402
|
"Removing #{Ext::Test::TAG_SOURCE_END} tag."
|
|
393
403
|
end
|
|
394
|
-
test.
|
|
404
|
+
test.clear_internal_tag(Ext::Test::TAG_SOURCE_END)
|
|
395
405
|
end
|
|
396
406
|
end
|
|
397
407
|
|
|
@@ -409,8 +419,8 @@ module Datadog
|
|
|
409
419
|
"but it was not found. Fixing it by assigning test suite [#{test_suite.name}] to the test."
|
|
410
420
|
end
|
|
411
421
|
|
|
412
|
-
test.
|
|
413
|
-
test.
|
|
422
|
+
test.set_internal_tag(Ext::Test::TAG_TEST_SUITE_ID, test_suite.id.to_s)
|
|
423
|
+
test.set_internal_tag(Ext::Test::TAG_SUITE, test_suite.name)
|
|
414
424
|
end
|
|
415
425
|
|
|
416
426
|
def validate_test_suite_level_visibility_correctness(test)
|
|
@@ -469,7 +479,7 @@ module Datadog
|
|
|
469
479
|
@known_tests_enabled = false
|
|
470
480
|
|
|
471
481
|
# this adds unfortunate knowledge on EFD from Testvisibility, rethink this
|
|
472
|
-
test_session&.
|
|
482
|
+
test_session&.set_internal_tag(Ext::Test::TAG_EARLY_FLAKE_ABORT_REASON, Ext::Test::EARLY_FLAKE_FAULTY)
|
|
473
483
|
|
|
474
484
|
Datadog.logger.warn("Empty set of tests known to Datadog")
|
|
475
485
|
end
|
|
@@ -487,7 +497,7 @@ module Datadog
|
|
|
487
497
|
end
|
|
488
498
|
|
|
489
499
|
def mark_test_as_new(test_span)
|
|
490
|
-
test_span.
|
|
500
|
+
test_span.set_internal_tag(Ext::Test::TAG_IS_NEW, "true")
|
|
491
501
|
end
|
|
492
502
|
|
|
493
503
|
def test_impact_analysis
|
|
@@ -10,6 +10,7 @@ require_relative "telemetry"
|
|
|
10
10
|
|
|
11
11
|
require_relative "../ext/app_types"
|
|
12
12
|
require_relative "../ext/environment"
|
|
13
|
+
require_relative "../ext/metadata"
|
|
13
14
|
require_relative "../ext/test"
|
|
14
15
|
|
|
15
16
|
require_relative "../utils/configuration"
|
|
@@ -43,6 +44,14 @@ module Datadog
|
|
|
43
44
|
@any_tests_started = false
|
|
44
45
|
end
|
|
45
46
|
|
|
47
|
+
def shared_tags
|
|
48
|
+
@shared_tags || Span::EMPTY_TAGS
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def finalize_shared_tags
|
|
52
|
+
@shared_tags = build_shared_tags
|
|
53
|
+
end
|
|
54
|
+
|
|
46
55
|
def start_test_session(service: nil, tags: {})
|
|
47
56
|
@process_context.fetch_or_activate_test_session do
|
|
48
57
|
@mutex.synchronize { @any_tests_started = false }
|
|
@@ -239,17 +248,25 @@ module Datadog
|
|
|
239
248
|
end
|
|
240
249
|
|
|
241
250
|
# TAGGING
|
|
251
|
+
def build_shared_tags
|
|
252
|
+
environment_tags = @shared_tags || Ext::Environment.tags(ENV)
|
|
253
|
+
.slice(*Ext::Metadata::SHARED_ENVIRONMENT_TAGS)
|
|
254
|
+
.transform_values { |value| Core::Utils.utf8_encode(value).dup.freeze }
|
|
255
|
+
tags = environment_tags.merge(Ext::Test::LibraryCapabilities::CAPABILITY_VERSIONS)
|
|
256
|
+
tags[Ext::Test::TAG_USER_PROVIDED_TEST_SERVICE] = Utils::Configuration.service_name_provided_by_user?.to_s.freeze
|
|
257
|
+
session_name = @test_tracing_component.logical_test_session_name
|
|
258
|
+
tags[Ext::Test::TAG_TEST_SESSION_NAME] = session_name.dup.freeze unless session_name.nil?
|
|
259
|
+
tags.freeze
|
|
260
|
+
end
|
|
261
|
+
|
|
242
262
|
def set_initial_tags(ci_span, tags)
|
|
243
|
-
@
|
|
263
|
+
@shared_tags ||= build_shared_tags
|
|
244
264
|
|
|
245
265
|
ci_span.set_default_tags
|
|
246
266
|
ci_span.set_environment_runtime_tags
|
|
247
|
-
|
|
248
|
-
ci_span.
|
|
249
|
-
ci_span.
|
|
250
|
-
ci_span.set_tags(@environment_tags)
|
|
251
|
-
|
|
252
|
-
ci_span.set_metric(Ext::Test::METRIC_CPU_COUNT, Utils::TestRun.virtual_cpu_count)
|
|
267
|
+
ci_span.set_internal_tags(@runtime_tags_overrides) unless @runtime_tags_overrides.empty?
|
|
268
|
+
ci_span.set_internal_tags(tags.reject { |key, _| Ext::Metadata::SHARED_TAGS.include?(key.to_s) })
|
|
269
|
+
ci_span.set_internal_metric(Ext::Test::METRIC_CPU_COUNT, Utils::TestRun.virtual_cpu_count)
|
|
253
270
|
end
|
|
254
271
|
|
|
255
272
|
# PROPAGATING CONTEXT FROM TOP-LEVEL TO THE LOWER LEVELS
|
|
@@ -28,7 +28,7 @@ module Datadog
|
|
|
28
28
|
return
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
test_session.
|
|
31
|
+
test_session.set_internal_tag(Ext::Test::TAG_CODE_COVERAGE_LINES_PCT, result.covered_percent)
|
|
32
32
|
rescue => e
|
|
33
33
|
Datadog.logger.warn("Failed to extract SimpleCov code coverage: #{e.class}: #{e.message}")
|
|
34
34
|
end
|
|
@@ -112,7 +112,7 @@ module Datadog
|
|
|
112
112
|
unless response.ok?
|
|
113
113
|
# mark the test session so that all events emitted in this session are tagged
|
|
114
114
|
# with the hidden _dd.ci.library_configuration_error.known_tests tag
|
|
115
|
-
test_session.
|
|
115
|
+
test_session.set_internal_tag(Ext::Test::LibraryConfigurationError::TAG_KNOWN_TESTS, "true")
|
|
116
116
|
|
|
117
117
|
Datadog.logger.debug(
|
|
118
118
|
"Failed to fetch known tests page ##{page_number}, bailing out of known tests fetch. " \
|
|
@@ -16,6 +16,10 @@ module Datadog
|
|
|
16
16
|
@local_test_suites_mode = true
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
def shared_tags
|
|
20
|
+
{}
|
|
21
|
+
end
|
|
22
|
+
|
|
19
23
|
def configure(_, _)
|
|
20
24
|
end
|
|
21
25
|
|
|
@@ -33,7 +37,8 @@ module Datadog
|
|
|
33
37
|
skip_tracing
|
|
34
38
|
end
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
# @internal_api
|
|
41
|
+
def trace_test(test_name, test_suite_name, service: nil, tags: {}, prevent_failure_suppression: false, no_auto_retry: false, &block)
|
|
37
42
|
skip_tracing(block)
|
|
38
43
|
end
|
|
39
44
|
|
|
@@ -7,12 +7,10 @@ require "datadog/core/utils/only_once"
|
|
|
7
7
|
require_relative "serializers/factories/test_suite_level"
|
|
8
8
|
require_relative "serializers/meta_truncation"
|
|
9
9
|
|
|
10
|
-
require_relative "../ext/app_types"
|
|
11
10
|
require_relative "../ext/telemetry"
|
|
12
11
|
require_relative "../ext/transport"
|
|
13
12
|
require_relative "../transport/event_platform_transport"
|
|
14
13
|
require_relative "../transport/telemetry"
|
|
15
|
-
require_relative "../utils/configuration"
|
|
16
14
|
|
|
17
15
|
module Datadog
|
|
18
16
|
module CI
|
|
@@ -96,7 +94,7 @@ module Datadog
|
|
|
96
94
|
packer.write(1)
|
|
97
95
|
|
|
98
96
|
packer.write("metadata")
|
|
99
|
-
packer.write_map_header(
|
|
97
|
+
packer.write_map_header(2)
|
|
100
98
|
|
|
101
99
|
packer.write("*")
|
|
102
100
|
metadata_fields_count = dd_env ? 4 : 3
|
|
@@ -116,25 +114,8 @@ module Datadog
|
|
|
116
114
|
packer.write("library_version")
|
|
117
115
|
packer.write(Serializers::MetaTruncation.truncate_value(Datadog::CI::VERSION::STRING))
|
|
118
116
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
Ext::AppTypes::CI_SPAN_TYPES.each do |ci_span_type|
|
|
122
|
-
packer.write(ci_span_type)
|
|
123
|
-
packer.write_map_header(2 + library_capabilities_tags.count)
|
|
124
|
-
|
|
125
|
-
packer.write(Ext::Test::TAG_TEST_SESSION_NAME)
|
|
126
|
-
packer.write(Serializers::MetaTruncation.truncate_value(test_tracing&.logical_test_session_name))
|
|
127
|
-
|
|
128
|
-
packer.write(Ext::Test::TAG_USER_PROVIDED_TEST_SERVICE)
|
|
129
|
-
packer.write(
|
|
130
|
-
Serializers::MetaTruncation.truncate_value(Utils::Configuration.service_name_provided_by_user?.to_s)
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
library_capabilities_tags.each do |tag, value|
|
|
134
|
-
packer.write(tag)
|
|
135
|
-
packer.write(Serializers::MetaTruncation.truncate_value(value))
|
|
136
|
-
end
|
|
137
|
-
end
|
|
117
|
+
packer.write("test_levels")
|
|
118
|
+
packer.write(Serializers::MetaTruncation.truncate_string_values(test_tracing&.shared_tags || {}))
|
|
138
119
|
|
|
139
120
|
packer.write("events")
|
|
140
121
|
end
|
|
@@ -18,19 +18,28 @@ module Datadog
|
|
|
18
18
|
:hostname,
|
|
19
19
|
:port,
|
|
20
20
|
:timeout,
|
|
21
|
-
:ssl
|
|
21
|
+
:ssl,
|
|
22
|
+
:uds_path
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
# With uds_path, connects to the Unix domain socket at that path
|
|
25
|
+
# instead of hostname and port.
|
|
26
|
+
def initialize(hostname:, port:, ssl:, timeout_seconds:, uds_path: nil)
|
|
24
27
|
@hostname = hostname
|
|
25
28
|
@port = port
|
|
26
29
|
@timeout = timeout_seconds
|
|
27
30
|
@ssl = ssl
|
|
31
|
+
@uds_path = uds_path
|
|
28
32
|
end
|
|
29
33
|
|
|
30
34
|
def open(&block)
|
|
31
|
-
|
|
35
|
+
path = uds_path
|
|
36
|
+
req = if path
|
|
37
|
+
NetHttpClient.unix_socket_net_http(path)
|
|
38
|
+
else
|
|
39
|
+
# Without a socket, the agent settings or the agentless intake give a host.
|
|
40
|
+
NetHttpClient.original_net_http.new(_ = hostname, port).tap { |http| http.use_ssl = ssl }
|
|
41
|
+
end
|
|
32
42
|
|
|
33
|
-
req.use_ssl = ssl
|
|
34
43
|
req.open_timeout = req.read_timeout = timeout
|
|
35
44
|
|
|
36
45
|
req.start(&block)
|
|
@@ -140,6 +149,17 @@ module Datadog
|
|
|
140
149
|
nil
|
|
141
150
|
end
|
|
142
151
|
|
|
152
|
+
# Whether the request failed with an error the transport doesn't expect,
|
|
153
|
+
# which it used to raise; see Transport::HTTP.
|
|
154
|
+
def unexpected_error?
|
|
155
|
+
false
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Whether the request failed with a server error or an unexpected transport error.
|
|
159
|
+
def system_error?
|
|
160
|
+
server_error? || unexpected_error?
|
|
161
|
+
end
|
|
162
|
+
|
|
143
163
|
def telemetry_error_type
|
|
144
164
|
return nil if ok?
|
|
145
165
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "socket"
|
|
5
|
+
require "timeout"
|
|
6
|
+
|
|
3
7
|
module Datadog
|
|
4
8
|
module CI
|
|
5
9
|
module Transport
|
|
@@ -10,6 +14,33 @@ module Datadog
|
|
|
10
14
|
|
|
11
15
|
WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP
|
|
12
16
|
end
|
|
17
|
+
|
|
18
|
+
# A Net::HTTP connection to an agent on a Unix domain socket. Like the
|
|
19
|
+
# TCP connections, it is built on original_net_http so that WebMock
|
|
20
|
+
# leaves it alone; the host and port only go in the Host header.
|
|
21
|
+
def self.unix_socket_net_http(uds_path)
|
|
22
|
+
# @type var http: Net::HTTP & UnixSocketConnection
|
|
23
|
+
http = _ = original_net_http.new("localhost", 80).extend(UnixSocketConnection)
|
|
24
|
+
http.uds_path = uds_path
|
|
25
|
+
http
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Connects a Net::HTTP to a Unix domain socket instead of a host and port.
|
|
29
|
+
module UnixSocketConnection
|
|
30
|
+
attr_accessor :uds_path
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def connect
|
|
35
|
+
unix_socket = ::Timeout.timeout(open_timeout, ::Net::OpenTimeout) { ::UNIXSocket.new(uds_path) }
|
|
36
|
+
@socket = ::Net::BufferedIO.new(
|
|
37
|
+
unix_socket,
|
|
38
|
+
read_timeout: read_timeout,
|
|
39
|
+
write_timeout: write_timeout,
|
|
40
|
+
continue_timeout: continue_timeout
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
13
44
|
end
|
|
14
45
|
end
|
|
15
46
|
end
|
|
@@ -18,7 +18,8 @@ module Datadog
|
|
|
18
18
|
:port,
|
|
19
19
|
:ssl,
|
|
20
20
|
:timeout,
|
|
21
|
-
:compress
|
|
21
|
+
:compress,
|
|
22
|
+
:uds_path
|
|
22
23
|
|
|
23
24
|
DEFAULT_TIMEOUT = 30
|
|
24
25
|
MAX_RETRIES = 3
|
|
@@ -40,9 +41,10 @@ module Datadog
|
|
|
40
41
|
SocketError # DNS/network issues
|
|
41
42
|
].freeze
|
|
42
43
|
|
|
43
|
-
def initialize(host:, port:, timeout: DEFAULT_TIMEOUT, ssl: true, compress: false)
|
|
44
|
+
def initialize(host:, port:, timeout: DEFAULT_TIMEOUT, ssl: true, compress: false, uds_path: nil)
|
|
44
45
|
@host = host
|
|
45
46
|
@port = port
|
|
47
|
+
@uds_path = uds_path
|
|
46
48
|
@timeout = timeout
|
|
47
49
|
@ssl = ssl.nil? || ssl
|
|
48
50
|
@compress = compress.nil? ? false : compress
|
|
@@ -70,7 +72,7 @@ module Datadog
|
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
Datadog.logger.debug do
|
|
73
|
-
"Sending #{verb} request: host=#{host}; port=#{port}; ssl_enabled=#{ssl}; " \
|
|
75
|
+
"Sending #{verb} request: host=#{host}; port=#{port}; uds_path=#{uds_path}; ssl_enabled=#{ssl}; " \
|
|
74
76
|
"compression_enabled=#{compress}; path=#{path}; payload_size=#{payload.size}"
|
|
75
77
|
end
|
|
76
78
|
|
|
@@ -88,6 +90,10 @@ module Datadog
|
|
|
88
90
|
response.request_size = payload.bytesize
|
|
89
91
|
response.duration_ms = duration_ms
|
|
90
92
|
|
|
93
|
+
if response.server_error?
|
|
94
|
+
Datadog.logger.warn("Failed to send request to #{path} with server error #{response.code}")
|
|
95
|
+
end
|
|
96
|
+
|
|
91
97
|
response
|
|
92
98
|
end
|
|
93
99
|
|
|
@@ -119,6 +125,11 @@ module Datadog
|
|
|
119
125
|
rescue *RETRIABLE_ERRORS => e
|
|
120
126
|
Datadog.logger.debug { "Failed to send request with retriable error #{e} (#{e.message})" }
|
|
121
127
|
response = ErrorResponse.new(e)
|
|
128
|
+
rescue => e
|
|
129
|
+
# Any other error, such as a refused connection (Errno::ECONNREFUSED) or a
|
|
130
|
+
# TLS failure, would otherwise reach the customer's test process.
|
|
131
|
+
Datadog.logger.warn("Failed to send request to #{path} with unexpected error #{e.class} (#{e.message})")
|
|
132
|
+
return ErrorResponse.new(e)
|
|
122
133
|
end
|
|
123
134
|
|
|
124
135
|
# Check if we've exceeded the maximum retry time
|
|
@@ -153,7 +164,7 @@ module Datadog
|
|
|
153
164
|
|
|
154
165
|
def adapter
|
|
155
166
|
@adapter ||= Datadog::CI::Transport::Adapters::Net.new(
|
|
156
|
-
hostname: host, port: port, ssl: ssl, timeout_seconds: timeout
|
|
167
|
+
hostname: host, port: port, ssl: ssl, timeout_seconds: timeout, uds_path: uds_path
|
|
157
168
|
)
|
|
158
169
|
end
|
|
159
170
|
|
|
@@ -164,6 +175,11 @@ module Datadog
|
|
|
164
175
|
|
|
165
176
|
attr_reader :error
|
|
166
177
|
|
|
178
|
+
def unexpected_error?
|
|
179
|
+
NON_RETRIABLE_ERRORS.none? { |type| type === error } &&
|
|
180
|
+
RETRIABLE_ERRORS.none? { |type| type === error }
|
|
181
|
+
end
|
|
182
|
+
|
|
167
183
|
def payload
|
|
168
184
|
""
|
|
169
185
|
end
|