datadog-ci 1.0.0.beta3 → 1.0.0.beta4

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: 335897204d48926d8c0e3ab1ef8e7c6247a88b12627e27e021614f1b368ab788
4
- data.tar.gz: db5b4ac716d7e0f28712cb7fef86c1f438f2a8b5fa28af0bb67ef91d3758d1c0
3
+ metadata.gz: 035d75d50e0e09c7895bc0e434c5ac1e0655618763ac724a94989833e0c07d61
4
+ data.tar.gz: bfbd5d6ff101ef51e59d3546d110f906f178c23602241f85b3a8b413524a9900
5
5
  SHA512:
6
- metadata.gz: c2ebd289964298131bed28406316a48992aaec8e54a6fb21f58ffb6c3d2c523f49fbc5aedf83c9f72a5b8ba45c54cce6df46b8d83eae6ce42804a8901954b61c
7
- data.tar.gz: dd1fcd1c56179c0ab933d166801f69cb843efe67449ad69e7491ee674ff3325fcb9b1adb814881a80137d24de6fa264103ad02d71b73c814acf84a56b706a707
6
+ metadata.gz: c1b6463b913cbff1e20a2c3f4fcaa6c47814ba693eee5682fa41c3baa74f9e92414b4e554ec8407807d6eeb1744f0c76d87bb0889bd0e639c6ebdc3de1dcd180
7
+ data.tar.gz: dca4568f30dbaef22e8fac94389e682beb21ba6f92f0578553ff01d2ad289f38d33f899c79bef604f3f83906d6c31b9e64a9495cc3dc986fb321bd810430780d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0.beta4] - 2024-05-14
4
+
5
+ ### Added
6
+
7
+ * Knapsack Pro 7/RSpec 3 support ([#172][])
8
+ * add settings option to ignore code coverage for bundled gems location ([#174][])
9
+ * log an error message if tracing is disabled but test visibility is enabled ([#175][])
10
+
11
+ ### Removed
12
+
13
+ * remove deprecated use alias ([#173][])
14
+
3
15
  ## [1.0.0.beta3] - 2024-04-30
4
16
 
5
17
  ### Added
@@ -226,7 +238,8 @@ Currently test suite level visibility is not used by our instrumentation: it wil
226
238
 
227
239
  - Ruby versions < 2.7 no longer supported ([#8][])
228
240
 
229
- [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v0.8.3...main
241
+ [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.0.beta4...main
242
+ [1.0.0.beta4]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.0.beta3...v1.0.0.beta4
230
243
  [1.0.0.beta3]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.0.beta2...v1.0.0.beta3
231
244
  [1.0.0.beta2]: https://github.com/DataDog/datadog-ci-rb/compare/v1.0.0.beta1...v1.0.0.beta2
232
245
  [1.0.0.beta1]: https://github.com/DataDog/datadog-ci-rb/compare/v0.8.3...v1.0.0.beta1
@@ -321,3 +334,7 @@ Currently test suite level visibility is not used by our instrumentation: it wil
321
334
  [#166]: https://github.com/DataDog/datadog-ci-rb/issues/166
322
335
  [#167]: https://github.com/DataDog/datadog-ci-rb/issues/167
323
336
  [#168]: https://github.com/DataDog/datadog-ci-rb/issues/168
337
+ [#172]: https://github.com/DataDog/datadog-ci-rb/issues/172
338
+ [#173]: https://github.com/DataDog/datadog-ci-rb/issues/173
339
+ [#174]: https://github.com/DataDog/datadog-ci-rb/issues/174
340
+ [#175]: https://github.com/DataDog/datadog-ci-rb/issues/175
@@ -5,10 +5,35 @@
5
5
  #define DD_COV_TARGET_FILES 1
6
6
  #define DD_COV_TARGET_LINES 2
7
7
 
8
+ static int is_prefix(VALUE prefix, const char *str)
9
+ {
10
+ if (prefix == Qnil)
11
+ {
12
+ return 0;
13
+ }
14
+
15
+ const char *c_prefix = RSTRING_PTR(prefix);
16
+ if (c_prefix == NULL)
17
+ {
18
+ return 0;
19
+ }
20
+
21
+ long prefix_len = RSTRING_LEN(prefix);
22
+ if (strncmp(c_prefix, str, prefix_len) == 0)
23
+ {
24
+ return 1;
25
+ }
26
+ else
27
+ {
28
+ return 0;
29
+ }
30
+ }
31
+
8
32
  // Data structure
9
33
  struct dd_cov_data
10
34
  {
11
35
  VALUE root;
36
+ VALUE ignored_path;
12
37
  int mode;
13
38
  VALUE coverage;
14
39
  };
@@ -18,6 +43,7 @@ static void dd_cov_mark(void *ptr)
18
43
  struct dd_cov_data *dd_cov_data = ptr;
19
44
  rb_gc_mark_movable(dd_cov_data->coverage);
20
45
  rb_gc_mark_movable(dd_cov_data->root);
46
+ rb_gc_mark_movable(dd_cov_data->ignored_path);
21
47
  }
22
48
 
23
49
  static void dd_cov_free(void *ptr)
@@ -32,6 +58,7 @@ static void dd_cov_compact(void *ptr)
32
58
  struct dd_cov_data *dd_cov_data = ptr;
33
59
  dd_cov_data->coverage = rb_gc_location(dd_cov_data->coverage);
34
60
  dd_cov_data->root = rb_gc_location(dd_cov_data->root);
61
+ dd_cov_data->ignored_path = rb_gc_location(dd_cov_data->ignored_path);
35
62
  }
36
63
 
37
64
  const rb_data_type_t dd_cov_data_type = {
@@ -49,6 +76,7 @@ static VALUE dd_cov_allocate(VALUE klass)
49
76
  VALUE obj = TypedData_Make_Struct(klass, struct dd_cov_data, &dd_cov_data_type, dd_cov_data);
50
77
  dd_cov_data->coverage = rb_hash_new();
51
78
  dd_cov_data->root = Qnil;
79
+ dd_cov_data->ignored_path = Qnil;
52
80
  dd_cov_data->mode = DD_COV_TARGET_FILES;
53
81
  return obj;
54
82
  }
@@ -66,6 +94,8 @@ static VALUE dd_cov_initialize(int argc, VALUE *argv, VALUE self)
66
94
  rb_raise(rb_eArgError, "root is required");
67
95
  }
68
96
 
97
+ VALUE rb_ignored_path = rb_hash_lookup(opt, ID2SYM(rb_intern("ignored_path")));
98
+
69
99
  VALUE rb_mode = rb_hash_lookup(opt, ID2SYM(rb_intern("mode")));
70
100
  if (!RTEST(rb_mode) || rb_mode == ID2SYM(rb_intern("files")))
71
101
  {
@@ -84,6 +114,7 @@ static VALUE dd_cov_initialize(int argc, VALUE *argv, VALUE self)
84
114
  TypedData_Get_Struct(self, struct dd_cov_data, &dd_cov_data_type, dd_cov_data);
85
115
 
86
116
  dd_cov_data->root = rb_root;
117
+ dd_cov_data->ignored_path = rb_ignored_path;
87
118
  dd_cov_data->mode = mode;
88
119
 
89
120
  return Qnil;
@@ -100,20 +131,15 @@ static void dd_cov_update_line_coverage(rb_event_flag_t event, VALUE data, VALUE
100
131
  return;
101
132
  }
102
133
 
103
- if (dd_cov_data->root == Qnil)
134
+ // if given filename is not located under the root, we skip it
135
+ if (is_prefix(dd_cov_data->root, filename) == 0)
104
136
  {
105
137
  return;
106
138
  }
107
139
 
108
- char *c_root = RSTRING_PTR(dd_cov_data->root);
109
- if (c_root == NULL)
110
- {
111
- return;
112
- }
113
- long root_len = RSTRING_LEN(dd_cov_data->root);
114
- // check that root is a prefix of the filename
115
- // so this file is located under the given root
116
- if (strncmp(c_root, filename, root_len) != 0)
140
+ // if ignored_path is provided and given filename is located under the ignored_path, we skip it too
141
+ // this is useful for ignoring bundled gems location
142
+ if (RTEST(dd_cov_data->ignored_path) && is_prefix(dd_cov_data->ignored_path, filename) == 1)
117
143
  {
118
144
  return;
119
145
  }
@@ -43,6 +43,16 @@ module Datadog
43
43
  end
44
44
 
45
45
  def activate_ci!(settings)
46
+ unless settings.tracing.enabled
47
+ Datadog.logger.error(
48
+ "CI visibility requires tracing to be enabled. Disabling CI visibility. " \
49
+ "NOTE: if you didn't disable tracing intentionally, add `c.tracing.enabled = true` to " \
50
+ "your Datadog.configure block."
51
+ )
52
+ settings.ci.enabled = false
53
+ return
54
+ end
55
+
46
56
  # Configure ddtrace library for CI visibility mode
47
57
  # Deactivate telemetry
48
58
  settings.telemetry.enabled = false
@@ -107,7 +117,8 @@ module Datadog
107
117
  dd_env: settings.env,
108
118
  config_tags: custom_configuration_tags,
109
119
  coverage_writer: coverage_writer,
110
- enabled: settings.ci.enabled && settings.ci.itr_enabled
120
+ enabled: settings.ci.enabled && settings.ci.itr_enabled,
121
+ bundle_location: settings.ci.itr_code_coverage_excluded_bundle_path
111
122
  )
112
123
 
113
124
  git_tree_uploader = Git::TreeUploader.new(api: test_visibility_api)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../ext/settings"
4
+ require_relative "../utils/bundle"
4
5
 
5
6
  module Datadog
6
7
  module CI
@@ -67,6 +68,14 @@ module Datadog
67
68
  o.default true
68
69
  end
69
70
 
71
+ option :itr_code_coverage_excluded_bundle_path do |o|
72
+ o.type :string, nilable: true
73
+ o.env CI::Ext::Settings::ENV_ITR_CODE_COVERAGE_EXCLUDED_BUNDLE_PATH
74
+ o.default do
75
+ Datadog::CI::Utils::Bundle.location
76
+ end
77
+ end
78
+
70
79
  define_method(:instrument) do |integration_name, options = {}, &block|
71
80
  return unless enabled
72
81
 
@@ -89,9 +98,6 @@ module Datadog
89
98
  fetch_integration(integration_name).configuration
90
99
  end
91
100
 
92
- # @deprecated Will be removed on datadog-ci-rb 1.0.
93
- alias_method :use, :instrument
94
-
95
101
  option :trace_flush
96
102
 
97
103
  option :writer_options do |o|
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "knapsack_pro/extensions/rspec_extension"
4
+
5
+ require_relative "runner"
6
+
7
+ module Datadog
8
+ module CI
9
+ module Contrib
10
+ module RSpec
11
+ # Instrument RSpec::Core::Example
12
+ module KnapsackPro
13
+ module Extension
14
+ def self.included(base)
15
+ base.singleton_class.prepend(ClassMethods)
16
+ end
17
+
18
+ module ClassMethods
19
+ def setup!
20
+ super
21
+
22
+ ::RSpec::Core::Runner.include(Datadog::CI::Contrib::RSpec::KnapsackPro::Runner)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../ext/test"
4
+ require_relative "../ext"
5
+
6
+ module Datadog
7
+ module CI
8
+ module Contrib
9
+ module RSpec
10
+ module KnapsackPro
11
+ module Runner
12
+ def self.included(base)
13
+ base.prepend(InstanceMethods)
14
+ end
15
+
16
+ module InstanceMethods
17
+ def knapsack__run_specs(*)
18
+ return super unless datadog_configuration[:enabled]
19
+
20
+ test_session = CI.start_test_session(
21
+ tags: {
22
+ CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
23
+ CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::RSpec::Integration.version.to_s
24
+ },
25
+ service: datadog_configuration[:service_name]
26
+ )
27
+
28
+ test_module = CI.start_test_module(Ext::FRAMEWORK)
29
+
30
+ result = super
31
+ return result unless test_module && test_session
32
+
33
+ if result != 0
34
+ test_module.failed!
35
+ test_session.failed!
36
+ else
37
+ test_module.passed!
38
+ test_session.passed!
39
+ end
40
+ test_module.finish
41
+ test_session.finish
42
+
43
+ result
44
+ end
45
+
46
+ private
47
+
48
+ def datadog_configuration
49
+ Datadog.configuration.ci[:rspec]
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -21,19 +21,35 @@ module Datadog
21
21
  end
22
22
 
23
23
  def patch
24
+ # ci-queue test runner instrumentation
25
+ # https://github.com/Shopify/ci-queue
24
26
  if ci_queue?
25
27
  ::RSpec::Queue::Runner.include(Runner)
26
28
  end
27
29
 
30
+ # Knapsack Pro test runner instrumentation
31
+ # https://github.com/KnapsackPro/knapsack_pro-ruby
32
+ if knapsack_pro?
33
+ require_relative "knapsack_pro/extension"
34
+ ::KnapsackPro::Extensions::RSpecExtension.include(KnapsackPro::Extension)
35
+ end
36
+
28
37
  ::RSpec::Core::Runner.include(Runner)
29
38
  ::RSpec::Core::Example.include(Example)
30
39
  ::RSpec::Core::ExampleGroup.include(ExampleGroup)
31
40
  end
32
41
 
33
42
  def ci_queue?
34
- # ::RSpec::Queue::Runner is a ci-queue runner
35
43
  defined?(::RSpec::Queue::Runner)
36
44
  end
45
+
46
+ def knapsack_pro?
47
+ knapsack_version = Gem.loaded_specs["knapsack_pro"]&.version
48
+
49
+ # additional instrumentation is needed for KnapsackPro version 7 and later
50
+ defined?(::KnapsackPro) &&
51
+ knapsack_version && knapsack_version >= Gem::Version.new("7")
52
+ end
37
53
  end
38
54
  end
39
55
  end
@@ -23,6 +23,11 @@ module Datadog
23
23
  TAG_NODE_NAME = "ci.node.name"
24
24
  TAG_CI_ENV_VARS = "_dd.ci.env_vars"
25
25
 
26
+ POSSIBLE_BUNDLE_LOCATIONS = [
27
+ "vendor/bundle",
28
+ ".bundle"
29
+ ].freeze
30
+
26
31
  module_function
27
32
 
28
33
  def tags(env)
@@ -12,6 +12,7 @@ module Datadog
12
12
  ENV_FORCE_TEST_LEVEL_VISIBILITY = "DD_CIVISIBILITY_FORCE_TEST_LEVEL_VISIBILITY"
13
13
  ENV_ITR_ENABLED = "DD_CIVISIBILITY_ITR_ENABLED"
14
14
  ENV_GIT_METADATA_UPLOAD_ENABLED = "DD_CIVISIBILITY_GIT_METADATA_UPLOAD_ENABLED"
15
+ ENV_ITR_CODE_COVERAGE_EXCLUDED_BUNDLE_PATH = "DD_CIVISIBILITY_ITR_CODE_COVERAGE_EXCLUDED_BUNDLE_PATH"
15
16
 
16
17
  # Source: https://docs.datadoghq.com/getting_started/site/
17
18
  DD_SITE_ALLOWLIST = [
@@ -30,20 +30,27 @@ module Datadog
30
30
  config_tags: {},
31
31
  api: nil,
32
32
  coverage_writer: nil,
33
- enabled: false
33
+ enabled: false,
34
+ bundle_location: nil
34
35
  )
35
36
  @enabled = enabled
36
37
  @api = api
37
38
  @dd_env = dd_env
38
39
  @config_tags = config_tags || {}
39
40
 
41
+ @bundle_location = if bundle_location && !File.absolute_path?(bundle_location)
42
+ File.join(Git::LocalRepository.root, bundle_location)
43
+ else
44
+ bundle_location
45
+ end
46
+
40
47
  @test_skipping_enabled = false
41
48
  @code_coverage_enabled = false
42
49
 
43
50
  @coverage_writer = coverage_writer
44
51
 
45
52
  @correlation_id = nil
46
- @skippable_tests = []
53
+ @skippable_tests = Set.new
47
54
 
48
55
  @skipped_tests_count = 0
49
56
  @mutex = Mutex.new
@@ -177,7 +184,10 @@ module Datadog
177
184
  end
178
185
 
179
186
  def coverage_collector
180
- Thread.current[:dd_coverage_collector] ||= Coverage::DDCov.new(root: Git::LocalRepository.root)
187
+ Thread.current[:dd_coverage_collector] ||= Coverage::DDCov.new(
188
+ root: Git::LocalRepository.root,
189
+ ignored_path: @bundle_location
190
+ )
181
191
  end
182
192
 
183
193
  def load_datadog_cov!
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../ext/environment"
4
+ require_relative "../git/local_repository"
5
+
6
+ module Datadog
7
+ module CI
8
+ module Utils
9
+ module Bundle
10
+ def self.location
11
+ require "bundler"
12
+ bundle_path = Bundler.bundle_path.to_s
13
+ bundle_path if bundle_path&.start_with?(Datadog::CI::Git::LocalRepository.root)
14
+ rescue => e
15
+ Datadog.logger.warn("Failed to find bundled gems location: #{e}")
16
+
17
+ Ext::Environment::POSSIBLE_BUNDLE_LOCATIONS.each do |location|
18
+ path = File.join(Datadog::CI::Git::LocalRepository.root, location)
19
+ return path if File.directory?(path)
20
+ end
21
+ nil
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -6,7 +6,7 @@ module Datadog
6
6
  MAJOR = "1"
7
7
  MINOR = "0"
8
8
  PATCH = "0"
9
- PRE = "beta3"
9
+ PRE = "beta4"
10
10
  BUILD = nil
11
11
  # PRE and BUILD above are modified for dev gems during gem build GHA workflow
12
12
 
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.0.beta3
4
+ version: 1.0.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-30 00:00:00.000000000 Z
11
+ date: 2024-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: datadog
@@ -88,6 +88,8 @@ files:
88
88
  - lib/datadog/ci/contrib/rspec/example_group.rb
89
89
  - lib/datadog/ci/contrib/rspec/ext.rb
90
90
  - lib/datadog/ci/contrib/rspec/integration.rb
91
+ - lib/datadog/ci/contrib/rspec/knapsack_pro/extension.rb
92
+ - lib/datadog/ci/contrib/rspec/knapsack_pro/runner.rb
91
93
  - lib/datadog/ci/contrib/rspec/patcher.rb
92
94
  - lib/datadog/ci/contrib/rspec/runner.rb
93
95
  - lib/datadog/ci/contrib/settings.rb
@@ -156,6 +158,7 @@ files:
156
158
  - lib/datadog/ci/transport/gzip.rb
157
159
  - lib/datadog/ci/transport/http.rb
158
160
  - lib/datadog/ci/transport/remote_settings_api.rb
161
+ - lib/datadog/ci/utils/bundle.rb
159
162
  - lib/datadog/ci/utils/configuration.rb
160
163
  - lib/datadog/ci/utils/git.rb
161
164
  - lib/datadog/ci/utils/parsing.rb
@@ -170,7 +173,7 @@ metadata:
170
173
  changelog_uri: https://github.com/DataDog/datadog-ci-rb/blob/main/CHANGELOG.md
171
174
  homepage_uri: https://github.com/DataDog/datadog-ci-rb
172
175
  source_code_uri: https://github.com/DataDog/datadog-ci-rb
173
- post_install_message:
176
+ post_install_message:
174
177
  rdoc_options: []
175
178
  require_paths:
176
179
  - lib
@@ -188,8 +191,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
191
  - !ruby/object:Gem::Version
189
192
  version: 2.0.0
190
193
  requirements: []
191
- rubygems_version: 3.5.9
192
- signing_key:
194
+ rubygems_version: 3.4.19
195
+ signing_key:
193
196
  specification_version: 4
194
197
  summary: Datadog CI visibility for your ruby application
195
198
  test_files: []