datadog-ci 1.15.0 → 1.17.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 +39 -2
- data/lib/datadog/ci/async_writer.rb +112 -0
- data/lib/datadog/ci/codeowners/rule.rb +5 -0
- data/lib/datadog/ci/configuration/components.rb +50 -9
- data/lib/datadog/ci/configuration/settings.rb +17 -0
- data/lib/datadog/ci/contrib/activesupport/configuration/settings.rb +25 -0
- data/lib/datadog/ci/contrib/activesupport/ext.rb +14 -0
- data/lib/datadog/ci/contrib/activesupport/integration.rb +43 -0
- data/lib/datadog/ci/contrib/activesupport/logs_formatter.rb +41 -0
- data/lib/datadog/ci/contrib/activesupport/patcher.rb +50 -0
- data/lib/datadog/ci/contrib/knapsack/patcher.rb +1 -3
- data/lib/datadog/ci/contrib/knapsack/runner.rb +2 -0
- data/lib/datadog/ci/contrib/lograge/configuration/settings.rb +25 -0
- data/lib/datadog/ci/contrib/lograge/ext.rb +14 -0
- data/lib/datadog/ci/contrib/lograge/integration.rb +43 -0
- data/lib/datadog/ci/contrib/lograge/log_subscriber.rb +41 -0
- data/lib/datadog/ci/contrib/lograge/patcher.rb +32 -0
- data/lib/datadog/ci/contrib/minitest/runner.rb +1 -0
- data/lib/datadog/ci/contrib/minitest/test.rb +7 -2
- data/lib/datadog/ci/contrib/parallel_tests/patcher.rb +1 -4
- data/lib/datadog/ci/contrib/patcher.rb +4 -0
- data/lib/datadog/ci/contrib/rspec/helpers.rb +1 -3
- data/lib/datadog/ci/contrib/semantic_logger/configuration/settings.rb +25 -0
- data/lib/datadog/ci/contrib/semantic_logger/ext.rb +14 -0
- data/lib/datadog/ci/contrib/semantic_logger/integration.rb +42 -0
- data/lib/datadog/ci/contrib/semantic_logger/logger.rb +32 -0
- data/lib/datadog/ci/contrib/semantic_logger/patcher.rb +32 -0
- data/lib/datadog/ci/ext/environment/extractor.rb +4 -6
- data/lib/datadog/ci/ext/environment/providers/appveyor.rb +5 -0
- data/lib/datadog/ci/ext/environment/providers/base.rb +7 -2
- data/lib/datadog/ci/ext/environment/providers/bitbucket.rb +6 -0
- data/lib/datadog/ci/ext/environment/providers/bitrise.rb +7 -1
- data/lib/datadog/ci/ext/environment/providers/buddy.rb +5 -0
- data/lib/datadog/ci/ext/environment/providers/github_actions.rb +37 -18
- data/lib/datadog/ci/ext/environment/providers/gitlab.rb +13 -1
- data/lib/datadog/ci/ext/environment/providers/user_defined_tags.rb +12 -0
- data/lib/datadog/ci/ext/git.rb +3 -0
- data/lib/datadog/ci/ext/settings.rb +3 -0
- data/lib/datadog/ci/ext/telemetry.rb +4 -0
- data/lib/datadog/ci/ext/test.rb +7 -3
- data/lib/datadog/ci/ext/transport.rb +3 -0
- data/lib/datadog/ci/git/local_repository.rb +238 -4
- data/lib/datadog/ci/git/tree_uploader.rb +10 -3
- data/lib/datadog/ci/impacted_tests_detection/component.rb +83 -0
- data/lib/datadog/ci/impacted_tests_detection/telemetry.rb +16 -0
- data/lib/datadog/ci/logs/component.rb +46 -0
- data/lib/datadog/ci/logs/transport.rb +73 -0
- data/lib/datadog/ci/remote/component.rb +6 -1
- data/lib/datadog/ci/remote/library_settings.rb +8 -0
- data/lib/datadog/ci/span.rb +7 -0
- data/lib/datadog/ci/test.rb +16 -0
- data/lib/datadog/ci/test_management/tests_properties.rb +2 -1
- data/lib/datadog/ci/test_retries/component.rb +8 -17
- data/lib/datadog/ci/test_retries/driver/{retry_new.rb → retry_flake_detection.rb} +2 -2
- data/lib/datadog/ci/test_retries/strategy/{retry_new.rb → retry_flake_detection.rb} +4 -4
- data/lib/datadog/ci/test_visibility/component.rb +6 -0
- data/lib/datadog/ci/test_visibility/null_component.rb +3 -1
- data/lib/datadog/ci/transport/api/agentless.rb +8 -1
- data/lib/datadog/ci/transport/api/base.rb +4 -0
- data/lib/datadog/ci/transport/api/builder.rb +5 -1
- data/lib/datadog/ci/transport/api/evp_proxy.rb +4 -0
- data/lib/datadog/ci/version.rb +1 -1
- data/lib/datadog/ci.rb +3 -0
- metadata +25 -6
- data/lib/datadog/ci/test_optimisation/coverage/writer.rb +0 -116
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require_relative "driver/no_retry"
|
4
4
|
require_relative "driver/retry_failed"
|
5
|
-
require_relative "driver/
|
5
|
+
require_relative "driver/retry_flake_detection"
|
6
6
|
|
7
7
|
require_relative "strategy/no_retry"
|
8
8
|
require_relative "strategy/retry_failed"
|
9
|
-
require_relative "strategy/
|
9
|
+
require_relative "strategy/retry_flake_detection"
|
10
10
|
require_relative "strategy/retry_flaky_fixed"
|
11
11
|
|
12
12
|
require_relative "../ext/telemetry"
|
@@ -31,13 +31,13 @@ module Datadog
|
|
31
31
|
)
|
32
32
|
no_retries_strategy = Strategy::NoRetry.new
|
33
33
|
|
34
|
-
|
34
|
+
retry_failed_strategy = Strategy::RetryFailed.new(
|
35
35
|
enabled: retry_failed_tests_enabled,
|
36
36
|
max_attempts: retry_failed_tests_max_attempts,
|
37
37
|
total_limit: retry_failed_tests_total_limit
|
38
38
|
)
|
39
39
|
|
40
|
-
|
40
|
+
retry_flake_detection_strategy = Strategy::RetryFlakeDetection.new(
|
41
41
|
enabled: retry_new_tests_enabled
|
42
42
|
)
|
43
43
|
|
@@ -49,8 +49,8 @@ module Datadog
|
|
49
49
|
# order is important, we apply the first matching strategy
|
50
50
|
@retry_strategies = [
|
51
51
|
retry_flaky_fixed_strategy,
|
52
|
-
|
53
|
-
|
52
|
+
retry_flake_detection_strategy,
|
53
|
+
retry_failed_strategy,
|
54
54
|
no_retries_strategy
|
55
55
|
]
|
56
56
|
@mutex = Mutex.new
|
@@ -111,23 +111,14 @@ module Datadog
|
|
111
111
|
test_span&.set_tag(Ext::Test::TAG_HAS_FAILED_ALL_RETRIES, "true") if test_span&.all_executions_failed?
|
112
112
|
|
113
113
|
# if we are attempting to fix the test and all retries passed, we indicate that the fix might have worked
|
114
|
-
|
115
|
-
|
116
|
-
end
|
114
|
+
# otherwise we send "false" to show that it didn't work
|
115
|
+
test_span&.set_tag(Ext::Test::TAG_ATTEMPT_TO_FIX_PASSED, test_span&.all_executions_passed?.to_s) if test_span&.attempt_to_fix?
|
117
116
|
end
|
118
117
|
|
119
118
|
def should_retry?
|
120
119
|
!!current_retry_driver&.should_retry?
|
121
120
|
end
|
122
121
|
|
123
|
-
def auto_test_retries_feature_enabled
|
124
|
-
@retry_failed_strategy.enabled
|
125
|
-
end
|
126
|
-
|
127
|
-
def early_flake_detection_feature_enabled
|
128
|
-
@retry_new_strategy.enabled
|
129
|
-
end
|
130
|
-
|
131
122
|
private
|
132
123
|
|
133
124
|
def current_retry_driver
|
@@ -9,7 +9,7 @@ module Datadog
|
|
9
9
|
module TestRetries
|
10
10
|
module Driver
|
11
11
|
# retry every new test up to 10 times (early flake detection)
|
12
|
-
class
|
12
|
+
class RetryFlakeDetection < Base
|
13
13
|
def initialize(test_span, max_attempts_thresholds:)
|
14
14
|
@max_attempts_thresholds = max_attempts_thresholds
|
15
15
|
@attempts = 0
|
@@ -36,7 +36,7 @@ module Datadog
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def retry_reason
|
39
|
-
Ext::Test::RetryReason::
|
39
|
+
Ext::Test::RetryReason::RETRY_DETECT_FLAKY
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
require_relative "base"
|
4
4
|
|
5
|
-
require_relative "../driver/
|
5
|
+
require_relative "../driver/retry_flake_detection"
|
6
6
|
|
7
7
|
module Datadog
|
8
8
|
module CI
|
9
9
|
module TestRetries
|
10
10
|
module Strategy
|
11
|
-
class
|
11
|
+
class RetryFlakeDetection < Base
|
12
12
|
DEFAULT_TOTAL_TESTS_COUNT = 100
|
13
13
|
|
14
14
|
attr_reader :enabled, :max_attempts_thresholds, :total_limit, :retried_count
|
@@ -31,7 +31,7 @@ module Datadog
|
|
31
31
|
mark_test_session_faulty(Datadog::CI.active_test_session)
|
32
32
|
end
|
33
33
|
|
34
|
-
@enabled && !test_span.skipped? && test_span.is_new?
|
34
|
+
@enabled && !test_span.skipped? && (test_span.is_new? || test_span.modified?)
|
35
35
|
end
|
36
36
|
|
37
37
|
def configure(library_settings, test_session)
|
@@ -52,7 +52,7 @@ module Datadog
|
|
52
52
|
end
|
53
53
|
@retried_count += 1
|
54
54
|
|
55
|
-
Driver::
|
55
|
+
Driver::RetryFlakeDetection.new(test_span, max_attempts_thresholds: @max_attempts_thresholds)
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
@@ -261,6 +261,8 @@ module Datadog
|
|
261
261
|
|
262
262
|
mark_test_as_new(test) if new_test?(test)
|
263
263
|
|
264
|
+
impacted_tests_detection.tag_modified_test(test)
|
265
|
+
|
264
266
|
test_management.tag_test_from_properties(test)
|
265
267
|
|
266
268
|
test_optimisation.mark_if_skippable(test)
|
@@ -435,6 +437,10 @@ module Datadog
|
|
435
437
|
Datadog.send(:components).test_management
|
436
438
|
end
|
437
439
|
|
440
|
+
def impacted_tests_detection
|
441
|
+
Datadog.send(:components).impacted_tests_detection
|
442
|
+
end
|
443
|
+
|
438
444
|
# DISTRIBUTED RUBY CONTEXT
|
439
445
|
def start_drb_service
|
440
446
|
return if @context_service_uri
|
@@ -8,7 +8,9 @@ module Datadog
|
|
8
8
|
def configure(_, _)
|
9
9
|
end
|
10
10
|
|
11
|
-
def start_test_session(
|
11
|
+
def start_test_session(
|
12
|
+
service: nil, tags: {}, estimated_total_tests_count: 0, distributed: false, local_test_suites_mode: true
|
13
|
+
)
|
12
14
|
skip_tracing
|
13
15
|
end
|
14
16
|
|
@@ -10,11 +10,12 @@ module Datadog
|
|
10
10
|
class Agentless < Base
|
11
11
|
attr_reader :api_key
|
12
12
|
|
13
|
-
def initialize(api_key:, citestcycle_url:, api_url:, citestcov_url:)
|
13
|
+
def initialize(api_key:, citestcycle_url:, api_url:, citestcov_url:, logs_intake_url:)
|
14
14
|
@api_key = api_key
|
15
15
|
@citestcycle_http = build_http_client(citestcycle_url, compress: true)
|
16
16
|
@api_http = build_http_client(api_url, compress: false)
|
17
17
|
@citestcov_http = build_http_client(citestcov_url, compress: true)
|
18
|
+
@logs_intake_http = build_http_client(logs_intake_url, compress: true)
|
18
19
|
end
|
19
20
|
|
20
21
|
def citestcycle_request(path:, payload:, headers: {}, verb: "post")
|
@@ -42,6 +43,12 @@ module Datadog
|
|
42
43
|
perform_request(@citestcov_http, path: path, payload: @citestcov_payload, headers: headers, verb: verb)
|
43
44
|
end
|
44
45
|
|
46
|
+
def logs_intake_request(path:, payload:, headers: {}, verb: "post")
|
47
|
+
super
|
48
|
+
|
49
|
+
perform_request(@logs_intake_http, path: path, payload: payload, headers: headers, verb: verb)
|
50
|
+
end
|
51
|
+
|
45
52
|
private
|
46
53
|
|
47
54
|
def perform_request(http_client, path:, payload:, headers:, verb:, accept_compressed_response: false)
|
@@ -38,6 +38,10 @@ module Datadog
|
|
38
38
|
].join("\r\n")
|
39
39
|
end
|
40
40
|
|
41
|
+
def logs_intake_request(path:, payload:, headers: {}, verb: "post")
|
42
|
+
headers[Ext::Transport::HEADER_CONTENT_TYPE] ||= Ext::Transport::CONTENT_TYPE_JSON
|
43
|
+
end
|
44
|
+
|
41
45
|
def headers_with_default(headers)
|
42
46
|
request_headers = default_headers
|
43
47
|
request_headers.merge!(headers)
|
@@ -27,11 +27,15 @@ module Datadog
|
|
27
27
|
citestcov_url = settings.ci.agentless_url ||
|
28
28
|
"https://#{Ext::Transport::TEST_COVERAGE_INTAKE_HOST_PREFIX}.#{dd_site}:443"
|
29
29
|
|
30
|
+
logs_intake_url = settings.ci.agentless_url ||
|
31
|
+
"https://#{Ext::Transport::LOGS_INTAKE_HOST_PREFIX}.#{dd_site}:443"
|
32
|
+
|
30
33
|
Agentless.new(
|
31
34
|
api_key: settings.api_key,
|
32
35
|
citestcycle_url: citestcycle_url,
|
33
36
|
api_url: api_url,
|
34
|
-
citestcov_url: citestcov_url
|
37
|
+
citestcov_url: citestcov_url,
|
38
|
+
logs_intake_url: logs_intake_url
|
35
39
|
)
|
36
40
|
end
|
37
41
|
|
@@ -46,6 +46,10 @@ module Datadog
|
|
46
46
|
perform_request(@agent_intake_http, path: path, payload: @citestcov_payload, headers: headers, verb: verb)
|
47
47
|
end
|
48
48
|
|
49
|
+
def logs_intake_request(path:, payload:, headers: {}, verb: "post")
|
50
|
+
raise NotImplementedError, "Logs intake is not supported in EVP proxy mode"
|
51
|
+
end
|
52
|
+
|
49
53
|
private
|
50
54
|
|
51
55
|
def perform_request(http_client, path:, payload:, headers:, verb:)
|
data/lib/datadog/ci/version.rb
CHANGED
data/lib/datadog/ci.rb
CHANGED
@@ -429,6 +429,9 @@ require_relative "ci/contrib/parallel_tests/integration"
|
|
429
429
|
require_relative "ci/contrib/selenium/integration"
|
430
430
|
require_relative "ci/contrib/cuprite/integration"
|
431
431
|
require_relative "ci/contrib/simplecov/integration"
|
432
|
+
require_relative "ci/contrib/activesupport/integration"
|
433
|
+
require_relative "ci/contrib/lograge/integration"
|
434
|
+
require_relative "ci/contrib/semantic_logger/integration"
|
432
435
|
|
433
436
|
# Configuration extensions
|
434
437
|
require_relative "ci/configuration/extensions"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datadog-ci
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Datadog, Inc.
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: datadog
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- ext/datadog_cov/datadog_cov.c
|
75
75
|
- ext/datadog_cov/extconf.rb
|
76
76
|
- lib/datadog/ci.rb
|
77
|
+
- lib/datadog/ci/async_writer.rb
|
77
78
|
- lib/datadog/ci/auto_instrument.rb
|
78
79
|
- lib/datadog/ci/cli/cli.rb
|
79
80
|
- lib/datadog/ci/cli/command/base.rb
|
@@ -87,6 +88,11 @@ files:
|
|
87
88
|
- lib/datadog/ci/configuration/components.rb
|
88
89
|
- lib/datadog/ci/configuration/extensions.rb
|
89
90
|
- lib/datadog/ci/configuration/settings.rb
|
91
|
+
- lib/datadog/ci/contrib/activesupport/configuration/settings.rb
|
92
|
+
- lib/datadog/ci/contrib/activesupport/ext.rb
|
93
|
+
- lib/datadog/ci/contrib/activesupport/integration.rb
|
94
|
+
- lib/datadog/ci/contrib/activesupport/logs_formatter.rb
|
95
|
+
- lib/datadog/ci/contrib/activesupport/patcher.rb
|
90
96
|
- lib/datadog/ci/contrib/ciqueue/integration.rb
|
91
97
|
- lib/datadog/ci/contrib/ciqueue/patcher.rb
|
92
98
|
- lib/datadog/ci/contrib/cucumber/configuration/settings.rb
|
@@ -108,6 +114,11 @@ files:
|
|
108
114
|
- lib/datadog/ci/contrib/knapsack/integration.rb
|
109
115
|
- lib/datadog/ci/contrib/knapsack/patcher.rb
|
110
116
|
- lib/datadog/ci/contrib/knapsack/runner.rb
|
117
|
+
- lib/datadog/ci/contrib/lograge/configuration/settings.rb
|
118
|
+
- lib/datadog/ci/contrib/lograge/ext.rb
|
119
|
+
- lib/datadog/ci/contrib/lograge/integration.rb
|
120
|
+
- lib/datadog/ci/contrib/lograge/log_subscriber.rb
|
121
|
+
- lib/datadog/ci/contrib/lograge/patcher.rb
|
111
122
|
- lib/datadog/ci/contrib/minitest/configuration/settings.rb
|
112
123
|
- lib/datadog/ci/contrib/minitest/ext.rb
|
113
124
|
- lib/datadog/ci/contrib/minitest/helpers.rb
|
@@ -138,6 +149,11 @@ files:
|
|
138
149
|
- lib/datadog/ci/contrib/selenium/integration.rb
|
139
150
|
- lib/datadog/ci/contrib/selenium/navigation.rb
|
140
151
|
- lib/datadog/ci/contrib/selenium/patcher.rb
|
152
|
+
- lib/datadog/ci/contrib/semantic_logger/configuration/settings.rb
|
153
|
+
- lib/datadog/ci/contrib/semantic_logger/ext.rb
|
154
|
+
- lib/datadog/ci/contrib/semantic_logger/integration.rb
|
155
|
+
- lib/datadog/ci/contrib/semantic_logger/logger.rb
|
156
|
+
- lib/datadog/ci/contrib/semantic_logger/patcher.rb
|
141
157
|
- lib/datadog/ci/contrib/settings.rb
|
142
158
|
- lib/datadog/ci/contrib/simplecov/configuration/settings.rb
|
143
159
|
- lib/datadog/ci/contrib/simplecov/ext.rb
|
@@ -178,6 +194,10 @@ files:
|
|
178
194
|
- lib/datadog/ci/git/tree_uploader.rb
|
179
195
|
- lib/datadog/ci/git/upload_packfile.rb
|
180
196
|
- lib/datadog/ci/git/user.rb
|
197
|
+
- lib/datadog/ci/impacted_tests_detection/component.rb
|
198
|
+
- lib/datadog/ci/impacted_tests_detection/telemetry.rb
|
199
|
+
- lib/datadog/ci/logs/component.rb
|
200
|
+
- lib/datadog/ci/logs/transport.rb
|
181
201
|
- lib/datadog/ci/readonly_test_module.rb
|
182
202
|
- lib/datadog/ci/readonly_test_session.rb
|
183
203
|
- lib/datadog/ci/remote/component.rb
|
@@ -194,7 +214,6 @@ files:
|
|
194
214
|
- lib/datadog/ci/test_optimisation/coverage/ddcov.rb
|
195
215
|
- lib/datadog/ci/test_optimisation/coverage/event.rb
|
196
216
|
- lib/datadog/ci/test_optimisation/coverage/transport.rb
|
197
|
-
- lib/datadog/ci/test_optimisation/coverage/writer.rb
|
198
217
|
- lib/datadog/ci/test_optimisation/skippable.rb
|
199
218
|
- lib/datadog/ci/test_optimisation/skippable_percentage/base.rb
|
200
219
|
- lib/datadog/ci/test_optimisation/skippable_percentage/calculator.rb
|
@@ -204,14 +223,14 @@ files:
|
|
204
223
|
- lib/datadog/ci/test_retries/driver/base.rb
|
205
224
|
- lib/datadog/ci/test_retries/driver/no_retry.rb
|
206
225
|
- lib/datadog/ci/test_retries/driver/retry_failed.rb
|
226
|
+
- lib/datadog/ci/test_retries/driver/retry_flake_detection.rb
|
207
227
|
- lib/datadog/ci/test_retries/driver/retry_flaky_fixed.rb
|
208
|
-
- lib/datadog/ci/test_retries/driver/retry_new.rb
|
209
228
|
- lib/datadog/ci/test_retries/null_component.rb
|
210
229
|
- lib/datadog/ci/test_retries/strategy/base.rb
|
211
230
|
- lib/datadog/ci/test_retries/strategy/no_retry.rb
|
212
231
|
- lib/datadog/ci/test_retries/strategy/retry_failed.rb
|
232
|
+
- lib/datadog/ci/test_retries/strategy/retry_flake_detection.rb
|
213
233
|
- lib/datadog/ci/test_retries/strategy/retry_flaky_fixed.rb
|
214
|
-
- lib/datadog/ci/test_retries/strategy/retry_new.rb
|
215
234
|
- lib/datadog/ci/test_session.rb
|
216
235
|
- lib/datadog/ci/test_suite.rb
|
217
236
|
- lib/datadog/ci/test_visibility/component.rb
|
@@ -281,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
300
|
- !ruby/object:Gem::Version
|
282
301
|
version: 2.0.0
|
283
302
|
requirements: []
|
284
|
-
rubygems_version: 3.6.
|
303
|
+
rubygems_version: 3.6.7
|
285
304
|
specification_version: 4
|
286
305
|
summary: Datadog Test Optimization for your ruby application
|
287
306
|
test_files: []
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "datadog/core/workers/async"
|
4
|
-
require "datadog/core/workers/queue"
|
5
|
-
require "datadog/core/workers/polling"
|
6
|
-
|
7
|
-
require "datadog/core/buffer/cruby"
|
8
|
-
require "datadog/core/buffer/thread_safe"
|
9
|
-
|
10
|
-
require "datadog/core/environment/ext"
|
11
|
-
|
12
|
-
module Datadog
|
13
|
-
module CI
|
14
|
-
module TestOptimisation
|
15
|
-
module Coverage
|
16
|
-
class Writer
|
17
|
-
include Core::Workers::Queue
|
18
|
-
include Core::Workers::Polling
|
19
|
-
|
20
|
-
attr_reader :transport
|
21
|
-
|
22
|
-
DEFAULT_BUFFER_MAX_SIZE = 10_000
|
23
|
-
DEFAULT_SHUTDOWN_TIMEOUT = 60
|
24
|
-
|
25
|
-
DEFAULT_INTERVAL = 3
|
26
|
-
|
27
|
-
def initialize(transport:, options: {})
|
28
|
-
@transport = transport
|
29
|
-
|
30
|
-
# Workers::Polling settings
|
31
|
-
self.enabled = options.fetch(:enabled, true)
|
32
|
-
|
33
|
-
# Workers::Async::Thread settings
|
34
|
-
self.fork_policy = Core::Workers::Async::Thread::FORK_POLICY_RESTART
|
35
|
-
|
36
|
-
# Workers::IntervalLoop settings
|
37
|
-
self.loop_base_interval = options[:interval] || DEFAULT_INTERVAL
|
38
|
-
self.loop_back_off_ratio = options[:back_off_ratio] if options.key?(:back_off_ratio)
|
39
|
-
self.loop_back_off_max = options[:back_off_max] if options.key?(:back_off_max)
|
40
|
-
|
41
|
-
@buffer_size = options.fetch(:buffer_size, DEFAULT_BUFFER_MAX_SIZE)
|
42
|
-
|
43
|
-
self.buffer = buffer_klass.new(@buffer_size)
|
44
|
-
|
45
|
-
@shutdown_timeout = options.fetch(:shutdown_timeout, DEFAULT_SHUTDOWN_TIMEOUT)
|
46
|
-
|
47
|
-
@stopped = false
|
48
|
-
end
|
49
|
-
|
50
|
-
def write(event)
|
51
|
-
return if @stopped
|
52
|
-
|
53
|
-
# Start worker thread. If the process has forked, it will trigger #after_fork to
|
54
|
-
# reconfigure the worker accordingly.
|
55
|
-
perform
|
56
|
-
|
57
|
-
enqueue(event)
|
58
|
-
end
|
59
|
-
|
60
|
-
def perform(*events)
|
61
|
-
responses = transport.send_events(events)
|
62
|
-
|
63
|
-
if responses.find(&:server_error?)
|
64
|
-
loop_back_off!
|
65
|
-
Datadog.logger.warn { "Encountered server error while sending coverage events" }
|
66
|
-
end
|
67
|
-
|
68
|
-
nil
|
69
|
-
rescue => e
|
70
|
-
Datadog.logger.warn { "Error while sending coverage events: #{e}" }
|
71
|
-
loop_back_off!
|
72
|
-
end
|
73
|
-
|
74
|
-
def stop(force_stop = false, timeout = @shutdown_timeout)
|
75
|
-
@stopped = true
|
76
|
-
|
77
|
-
buffer.close if running?
|
78
|
-
|
79
|
-
super
|
80
|
-
end
|
81
|
-
|
82
|
-
def enqueue(event)
|
83
|
-
buffer.push(event)
|
84
|
-
end
|
85
|
-
|
86
|
-
def dequeue
|
87
|
-
buffer.pop
|
88
|
-
end
|
89
|
-
|
90
|
-
def work_pending?
|
91
|
-
!buffer.empty?
|
92
|
-
end
|
93
|
-
|
94
|
-
def async?
|
95
|
-
true
|
96
|
-
end
|
97
|
-
|
98
|
-
def after_fork
|
99
|
-
# In multiprocess environments, forks will share the same buffer until its written to.
|
100
|
-
# A.K.A. copy-on-write. We don't want forks to write events generated from another process.
|
101
|
-
# Instead, we reset it after the fork. (Make sure any enqueue operations happen after this.)
|
102
|
-
self.buffer = buffer_klass.new(@buffer_size)
|
103
|
-
end
|
104
|
-
|
105
|
-
def buffer_klass
|
106
|
-
if Core::Environment::Ext::RUBY_ENGINE == "ruby"
|
107
|
-
Core::Buffer::CRuby
|
108
|
-
else
|
109
|
-
Core::Buffer::ThreadSafe
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|