datadog-ci 1.0.0.beta1 → 1.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +37 -46
- data/lib/datadog/ci/configuration/components.rb +43 -9
- data/lib/datadog/ci/configuration/settings.rb +6 -0
- data/lib/datadog/ci/contrib/cucumber/formatter.rb +9 -7
- data/lib/datadog/ci/contrib/cucumber/patcher.rb +3 -0
- data/lib/datadog/ci/contrib/cucumber/step.rb +27 -0
- data/lib/datadog/ci/contrib/minitest/hooks.rb +4 -2
- data/lib/datadog/ci/contrib/rspec/example.rb +9 -5
- data/lib/datadog/ci/ext/environment/providers/local_git.rb +8 -79
- data/lib/datadog/ci/ext/environment.rb +11 -16
- data/lib/datadog/ci/ext/settings.rb +1 -0
- data/lib/datadog/ci/ext/test.rb +5 -0
- data/lib/datadog/ci/ext/transport.rb +8 -0
- data/lib/datadog/ci/git/local_repository.rb +238 -0
- data/lib/datadog/ci/git/packfiles.rb +70 -0
- data/lib/datadog/ci/git/search_commits.rb +77 -0
- data/lib/datadog/ci/git/tree_uploader.rb +90 -0
- data/lib/datadog/ci/git/upload_packfile.rb +66 -0
- data/lib/datadog/ci/git/user.rb +29 -0
- data/lib/datadog/ci/itr/coverage/event.rb +18 -1
- data/lib/datadog/ci/itr/coverage/writer.rb +108 -0
- data/lib/datadog/ci/itr/runner.rb +120 -11
- data/lib/datadog/ci/itr/skippable.rb +106 -0
- data/lib/datadog/ci/span.rb +9 -0
- data/lib/datadog/ci/test.rb +19 -12
- data/lib/datadog/ci/test_module.rb +2 -2
- data/lib/datadog/ci/test_session.rb +2 -2
- data/lib/datadog/ci/test_suite.rb +2 -2
- data/lib/datadog/ci/test_visibility/null_recorder.rb +4 -1
- data/lib/datadog/ci/test_visibility/recorder.rb +47 -9
- data/lib/datadog/ci/test_visibility/transport.rb +1 -1
- data/lib/datadog/ci/transport/http.rb +24 -4
- data/lib/datadog/ci/transport/remote_settings_api.rb +12 -6
- data/lib/datadog/ci/utils/configuration.rb +2 -2
- data/lib/datadog/ci/utils/git.rb +6 -67
- data/lib/datadog/ci/utils/parsing.rb +16 -0
- data/lib/datadog/ci/utils/test_run.rb +13 -0
- data/lib/datadog/ci/version.rb +1 -1
- data/lib/datadog/ci/worker.rb +35 -0
- data/lib/datadog/ci.rb +4 -0
- metadata +15 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b3e03ab226d98aac3dd518b1c554452a4c3812cb67e9a1d64762e2fe8767633
|
4
|
+
data.tar.gz: eac352d2b2488d16f979004f617097efe109364069f1c7b78cecfceef5365efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56ab91025f2a224e86bd732a5c891e961af184b29618241f8853756780ccba894c11955b00020a70139d72e47f57d22dfdf1f2ed6437f1d4e4a9d998453d7a4
|
7
|
+
data.tar.gz: e7c1aa73096d8d8b49800bbed168f288b7676d8fa328011c3e9c4f7024c86c17cf2c210a94a64dcd80f94121a80b36a824f0ca4e3aa6ccb1c35f682a1fb9e18b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.0.0.beta2] - 2024-04-23
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
* Code coverage events writer ([#150])
|
8
|
+
* Git tree upload - git command line integration ([#151])
|
9
|
+
* Add Git::SearchCommits api client ([#152])
|
10
|
+
* Upload packfiles API client ([#153])
|
11
|
+
* Git tree uploader ([#154])
|
12
|
+
* Git repository unshallowing logic ([#155])
|
13
|
+
* Git upload async worker ([#156])
|
14
|
+
* Reduce ITR-induced code coverage overhead for default branch ([#157])
|
15
|
+
* Skippable tests api client ([#158])
|
16
|
+
* Request skippable tests when configuring ITR ([#159])
|
17
|
+
* Test skipping implementation ([#160])
|
18
|
+
|
3
19
|
## [1.0.0.beta1] - 2024-03-25
|
4
20
|
|
5
21
|
### Added
|
@@ -199,6 +215,7 @@ Currently test suite level visibility is not used by our instrumentation: it wil
|
|
199
215
|
* Ruby versions < 2.7 no longer supported ([#8][])
|
200
216
|
|
201
217
|
[Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v0.8.3...main
|
218
|
+
[1.0.0.beta2]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.0.beta1...v1.0.0.beta2
|
202
219
|
[1.0.0.beta1]: https://github.com/DataDog/datadog-ci-rb/compare/v0.8.3...v1.0.0.beta1
|
203
220
|
[0.8.3]: https://github.com/DataDog/datadog-ci-rb/compare/v0.8.2...v0.8.3
|
204
221
|
[0.8.2]: https://github.com/DataDog/datadog-ci-rb/compare/v0.8.1...v0.8.2
|
@@ -276,3 +293,14 @@ Currently test suite level visibility is not used by our instrumentation: it wil
|
|
276
293
|
[#142]: https://github.com/DataDog/datadog-ci-rb/issues/142
|
277
294
|
[#145]: https://github.com/DataDog/datadog-ci-rb/issues/145
|
278
295
|
[#148]: https://github.com/DataDog/datadog-ci-rb/issues/148
|
296
|
+
[#150]: https://github.com/DataDog/datadog-ci-rb/issues/150
|
297
|
+
[#151]: https://github.com/DataDog/datadog-ci-rb/issues/151
|
298
|
+
[#152]: https://github.com/DataDog/datadog-ci-rb/issues/152
|
299
|
+
[#153]: https://github.com/DataDog/datadog-ci-rb/issues/153
|
300
|
+
[#154]: https://github.com/DataDog/datadog-ci-rb/issues/154
|
301
|
+
[#155]: https://github.com/DataDog/datadog-ci-rb/issues/155
|
302
|
+
[#156]: https://github.com/DataDog/datadog-ci-rb/issues/156
|
303
|
+
[#157]: https://github.com/DataDog/datadog-ci-rb/issues/157
|
304
|
+
[#158]: https://github.com/DataDog/datadog-ci-rb/issues/158
|
305
|
+
[#159]: https://github.com/DataDog/datadog-ci-rb/issues/159
|
306
|
+
[#160]: https://github.com/DataDog/datadog-ci-rb/issues/160
|
data/README.md
CHANGED
@@ -18,6 +18,10 @@ group :test do
|
|
18
18
|
end
|
19
19
|
```
|
20
20
|
|
21
|
+
## Upgrade from ddtrace v1.x
|
22
|
+
|
23
|
+
If you used [test visibility for Ruby](https://docs.datadoghq.com/tests/setup/ruby/) with [ddtrace](https://github.com/datadog/dd-trace-rb) gem, check out our [upgrade guide](/docs/UpgradeGuide.md).
|
24
|
+
|
21
25
|
## Usage
|
22
26
|
|
23
27
|
### RSpec
|
@@ -31,25 +35,14 @@ require 'datadog/ci'
|
|
31
35
|
# Only activates test instrumentation on CI
|
32
36
|
if ENV["DD_ENV"] == "ci"
|
33
37
|
Datadog.configure do |c|
|
34
|
-
# Configures the tracer to ensure results delivery
|
35
|
-
c.ci.enabled = true
|
36
|
-
|
37
38
|
# The name of the service or library under test
|
38
39
|
c.service = 'my-ruby-app'
|
39
|
-
|
40
|
-
|
41
|
-
c.ci.instrument :rspec, **options
|
40
|
+
c.ci.enabled = true
|
41
|
+
c.ci.instrument :rspec
|
42
42
|
end
|
43
43
|
end
|
44
44
|
```
|
45
45
|
|
46
|
-
`options` are the following keyword arguments:
|
47
|
-
|
48
|
-
| Key | Description | Default |
|
49
|
-
| --- | ----------- | ------- |
|
50
|
-
| `enabled` | Defines whether RSpec tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
|
51
|
-
| `service_name` | Service name used for `rspec` instrumentation. | `'rspec'` |
|
52
|
-
|
53
46
|
### Minitest
|
54
47
|
|
55
48
|
The Minitest integration will trace all executions of tests when using `minitest` test framework.
|
@@ -64,13 +57,10 @@ require 'datadog/ci'
|
|
64
57
|
if ENV["DD_ENV"] == "ci"
|
65
58
|
# Configure default Minitest integration
|
66
59
|
Datadog.configure do |c|
|
67
|
-
# Configures the tracer to ensure results delivery
|
68
|
-
c.ci.enabled = true
|
69
|
-
|
70
60
|
# The name of the service or library under test
|
71
61
|
c.service = 'my-ruby-app'
|
72
|
-
|
73
|
-
c.ci.instrument :minitest
|
62
|
+
c.ci.enabled = true
|
63
|
+
c.ci.instrument :minitest
|
74
64
|
end
|
75
65
|
end
|
76
66
|
```
|
@@ -87,20 +77,13 @@ require 'minitest/autorun'
|
|
87
77
|
|
88
78
|
if ENV["DD_ENV"] == "ci"
|
89
79
|
Datadog.configure do |c|
|
90
|
-
c.ci.enabled = true
|
91
80
|
c.service = 'my-ruby-app'
|
81
|
+
c.ci.enabled = true
|
92
82
|
c.ci.instrument :minitest
|
93
83
|
end
|
94
84
|
end
|
95
85
|
```
|
96
86
|
|
97
|
-
`options` are the following keyword arguments:
|
98
|
-
|
99
|
-
| Key | Description | Default |
|
100
|
-
| --- | ----------- | ------- |
|
101
|
-
| `enabled` | Defines whether Minitest tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
|
102
|
-
| `service_name` | Service name used for `minitest` instrumentation. | `'minitest'` |
|
103
|
-
|
104
87
|
### Cucumber
|
105
88
|
|
106
89
|
Activate `Cucumber` integration with configuration
|
@@ -112,24 +95,31 @@ require 'datadog/ci'
|
|
112
95
|
# Only activates test instrumentation on CI
|
113
96
|
if ENV["DD_ENV"] == "ci"
|
114
97
|
Datadog.configure do |c|
|
115
|
-
# Configures the tracer to ensure results delivery
|
116
|
-
c.ci.enabled = true
|
117
|
-
|
118
98
|
# The name of the service or library under test
|
119
99
|
c.service = 'my-ruby-app'
|
120
|
-
|
121
|
-
|
122
|
-
c.ci.instrument :cucumber, **options
|
100
|
+
c.ci.enabled = true
|
101
|
+
c.ci.instrument :cucumber
|
123
102
|
end
|
124
103
|
end
|
125
104
|
```
|
126
105
|
|
127
|
-
|
106
|
+
### Instrumentation options
|
107
|
+
|
108
|
+
Configuration `ci.instrument` accepts the following optional parameters:
|
128
109
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
110
|
+
- `enabled` (default: `true`) - defines whether tests should be traced (useful for temporarily disabling tracing)
|
111
|
+
- `service_name` - name of the service or library under test (when you want it to be different for a test framework)
|
112
|
+
|
113
|
+
Example usage:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
Datadog.configure do |c|
|
117
|
+
c.service = 'my-ruby-app'
|
118
|
+
c.ci.enabled = true
|
119
|
+
c.ci.instrument :cucumber, service_name: 'my-cucumber-features', enabled: true
|
120
|
+
c.ci.instrument :minitest, service_name: 'my-unit-tests', enabled: false
|
121
|
+
end
|
122
|
+
```
|
133
123
|
|
134
124
|
## Agentless mode
|
135
125
|
|
@@ -154,7 +144,7 @@ or other external calls like here:
|
|
154
144
|
|
155
145
|
![Test trace with redis instrumented](./docs/screenshots/test-trace-with-redis.png)
|
156
146
|
|
157
|
-
|
147
|
+
To achieve this, add Datadog tracing instrumentations in your `Datadog.configure` block:
|
158
148
|
|
159
149
|
```ruby
|
160
150
|
Datadog.configure do |c|
|
@@ -167,13 +157,13 @@ end
|
|
167
157
|
...or enable auto instrumentation in your test_helper/spec_helper:
|
168
158
|
|
169
159
|
```ruby
|
170
|
-
require "
|
160
|
+
require "datadog/auto_instrument"
|
171
161
|
```
|
172
162
|
|
173
163
|
Note: in CI mode these traces are going to be submitted to CI Visibility,
|
174
164
|
they will **not** show up in Datadog APM.
|
175
165
|
|
176
|
-
For the full list of available instrumentations see [
|
166
|
+
For the full list of available instrumentations see [datadog documentation](https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md)
|
177
167
|
|
178
168
|
### WebMock
|
179
169
|
|
@@ -187,8 +177,7 @@ Webmock accordingly.
|
|
187
177
|
|
188
178
|
```ruby
|
189
179
|
# when using agentless mode
|
190
|
-
|
191
|
-
WebMock.disable_net_connect!(:allow => /datadoghq.com/)
|
180
|
+
WebMock.disable_net_connect!(:allow => /datadoghq/)
|
192
181
|
|
193
182
|
# when using agent
|
194
183
|
WebMock.disable_net_connect!(:allow_localhost => true)
|
@@ -211,8 +200,10 @@ VCR.configure do |config|
|
|
211
200
|
config.ignore_hosts "127.0.0.1", "localhost"
|
212
201
|
|
213
202
|
# when using agentless mode
|
214
|
-
|
215
|
-
|
203
|
+
config.ignore_request do |request|
|
204
|
+
# ignore all requests to datadoghq hosts
|
205
|
+
request.uri =~ /datadoghq/
|
206
|
+
end
|
216
207
|
end
|
217
208
|
```
|
218
209
|
|
@@ -220,7 +211,7 @@ end
|
|
220
211
|
|
221
212
|
Startup logs produce a report of tracing state when the application is initially configured.
|
222
213
|
These logs are activated by default in test mode, if you don't want them you can disable this
|
223
|
-
via `
|
214
|
+
via `DD_TRACE_STARTUP_LOGS=0` or in the `Datadog.configure` block:
|
224
215
|
|
225
216
|
```ruby
|
226
217
|
Datadog.configure { |c| c.diagnostics.startup_logs.enabled = false }
|
@@ -230,7 +221,7 @@ Datadog.configure { |c| c.diagnostics.startup_logs.enabled = false }
|
|
230
221
|
|
231
222
|
Switching the library into debug mode will produce verbose, detailed logs about tracing activity, including any suppressed errors. This output can be helpful in identifying errors, confirming trace output, or catching HTTP transport issues.
|
232
223
|
|
233
|
-
You can enable this via `
|
224
|
+
You can enable this via `DD_TRACE_DEBUG=1` or in the `Datadog.configure` block:
|
234
225
|
|
235
226
|
```ruby
|
236
227
|
Datadog.configure { |c| c.diagnostics.debug = true }
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "../ext/settings"
|
4
|
+
require_relative "../git/tree_uploader"
|
4
5
|
require_relative "../itr/runner"
|
6
|
+
require_relative "../itr/coverage/transport"
|
7
|
+
require_relative "../itr/coverage/writer"
|
5
8
|
require_relative "../test_visibility/flush"
|
6
9
|
require_relative "../test_visibility/recorder"
|
7
10
|
require_relative "../test_visibility/null_recorder"
|
@@ -10,25 +13,34 @@ require_relative "../test_visibility/serializers/factories/test_suite_level"
|
|
10
13
|
require_relative "../test_visibility/transport"
|
11
14
|
require_relative "../transport/api/builder"
|
12
15
|
require_relative "../transport/remote_settings_api"
|
16
|
+
require_relative "../worker"
|
13
17
|
|
14
18
|
module Datadog
|
15
19
|
module CI
|
16
20
|
module Configuration
|
17
21
|
# Adds CI behavior to Datadog trace components
|
18
22
|
module Components
|
19
|
-
attr_reader :ci_recorder
|
23
|
+
attr_reader :ci_recorder, :itr
|
20
24
|
|
21
25
|
def initialize(settings)
|
22
26
|
# Activate CI mode if enabled
|
23
27
|
if settings.ci.enabled
|
24
28
|
activate_ci!(settings)
|
25
29
|
else
|
30
|
+
@itr = nil
|
26
31
|
@ci_recorder = TestVisibility::NullRecorder.new
|
27
32
|
end
|
28
33
|
|
29
34
|
super
|
30
35
|
end
|
31
36
|
|
37
|
+
def shutdown!(replacement = nil)
|
38
|
+
super
|
39
|
+
|
40
|
+
@ci_recorder&.shutdown!
|
41
|
+
@itr&.shutdown!
|
42
|
+
end
|
43
|
+
|
32
44
|
def activate_ci!(settings)
|
33
45
|
# Configure ddtrace library for CI visibility mode
|
34
46
|
# Deactivate telemetry
|
@@ -49,10 +61,17 @@ module Datadog
|
|
49
61
|
|
50
62
|
# transport creation
|
51
63
|
writer_options = settings.ci.writer_options
|
64
|
+
coverage_writer = nil
|
52
65
|
test_visibility_api = build_test_visibility_api(settings)
|
53
66
|
|
54
67
|
if test_visibility_api
|
55
|
-
|
68
|
+
# setup writer for code coverage payloads
|
69
|
+
coverage_writer = ITR::Coverage::Writer.new(
|
70
|
+
transport: ITR::Coverage::Transport.new(api: test_visibility_api)
|
71
|
+
)
|
72
|
+
|
73
|
+
# configure tracing writer to send traces to CI visibility backend
|
74
|
+
writer_options[:transport] = TestVisibility::Transport.new(
|
56
75
|
api: test_visibility_api,
|
57
76
|
serializers_factory: serializers_factory(settings),
|
58
77
|
dd_env: settings.env
|
@@ -71,21 +90,36 @@ module Datadog
|
|
71
90
|
|
72
91
|
settings.tracing.test_mode.writer_options = writer_options
|
73
92
|
|
74
|
-
itr = Datadog::CI::ITR::Runner.new(
|
75
|
-
enabled: settings.ci.enabled && settings.ci.itr_enabled
|
76
|
-
)
|
77
|
-
|
78
93
|
remote_settings_api = Transport::RemoteSettingsApi.new(
|
79
94
|
api: test_visibility_api,
|
80
95
|
dd_env: settings.env
|
81
96
|
)
|
82
97
|
|
98
|
+
itr = ITR::Runner.new(
|
99
|
+
api: test_visibility_api,
|
100
|
+
dd_env: settings.env,
|
101
|
+
coverage_writer: coverage_writer,
|
102
|
+
enabled: settings.ci.enabled && settings.ci.itr_enabled
|
103
|
+
)
|
104
|
+
|
105
|
+
git_tree_uploader = Git::TreeUploader.new(api: test_visibility_api)
|
106
|
+
git_tree_upload_worker = if settings.ci.git_metadata_upload_enabled
|
107
|
+
Worker.new do |repository_url|
|
108
|
+
git_tree_uploader.call(repository_url)
|
109
|
+
end
|
110
|
+
else
|
111
|
+
DummyWorker.new
|
112
|
+
end
|
113
|
+
|
83
114
|
# CI visibility recorder global instance
|
84
115
|
@ci_recorder = TestVisibility::Recorder.new(
|
85
116
|
test_suite_level_visibility_enabled: !settings.ci.force_test_level_visibility,
|
86
117
|
itr: itr,
|
87
|
-
remote_settings_api: remote_settings_api
|
118
|
+
remote_settings_api: remote_settings_api,
|
119
|
+
git_tree_upload_worker: git_tree_upload_worker
|
88
120
|
)
|
121
|
+
|
122
|
+
@itr = itr
|
89
123
|
end
|
90
124
|
|
91
125
|
def build_test_visibility_api(settings)
|
@@ -122,9 +156,9 @@ module Datadog
|
|
122
156
|
|
123
157
|
def serializers_factory(settings)
|
124
158
|
if settings.ci.force_test_level_visibility
|
125
|
-
|
159
|
+
TestVisibility::Serializers::Factories::TestLevel
|
126
160
|
else
|
127
|
-
|
161
|
+
TestVisibility::Serializers::Factories::TestSuiteLevel
|
128
162
|
end
|
129
163
|
end
|
130
164
|
|
@@ -61,6 +61,12 @@ module Datadog
|
|
61
61
|
o.default false
|
62
62
|
end
|
63
63
|
|
64
|
+
option :git_metadata_upload_enabled do |o|
|
65
|
+
o.type :bool
|
66
|
+
o.env CI::Ext::Settings::ENV_GIT_METADATA_UPLOAD_ENABLED
|
67
|
+
o.default true
|
68
|
+
end
|
69
|
+
|
64
70
|
define_method(:instrument) do |integration_name, options = {}, &block|
|
65
71
|
return unless enabled
|
66
72
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "../../ext/test"
|
4
|
-
require_relative "../../
|
4
|
+
require_relative "../../git/local_repository"
|
5
|
+
require_relative "../../utils/test_run"
|
5
6
|
require_relative "ext"
|
6
7
|
|
7
8
|
module Datadog
|
@@ -55,25 +56,26 @@ module Datadog
|
|
55
56
|
def on_test_case_started(event)
|
56
57
|
test_suite_name = test_suite_name(event.test_case)
|
57
58
|
|
59
|
+
# @type var tags: Hash[String, String]
|
58
60
|
tags = {
|
59
61
|
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
|
60
62
|
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Cucumber::Integration.version.to_s,
|
61
|
-
CI::Ext::Test::TAG_SOURCE_FILE =>
|
63
|
+
CI::Ext::Test::TAG_SOURCE_FILE => Git::LocalRepository.relative_to_root(event.test_case.location.file),
|
62
64
|
CI::Ext::Test::TAG_SOURCE_START => event.test_case.location.line.to_s
|
63
65
|
}
|
64
66
|
|
67
|
+
if (parameters = extract_parameters_hash(event.test_case))
|
68
|
+
tags[CI::Ext::Test::TAG_PARAMETERS] = Utils::TestRun.test_parameters(arguments: parameters)
|
69
|
+
end
|
70
|
+
|
65
71
|
start_test_suite(test_suite_name) unless same_test_suite_as_current?(test_suite_name)
|
66
72
|
|
67
|
-
|
73
|
+
CI.start_test(
|
68
74
|
event.test_case.name,
|
69
75
|
test_suite_name,
|
70
76
|
tags: tags,
|
71
77
|
service: configuration[:service_name]
|
72
78
|
)
|
73
|
-
|
74
|
-
if (parameters = extract_parameters_hash(event.test_case))
|
75
|
-
test_span&.set_parameters(parameters)
|
76
|
-
end
|
77
79
|
end
|
78
80
|
|
79
81
|
def on_test_case_finished(event)
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "datadog/tracing/contrib/patcher"
|
4
|
+
|
4
5
|
require_relative "instrumentation"
|
6
|
+
require_relative "step"
|
5
7
|
|
6
8
|
module Datadog
|
7
9
|
module CI
|
@@ -19,6 +21,7 @@ module Datadog
|
|
19
21
|
|
20
22
|
def patch
|
21
23
|
::Cucumber::Runtime.include(Instrumentation)
|
24
|
+
::Cucumber::Core::Test::Step.include(Datadog::CI::Contrib::Cucumber::Step)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module CI
|
5
|
+
module Contrib
|
6
|
+
module Cucumber
|
7
|
+
# instruments Cucumber::Core::Test::Step from cucumber-ruby-core to change
|
8
|
+
module Step
|
9
|
+
def self.included(base)
|
10
|
+
base.prepend(InstanceMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module InstanceMethods
|
14
|
+
def execute(*args)
|
15
|
+
test_span = CI.active_test
|
16
|
+
if test_span&.skipped_by_itr?
|
17
|
+
@action.skip(*args)
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "../../ext/test"
|
4
|
+
require_relative "../../git/local_repository"
|
4
5
|
require_relative "ext"
|
5
6
|
require_relative "helpers"
|
6
7
|
|
@@ -24,17 +25,18 @@ module Datadog
|
|
24
25
|
|
25
26
|
source_file, line_number = method(name).source_location
|
26
27
|
|
27
|
-
CI.start_test(
|
28
|
+
test_span = CI.start_test(
|
28
29
|
name,
|
29
30
|
test_suite_name,
|
30
31
|
tags: {
|
31
32
|
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
|
32
33
|
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::Minitest::Integration.version.to_s,
|
33
|
-
CI::Ext::Test::TAG_SOURCE_FILE =>
|
34
|
+
CI::Ext::Test::TAG_SOURCE_FILE => Git::LocalRepository.relative_to_root(source_file),
|
34
35
|
CI::Ext::Test::TAG_SOURCE_START => line_number.to_s
|
35
36
|
},
|
36
37
|
service: datadog_configuration[:service_name]
|
37
38
|
)
|
39
|
+
skip(CI::Ext::Test::ITR_TEST_SKIP_REASON) if test_span&.skipped_by_itr?
|
38
40
|
end
|
39
41
|
|
40
42
|
def after_teardown
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "../../ext/test"
|
4
|
-
require_relative "../../
|
4
|
+
require_relative "../../git/local_repository"
|
5
|
+
require_relative "../../utils/test_run"
|
5
6
|
require_relative "ext"
|
6
7
|
|
7
8
|
module Datadog
|
@@ -41,14 +42,17 @@ module Datadog
|
|
41
42
|
tags: {
|
42
43
|
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
|
43
44
|
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::RSpec::Integration.version.to_s,
|
44
|
-
CI::Ext::Test::TAG_SOURCE_FILE =>
|
45
|
-
CI::Ext::Test::TAG_SOURCE_START => metadata[:line_number].to_s
|
45
|
+
CI::Ext::Test::TAG_SOURCE_FILE => Git::LocalRepository.relative_to_root(metadata[:file_path]),
|
46
|
+
CI::Ext::Test::TAG_SOURCE_START => metadata[:line_number].to_s,
|
47
|
+
CI::Ext::Test::TAG_PARAMETERS => Utils::TestRun.test_parameters(
|
48
|
+
metadata: {"scoped_id" => metadata[:scoped_id]}
|
49
|
+
)
|
46
50
|
},
|
47
51
|
service: datadog_configuration[:service_name]
|
48
52
|
) do |test_span|
|
49
|
-
|
53
|
+
metadata[:skip] = CI::Ext::Test::ITR_TEST_SKIP_REASON if test_span&.skipped_by_itr?
|
50
54
|
|
51
|
-
|
55
|
+
result = super
|
52
56
|
|
53
57
|
case execution_result.status
|
54
58
|
when :passed
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "base"
|
4
|
-
require_relative "../../../
|
4
|
+
require_relative "../../../git/local_repository"
|
5
5
|
|
6
6
|
module Datadog
|
7
7
|
module CI
|
@@ -11,48 +11,23 @@ module Datadog
|
|
11
11
|
# As a fallback we try to fetch git information from the local git repository
|
12
12
|
class LocalGit < Base
|
13
13
|
def git_repository_url
|
14
|
-
|
15
|
-
rescue => e
|
16
|
-
Datadog.logger.debug(
|
17
|
-
"Unable to read git repository url: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
18
|
-
)
|
19
|
-
nil
|
14
|
+
CI::Git::LocalRepository.git_repository_url
|
20
15
|
end
|
21
16
|
|
22
17
|
def git_commit_sha
|
23
|
-
|
24
|
-
rescue => e
|
25
|
-
Datadog.logger.debug(
|
26
|
-
"Unable to read git commit SHA: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
27
|
-
)
|
28
|
-
nil
|
18
|
+
CI::Git::LocalRepository.git_commit_sha
|
29
19
|
end
|
30
20
|
|
31
21
|
def git_branch
|
32
|
-
|
33
|
-
rescue => e
|
34
|
-
Datadog.logger.debug(
|
35
|
-
"Unable to read git branch: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
36
|
-
)
|
37
|
-
nil
|
22
|
+
CI::Git::LocalRepository.git_branch
|
38
23
|
end
|
39
24
|
|
40
25
|
def git_tag
|
41
|
-
|
42
|
-
rescue => e
|
43
|
-
Datadog.logger.debug(
|
44
|
-
"Unable to read git tag: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
45
|
-
)
|
46
|
-
nil
|
26
|
+
CI::Git::LocalRepository.git_tag
|
47
27
|
end
|
48
28
|
|
49
29
|
def git_commit_message
|
50
|
-
|
51
|
-
rescue => e
|
52
|
-
Datadog.logger.debug(
|
53
|
-
"Unable to read git commit message: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
54
|
-
)
|
55
|
-
nil
|
30
|
+
CI::Git::LocalRepository.git_commit_message
|
56
31
|
end
|
57
32
|
|
58
33
|
def git_commit_author_name
|
@@ -80,12 +55,7 @@ module Datadog
|
|
80
55
|
end
|
81
56
|
|
82
57
|
def workspace_path
|
83
|
-
|
84
|
-
rescue => e
|
85
|
-
Datadog.logger.debug(
|
86
|
-
"Unable to read git base directory: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
87
|
-
)
|
88
|
-
nil
|
58
|
+
CI::Git::LocalRepository.git_root
|
89
59
|
end
|
90
60
|
|
91
61
|
private
|
@@ -105,48 +75,7 @@ module Datadog
|
|
105
75
|
end
|
106
76
|
|
107
77
|
def set_git_commit_users
|
108
|
-
|
109
|
-
output = Utils::Git.exec_git_command("git show -s --format='%an\t%ae\t%at\t%cn\t%ce\t%ct'")
|
110
|
-
unless output
|
111
|
-
Datadog.logger.debug(
|
112
|
-
"Unable to read git commit users: git command output is nil"
|
113
|
-
)
|
114
|
-
@author = @committer = NilUser.new
|
115
|
-
return
|
116
|
-
end
|
117
|
-
|
118
|
-
author_name, author_email, author_timestamp,
|
119
|
-
committer_name, committer_email, committer_timestamp = output.split("\t").each(&:strip!)
|
120
|
-
|
121
|
-
@author = GitUser.new(author_name, author_email, author_timestamp)
|
122
|
-
@committer = GitUser.new(committer_name, committer_email, committer_timestamp)
|
123
|
-
rescue => e
|
124
|
-
Datadog.logger.debug(
|
125
|
-
"Unable to read git commit users: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
126
|
-
)
|
127
|
-
@author = @committer = NilUser.new
|
128
|
-
end
|
129
|
-
|
130
|
-
class GitUser
|
131
|
-
attr_reader :name, :email, :timestamp
|
132
|
-
|
133
|
-
def initialize(name, email, timestamp)
|
134
|
-
@name = name
|
135
|
-
@email = email
|
136
|
-
@timestamp = timestamp
|
137
|
-
end
|
138
|
-
|
139
|
-
def date
|
140
|
-
return nil if timestamp.nil?
|
141
|
-
|
142
|
-
Time.at(timestamp.to_i).utc.to_datetime.iso8601
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
class NilUser < GitUser
|
147
|
-
def initialize
|
148
|
-
super(nil, nil, nil)
|
149
|
-
end
|
78
|
+
@author, @committer = CI::Git::LocalRepository.git_commit_users
|
150
79
|
end
|
151
80
|
end
|
152
81
|
end
|