datadog-ci 1.41.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -2
  3. data/README.md +45 -0
  4. data/lib/datadog/ci/async_writer.rb +1 -4
  5. data/lib/datadog/ci/concurrent_span.rb +20 -0
  6. data/lib/datadog/ci/configuration/components.rb +2 -1
  7. data/lib/datadog/ci/configuration/extensions.rb +2 -0
  8. data/lib/datadog/ci/configuration/reconfiguration.rb +29 -0
  9. data/lib/datadog/ci/configuration/settings.rb +9 -2
  10. data/lib/datadog/ci/contrib/cucumber/formatter.rb +27 -8
  11. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +11 -3
  12. data/lib/datadog/ci/contrib/cuprite/driver.rb +5 -5
  13. data/lib/datadog/ci/contrib/knapsack/runner.rb +1 -1
  14. data/lib/datadog/ci/contrib/minitest/helpers.rb +59 -0
  15. data/lib/datadog/ci/contrib/minitest/reporter.rb +2 -2
  16. data/lib/datadog/ci/contrib/minitest/runner.rb +14 -1
  17. data/lib/datadog/ci/contrib/minitest/test.rb +4 -1
  18. data/lib/datadog/ci/contrib/rspec/example.rb +12 -2
  19. data/lib/datadog/ci/contrib/rspec/example_group.rb +3 -2
  20. data/lib/datadog/ci/contrib/rspec/runner.rb +2 -2
  21. data/lib/datadog/ci/contrib/selenium/navigation.rb +5 -5
  22. data/lib/datadog/ci/ext/metadata.rb +168 -0
  23. data/lib/datadog/ci/ext/settings.rb +1 -0
  24. data/lib/datadog/ci/ext/test.rb +11 -0
  25. data/lib/datadog/ci/impacted_tests_detection/component.rb +1 -1
  26. data/lib/datadog/ci/readonly_test_module.rb +16 -0
  27. data/lib/datadog/ci/readonly_test_session.rb +16 -0
  28. data/lib/datadog/ci/remote/library_settings_client.rb +1 -1
  29. data/lib/datadog/ci/remote/slow_test_retries.rb +3 -2
  30. data/lib/datadog/ci/span.rb +46 -10
  31. data/lib/datadog/ci/test.rb +75 -18
  32. data/lib/datadog/ci/test_discovery/component.rb +7 -1
  33. data/lib/datadog/ci/test_discovery/null_component.rb +4 -0
  34. data/lib/datadog/ci/test_impact_analysis/component.rb +21 -10
  35. data/lib/datadog/ci/test_impact_analysis/skippable.rb +1 -1
  36. data/lib/datadog/ci/test_management/component.rb +4 -4
  37. data/lib/datadog/ci/test_management/tests_properties.rb +1 -1
  38. data/lib/datadog/ci/test_retries/component.rb +34 -18
  39. data/lib/datadog/ci/test_retries/driver/base.rb +2 -2
  40. data/lib/datadog/ci/test_retries/driver/retry_flake_detection.rb +12 -4
  41. data/lib/datadog/ci/test_retries/strategy/retry_flake_detection.rb +2 -2
  42. data/lib/datadog/ci/test_retries/strategy/retry_flaky_fixed.rb +6 -3
  43. data/lib/datadog/ci/test_suite.rb +11 -0
  44. data/lib/datadog/ci/test_tracing/component.rb +28 -7
  45. data/lib/datadog/ci/test_tracing/context.rb +24 -7
  46. data/lib/datadog/ci/test_tracing/deprecated_total_coverage_metric.rb +1 -1
  47. data/lib/datadog/ci/test_tracing/known_tests.rb +1 -1
  48. data/lib/datadog/ci/test_tracing/null_component.rb +10 -1
  49. data/lib/datadog/ci/test_tracing/transport.rb +3 -22
  50. data/lib/datadog/ci/transport/adapters/net.rb +24 -4
  51. data/lib/datadog/ci/transport/adapters/net_http_client.rb +31 -0
  52. data/lib/datadog/ci/transport/api/evp_proxy.rb +2 -1
  53. data/lib/datadog/ci/transport/http.rb +20 -4
  54. data/lib/datadog/ci/utils/protected_tags.rb +27 -0
  55. data/lib/datadog/ci/utils/rum.rb +1 -1
  56. data/lib/datadog/ci/version.rb +1 -1
  57. data/lib/datadog/ci.rb +3 -0
  58. metadata +4 -1
@@ -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
- def initialize(hostname:, port:, ssl:, timeout_seconds:)
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
- req = NetHttpClient.original_net_http.new(hostname, port)
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
@@ -94,7 +94,8 @@ module Datadog
94
94
  port: agent_settings.port,
95
95
  ssl: agent_settings.ssl,
96
96
  timeout: agent_settings.timeout_seconds,
97
- compress: compress
97
+ compress: compress,
98
+ uds_path: agent_settings.uds_path
98
99
  )
99
100
  end
100
101
  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
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../ext/metadata"
4
+
5
+ module Datadog
6
+ module CI
7
+ module Utils
8
+ module ProtectedTags
9
+ @mutex = Mutex.new
10
+ @reported = {}
11
+
12
+ def self.reject?(key, operation)
13
+ return false unless Ext::Metadata::PROTECTED_TAGS.include?(key.to_s)
14
+
15
+ report = @mutex.synchronize do
16
+ id = [key.to_s.dup.freeze, operation]
17
+ next false if @reported.key?(id)
18
+
19
+ @reported[id] = true
20
+ end
21
+ Datadog.logger.error("Ignoring #{operation} for SDK-owned tag #{key}; use the supported configuration or instrumentation API") if report
22
+ true
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -23,7 +23,7 @@ module Datadog
23
23
  def self.stop_rum_session(script_executor, rum_flush_wait_millis: 500)
24
24
  return unless is_rum_active?(script_executor)
25
25
 
26
- Datadog::CI.active_test&.set_tag(
26
+ Datadog::CI.active_test&.set_internal_tag(
27
27
  CI::Ext::Test::TAG_IS_RUM_ACTIVE,
28
28
  "true"
29
29
  )
@@ -4,7 +4,7 @@ module Datadog
4
4
  module CI
5
5
  module VERSION
6
6
  MAJOR = 1
7
- MINOR = 41
7
+ MINOR = 43
8
8
  PATCH = 0
9
9
  PRE = nil
10
10
  BUILD = nil
data/lib/datadog/ci.rb CHANGED
@@ -24,6 +24,9 @@ module Datadog
24
24
  #
25
25
  # Returns the existing test session if one is already active. There is at most a single test session per process.
26
26
  #
27
+ # Complete all `Datadog.configure` calls before starting the session.
28
+ # Concurrent configuration and session startup are unsupported.
29
+ #
27
30
  # The {.start_test_session} method is used to mark the start of the test session:
28
31
  # ```
29
32
  # Datadog::CI.start_test_session(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadog-ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.41.0
4
+ version: 1.43.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
@@ -100,6 +100,7 @@ files:
100
100
  - lib/datadog/ci/concurrent_span.rb
101
101
  - lib/datadog/ci/configuration/components.rb
102
102
  - lib/datadog/ci/configuration/extensions.rb
103
+ - lib/datadog/ci/configuration/reconfiguration.rb
103
104
  - lib/datadog/ci/configuration/settings.rb
104
105
  - lib/datadog/ci/configuration/tracing_compatibility.rb
105
106
  - lib/datadog/ci/contrib/activesupport/configuration/settings.rb
@@ -203,6 +204,7 @@ files:
203
204
  - lib/datadog/ci/ext/environment/providers/travis.rb
204
205
  - lib/datadog/ci/ext/environment/providers/user_defined_tags.rb
205
206
  - lib/datadog/ci/ext/git.rb
207
+ - lib/datadog/ci/ext/metadata.rb
206
208
  - lib/datadog/ci/ext/rum.rb
207
209
  - lib/datadog/ci/ext/settings.rb
208
210
  - lib/datadog/ci/ext/telemetry.rb
@@ -316,6 +318,7 @@ files:
316
318
  - lib/datadog/ci/utils/git.rb
317
319
  - lib/datadog/ci/utils/json.rb
318
320
  - lib/datadog/ci/utils/parsing.rb
321
+ - lib/datadog/ci/utils/protected_tags.rb
319
322
  - lib/datadog/ci/utils/rum.rb
320
323
  - lib/datadog/ci/utils/runtime_tags_overrides.rb
321
324
  - lib/datadog/ci/utils/stateful.rb