datadog-ci 1.0.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73bd9b05aba53e1197420cc0e4a529339b6526e13775467fa326b4949e44043a
4
- data.tar.gz: 7613c476a2a3f2cf28d7dd99dd53da2fa6c921c9a03de18a6997f25e3fe0f27a
3
+ metadata.gz: 61f6379b9a5ac0c29ff9ee6b1687c1c2add77d6a5031dfd5758eb34a66cc6235
4
+ data.tar.gz: a795d8d69513925ee5ea6cf113cb54cec3711fe65ae5e928fcdeb8e1454323af
5
5
  SHA512:
6
- metadata.gz: fc66a07d4ccceb71f18b26d290e387b6b403d7efbb46169ced3db9ad0e67e2f29ec163bdaa43a7f7508c6511ca0c68d99257d32d3a25e62b42e00219d7ef44a1
7
- data.tar.gz: 6fb71c67ecea77fc61238fa7f739192a7670f51d8f4c052d436d2f4d69743f1202f27e27cf84fa76ce74860145d13badb00862c1c03b37d93dc9a33e597afb3d
6
+ metadata.gz: 3ea51d0baa70ecb4e66fb49712f4f291582ecb04455b2d32ec1328bb8ea3c112c4c25d80e450db542ee4f29408786b09a82b5f94fb1c7ef8c96b98d301e61e9b
7
+ data.tar.gz: 4f066970c2d9ed93001f35f9096cefcf2a4447a86cf7c1d89435853b1da00389c587924304c7a213e56f58f64b191523d202e34f86da535ded271583881411ac
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.1.0] - 2024-07-01
4
+
5
+ ### Added
6
+ * Ignore Webmock automatically when making HTTP calls ([#193][])
7
+
3
8
  ## [1.0.1] - 2024-06-11
4
9
 
5
10
  ### Fixed
@@ -267,7 +272,8 @@ Currently test suite level visibility is not used by our instrumentation: it wil
267
272
 
268
273
  - Ruby versions < 2.7 no longer supported ([#8][])
269
274
 
270
- [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.1...main
275
+ [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.1.0...main
276
+ [1.1.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.1...v1.1.0
271
277
  [1.0.1]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.0...v1.0.1
272
278
  [1.0.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.0.beta6...v1.0.0
273
279
  [1.0.0.beta6]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.0.beta5...v1.0.0.beta6
@@ -377,4 +383,5 @@ Currently test suite level visibility is not used by our instrumentation: it wil
377
383
  [#183]: https://github.com/DataDog/datadog-ci-rb/issues/183
378
384
  [#185]: https://github.com/DataDog/datadog-ci-rb/issues/185
379
385
  [#189]: https://github.com/DataDog/datadog-ci-rb/issues/189
380
- [#190]: https://github.com/DataDog/datadog-ci-rb/issues/190
386
+ [#190]: https://github.com/DataDog/datadog-ci-rb/issues/190
387
+ [#193]: https://github.com/DataDog/datadog-ci-rb/issues/193
@@ -205,7 +205,7 @@ module Datadog
205
205
  end
206
206
 
207
207
  def timecop?
208
- Gem.loaded_specs.key?("timecop") || defined?(Timecop)
208
+ Gem.loaded_specs.key?("timecop") || !!defined?(Timecop)
209
209
  end
210
210
  end
211
211
  end
@@ -100,7 +100,7 @@ module Datadog
100
100
  end
101
101
 
102
102
  def ci_queue?
103
- defined?(::RSpec::Queue::ExampleExtension) &&
103
+ !!defined?(::RSpec::Queue::ExampleExtension) &&
104
104
  self.class.ancestors.include?(::RSpec::Queue::ExampleExtension)
105
105
  end
106
106
  end
@@ -42,15 +42,15 @@ module Datadog
42
42
  end
43
43
 
44
44
  def ci_queue?
45
- defined?(::RSpec::Queue::Runner)
45
+ !!defined?(::RSpec::Queue::Runner)
46
46
  end
47
47
 
48
48
  def knapsack_pro?
49
49
  knapsack_version = Gem.loaded_specs["knapsack_pro"]&.version
50
50
 
51
51
  # additional instrumentation is needed for KnapsackPro version 7 and later
52
- defined?(::KnapsackPro) &&
53
- knapsack_version && knapsack_version >= Gem::Version.new("7")
52
+ !!defined?(::KnapsackPro) &&
53
+ !knapsack_version.nil? && knapsack_version >= Gem::Version.new("7")
54
54
  end
55
55
  end
56
56
  end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "datadog/core/transport/response"
4
+ require "datadog/core/transport/ext"
5
+
6
+ require_relative "../gzip"
7
+ require_relative "../../ext/transport"
8
+
9
+ module Datadog
10
+ module CI
11
+ module Transport
12
+ module Adapters
13
+ # Adapter for Net::HTTP
14
+ class Net
15
+ attr_reader \
16
+ :hostname,
17
+ :port,
18
+ :timeout,
19
+ :ssl
20
+
21
+ def initialize(hostname:, port:, ssl:, timeout_seconds:)
22
+ @hostname = hostname
23
+ @port = port
24
+ @timeout = timeout_seconds
25
+ @ssl = ssl
26
+ end
27
+
28
+ def open(&block)
29
+ req = net_http_client.new(hostname, port)
30
+
31
+ req.use_ssl = ssl
32
+ req.open_timeout = req.read_timeout = timeout
33
+
34
+ req.start(&block)
35
+ end
36
+
37
+ def call(path:, payload:, headers:, verb:)
38
+ headers ||= {}
39
+ # skip tracing for internal DD requests
40
+ headers[Core::Transport::Ext::HTTP::HEADER_DD_INTERNAL_UNTRACED_REQUEST] = "1"
41
+
42
+ if respond_to?(verb)
43
+ send(verb, path: path, payload: payload, headers: headers)
44
+ else
45
+ raise "Unknown HTTP method [#{verb}]"
46
+ end
47
+ end
48
+
49
+ def post(path:, payload:, headers:)
50
+ post = ::Net::HTTP::Post.new(path, headers)
51
+ post.body = payload
52
+
53
+ # Connect and send the request
54
+ http_response = open do |http|
55
+ http.request(post)
56
+ end
57
+
58
+ # Build and return response
59
+ Response.new(http_response)
60
+ end
61
+
62
+ class Response
63
+ include Datadog::Core::Transport::Response
64
+
65
+ attr_reader :http_response
66
+
67
+ def initialize(http_response)
68
+ @http_response = http_response
69
+ end
70
+
71
+ def payload
72
+ return @decompressed_payload if defined?(@decompressed_payload)
73
+ return http_response.body unless gzipped_content?
74
+ return http_response.body unless gzipped_body?(http_response.body)
75
+
76
+ Datadog.logger.debug("Decompressing gzipped response payload")
77
+ @decompressed_payload = Gzip.decompress(http_response.body)
78
+ end
79
+
80
+ def header(name)
81
+ http_response[name]
82
+ end
83
+
84
+ def code
85
+ http_response.code.to_i
86
+ end
87
+
88
+ def ok?
89
+ code.between?(200, 299)
90
+ end
91
+
92
+ def unsupported?
93
+ code == 415
94
+ end
95
+
96
+ def not_found?
97
+ code == 404
98
+ end
99
+
100
+ def client_error?
101
+ code.between?(400, 499)
102
+ end
103
+
104
+ def server_error?
105
+ code.between?(500, 599)
106
+ end
107
+
108
+ def gzipped_content?
109
+ header(Ext::Transport::HEADER_CONTENT_ENCODING) == Ext::Transport::CONTENT_ENCODING_GZIP
110
+ end
111
+
112
+ def gzipped_body?(body)
113
+ return false if body.nil? || body.empty?
114
+
115
+ # no-dd-sa
116
+ first_bytes = body[0, 2]
117
+ return false if first_bytes.nil? || first_bytes.empty?
118
+
119
+ first_bytes.b == Ext::Transport::GZIP_MAGIC_NUMBER
120
+ end
121
+
122
+ def inspect
123
+ "#{super}, http_response:#{http_response}"
124
+ end
125
+ end
126
+
127
+ private
128
+
129
+ def net_http_client
130
+ return ::Net::HTTP unless defined?(WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP)
131
+
132
+ WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -37,7 +37,7 @@ module Datadog
37
37
  end
38
38
 
39
39
  def citestcov_request(path:, payload:, headers: {}, verb: "post")
40
- super(path: path, payload: payload, headers: headers, verb: verb)
40
+ super
41
41
 
42
42
  perform_request(@citestcov_http, path: path, payload: @citestcov_payload, headers: headers, verb: verb)
43
43
  end
@@ -60,7 +60,7 @@ module Datadog
60
60
 
61
61
  Datadog::CI::Transport::HTTP.new(
62
62
  host: uri.host,
63
- port: uri.port,
63
+ port: uri.port || 80,
64
64
  ssl: uri.scheme == "https" || uri.port == 443,
65
65
  compress: compress
66
66
  )
@@ -39,7 +39,7 @@ module Datadog
39
39
  end
40
40
 
41
41
  def citestcov_request(path:, payload:, headers: {}, verb: "post")
42
- super(path: path, payload: payload, headers: headers, verb: verb)
42
+ super
43
43
 
44
44
  headers[Ext::Transport::HEADER_EVP_SUBDOMAIN] = Ext::Transport::TEST_COVERAGE_INTAKE_HOST_PREFIX
45
45
 
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "delegate"
4
- require "datadog/core/transport/http/adapters/net"
5
- require "datadog/core/transport/http/env"
6
- require "datadog/core/transport/request"
7
4
  require "socket"
8
5
 
9
6
  require_relative "gzip"
7
+ require_relative "adapters/net"
10
8
  require_relative "../ext/transport"
11
9
 
12
10
  module Datadog
@@ -24,7 +22,7 @@ module Datadog
24
22
  MAX_RETRIES = 3
25
23
  INITIAL_BACKOFF = 1
26
24
 
27
- def initialize(host:, timeout: DEFAULT_TIMEOUT, port: nil, ssl: true, compress: false)
25
+ def initialize(host:, port:, timeout: DEFAULT_TIMEOUT, ssl: true, compress: false)
28
26
  @host = host
29
27
  @port = port
30
28
  @timeout = timeout
@@ -70,7 +68,7 @@ module Datadog
70
68
 
71
69
  def perform_http_call(path:, payload:, headers:, verb:, retries: MAX_RETRIES, backoff: INITIAL_BACKOFF)
72
70
  adapter.call(
73
- build_env(path: path, payload: payload, headers: headers, verb: verb)
71
+ path: path, payload: payload, headers: headers, verb: verb
74
72
  )
75
73
  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, SocketError, Net::HTTPBadResponse => e
76
74
  Datadog.logger.debug("Failed to send request with #{e} (#{e.message})")
@@ -87,65 +85,17 @@ module Datadog
87
85
  end
88
86
  end
89
87
 
90
- def build_env(path:, payload:, headers:, verb:)
91
- env = Datadog::Core::Transport::HTTP::Env.new(
92
- Datadog::Core::Transport::Request.new
93
- )
94
- env.body = payload
95
- env.path = path
96
- env.headers = headers
97
- env.verb = verb
98
- env
99
- end
100
-
101
88
  def adapter
102
- settings = AdapterSettings.new(hostname: host, port: port, ssl: ssl, timeout_seconds: timeout)
103
- @adapter ||= Datadog::Core::Transport::HTTP::Adapters::Net.new(settings)
89
+ @adapter ||= Datadog::CI::Transport::Adapters::Net.new(
90
+ hostname: host, port: port, ssl: ssl, timeout_seconds: timeout
91
+ )
104
92
  end
105
93
 
106
- # adds compatibility with Datadog::Tracing transport and
107
- # provides ungzipping capabilities
94
+ # adds compatibility with Datadog::Tracing transport
108
95
  class ResponseDecorator < ::SimpleDelegator
109
- def payload
110
- return @decompressed_payload if defined?(@decompressed_payload)
111
-
112
- if gzipped?(__getobj__.payload)
113
- Datadog.logger.debug("Decompressing gzipped response payload")
114
- @decompressed_payload = Gzip.decompress(__getobj__.payload)
115
- else
116
- __getobj__.payload
117
- end
118
- end
119
-
120
96
  def trace_count
121
97
  0
122
98
  end
123
-
124
- def gzipped?(payload)
125
- return false if payload.nil? || payload.empty?
126
-
127
- # no-dd-sa
128
- first_bytes = payload[0, 2]
129
- return false if first_bytes.nil? || first_bytes.empty?
130
-
131
- first_bytes.b == Datadog::CI::Ext::Transport::GZIP_MAGIC_NUMBER
132
- end
133
- end
134
-
135
- class AdapterSettings
136
- attr_reader :hostname, :port, :ssl, :timeout_seconds
137
-
138
- def initialize(hostname:, port: nil, ssl: true, timeout_seconds: nil)
139
- @hostname = hostname
140
- @port = port
141
- @ssl = ssl
142
- @timeout_seconds = timeout_seconds
143
- end
144
-
145
- def ==(other)
146
- hostname == other.hostname && port == other.port && ssl == other.ssl &&
147
- timeout_seconds == other.timeout_seconds
148
- end
149
99
  end
150
100
  end
151
101
  end
@@ -4,8 +4,8 @@ module Datadog
4
4
  module CI
5
5
  module VERSION
6
6
  MAJOR = 1
7
- MINOR = 0
8
- PATCH = 1
7
+ MINOR = 1
8
+ PATCH = 0
9
9
  PRE = nil
10
10
  BUILD = nil
11
11
  # PRE and BUILD above are modified for dev gems during gem build GHA workflow
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadog-ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-11 00:00:00.000000000 Z
11
+ date: 2024-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: datadog
@@ -160,6 +160,7 @@ files:
160
160
  - lib/datadog/ci/test_visibility/serializers/test_v1.rb
161
161
  - lib/datadog/ci/test_visibility/serializers/test_v2.rb
162
162
  - lib/datadog/ci/test_visibility/transport.rb
163
+ - lib/datadog/ci/transport/adapters/net.rb
163
164
  - lib/datadog/ci/transport/api/agentless.rb
164
165
  - lib/datadog/ci/transport/api/base.rb
165
166
  - lib/datadog/ci/transport/api/builder.rb
@@ -201,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
202
  - !ruby/object:Gem::Version
202
203
  version: 2.0.0
203
204
  requirements: []
204
- rubygems_version: 3.5.9
205
+ rubygems_version: 3.5.11
205
206
  signing_key:
206
207
  specification_version: 4
207
208
  summary: Datadog CI visibility for your ruby application