datadog-ci 1.5.0 → 1.6.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: 876a0e7ada3aeaf87b19dade6ee73fec0fe8d37387cde5fc31b43aaad76e99c5
4
- data.tar.gz: 8c46ad7c35a621ae03b7b42faa5b3c6934066e422ff4d3a8ac2249cd6466ecd3
3
+ metadata.gz: f38fbb3ab8e2c8c1b058d7cbefb3ac30c59cd138fb2a69929d2c7309763b0c6e
4
+ data.tar.gz: 862f8c10065b47fb8763701399de65cf0da652f36f0d301ba3b0cd4e1c12080c
5
5
  SHA512:
6
- metadata.gz: 8f312e6920cad6072665c00dc5d253e66a7c3272abda20e79f86cf11beb38fffe0be789f644affb6f8920e458f00f221c7969fb84c2ee6f2198af6a140eafc64
7
- data.tar.gz: f9b7c2b184e7a140269eaa2069cbf5062270d6bb07410fd9b46cab4c521a8d0bd694a676086164c58300c264357e53e0118611053f6bdf0c2dee757b487b4769
6
+ metadata.gz: 4be4dec3f2b5a11d0a822a3cd17d422eedab4262445dd42ba4d4efa96d4ee3f92049e5b37e1b6497928cf1fe980a847e4749538275092ca9fecd24700db3c62f
7
+ data.tar.gz: 2ebcae9e728ffd517d2c4f583808ade0170cb705967b59710213633bc73d1cd5d529c2b22323f8f70d45f657a8d848e856560aacc53c3ec7aea6e3aff45110af
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.6.0] - 2024-09-20
4
+
5
+
6
+ ### Added
7
+ * support logical names for test sessions ([#235][])
8
+ * Send internal vCPU count metric ([#236][])
9
+
3
10
  ## [1.5.0] - 2024-09-18
4
11
 
5
12
  ### Added
@@ -325,7 +332,8 @@ Currently test suite level visibility is not used by our instrumentation: it wil
325
332
 
326
333
  - Ruby versions < 2.7 no longer supported ([#8][])
327
334
 
328
- [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.5.0...main
335
+ [Unreleased]: https://github.com/DataDog/datadog-ci-rb/compare/v1.6.0...main
336
+ [1.6.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.5.0...v1.6.0
329
337
  [1.5.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.4.1...v1.5.0
330
338
  [1.4.1]: https://github.com/DataDog/datadog-ci-rb/compare/v1.4.0...v1.4.1
331
339
  [1.4.0]: https://github.com/DataDog/datadog-ci-rb/compare/v1.3.0...v1.4.0
@@ -467,4 +475,6 @@ Currently test suite level visibility is not used by our instrumentation: it wil
467
475
  [#226]: https://github.com/DataDog/datadog-ci-rb/issues/226
468
476
  [#227]: https://github.com/DataDog/datadog-ci-rb/issues/227
469
477
  [#229]: https://github.com/DataDog/datadog-ci-rb/issues/229
470
- [#231]: https://github.com/DataDog/datadog-ci-rb/issues/231
478
+ [#231]: https://github.com/DataDog/datadog-ci-rb/issues/231
479
+ [#235]: https://github.com/DataDog/datadog-ci-rb/issues/235
480
+ [#236]: https://github.com/DataDog/datadog-ci-rb/issues/236
data/README.md CHANGED
@@ -13,6 +13,7 @@ Learn more on our [official website](https://docs.datadoghq.com/tests/) and chec
13
13
  - [Test Visibility](https://docs.datadoghq.com/tests/) - collect metrics and results for your tests
14
14
  - [Intelligent test runner](https://docs.datadoghq.com/intelligent_test_runner/) - save time by selectively running only tests affected by code changes
15
15
  - [Auto test retries](https://docs.datadoghq.com/tests/auto_test_retries/?tab=ruby) - retrying failing tests up to N times to avoid failing your build due to flaky tests
16
+ - [Early flake detection](https://docs.datadoghq.com/tests/early_flake_detection?tab=ruby) - Datadog’s test flakiness solution that identifies flakes early by running newly added tests multiple times
16
17
  - [Search and manage CI tests](https://docs.datadoghq.com/tests/search/)
17
18
  - [Enhance developer workflows](https://docs.datadoghq.com/tests/developer_workflows)
18
19
  - [Flaky test management](https://docs.datadoghq.com/tests/guides/flaky_test_management/)
@@ -123,7 +123,8 @@ module Datadog
123
123
  # @type ivar @test_optimisation: Datadog::CI::TestOptimisation::Component
124
124
  @test_optimisation = build_test_optimisation(settings, test_visibility_api)
125
125
  @test_visibility = TestVisibility::Component.new(
126
- test_suite_level_visibility_enabled: !settings.ci.force_test_level_visibility
126
+ test_suite_level_visibility_enabled: !settings.ci.force_test_level_visibility,
127
+ logical_test_session_name: settings.ci.test_session_name
127
128
  )
128
129
  end
129
130
 
@@ -24,6 +24,11 @@ module Datadog
24
24
  o.default false
25
25
  end
26
26
 
27
+ option :test_session_name do |o|
28
+ o.type :string, nilable: true
29
+ o.env CI::Ext::Settings::ENV_TEST_SESSION_NAME
30
+ end
31
+
27
32
  option :agentless_mode_enabled do |o|
28
33
  o.type :bool
29
34
  o.env CI::Ext::Settings::ENV_AGENTLESS_MODE_ENABLED
@@ -19,6 +19,7 @@ module Datadog
19
19
  ENV_RETRY_FAILED_TESTS_MAX_ATTEMPTS = "DD_CIVISIBILITY_FLAKY_RETRY_COUNT"
20
20
  ENV_RETRY_FAILED_TESTS_TOTAL_LIMIT = "DD_CIVISIBILITY_TOTAL_FLAKY_RETRY_COUNT"
21
21
  ENV_RETRY_NEW_TESTS_ENABLED = "DD_CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED"
22
+ ENV_TEST_SESSION_NAME = "DD_TEST_SESSION_NAME"
22
23
 
23
24
  # Source: https://docs.datadoghq.com/getting_started/site/
24
25
  DD_SITE_ALLOWLIST = %w[
@@ -68,6 +68,12 @@ module Datadog
68
68
  TAG_SPAN_KIND = "span.kind"
69
69
  SPAN_KIND_TEST = "test"
70
70
 
71
+ # common tags that are serialized directly in msgpack header in metadata field
72
+ METADATA_TAG_TEST_SESSION_NAME = "test_session.name"
73
+
74
+ # internal metric with the number of virtual CPUs
75
+ METRIC_CPU_COUNT = "_dd.host.vcpu_count"
76
+
71
77
  # tags that are common for the whole session and can be inherited from the test session
72
78
  INHERITABLE_TAGS = [TAG_FRAMEWORK, TAG_FRAMEWORK_VERSION].freeze
73
79
 
@@ -114,6 +114,13 @@ module Datadog
114
114
  tracer_span.clear_tag(key)
115
115
  end
116
116
 
117
+ # Gets metric value by key.
118
+ # @param [String] key the key of the metric.
119
+ # @return [Numeric] value the value of the metric.
120
+ def get_metric(key)
121
+ tracer_span.get_metric(key)
122
+ end
123
+
117
124
  # Sets metric value by key.
118
125
  # @param [String] key the key of the metric.
119
126
  # @param [Numeric] value the value of the metric.
@@ -28,6 +28,24 @@ module Datadog
28
28
  get_tag(Ext::Test::TAG_COMMAND)
29
29
  end
30
30
 
31
+ # Return the test session's command used to run the tests
32
+ # @return [String] the command for this test session.
33
+ def test_command
34
+ get_tag(Ext::Test::TAG_COMMAND)
35
+ end
36
+
37
+ # Return the test session's CI provider name (e.g. "travis", "circleci", etc.)
38
+ # @return [String] the provider name for this test session.
39
+ def ci_provider
40
+ get_tag(Ext::Environment::TAG_PROVIDER_NAME)
41
+ end
42
+
43
+ # Return the test session's CI job name (e.g. "build", "test", etc.)
44
+ # @return [String] the job name for this test session.
45
+ def ci_job_name
46
+ get_tag(Ext::Environment::TAG_JOB_NAME)
47
+ end
48
+
31
49
  def skipping_tests?
32
50
  get_tag(Ext::Test::TAG_ITR_TEST_SKIPPING_ENABLED) == "true"
33
51
  end
@@ -17,15 +17,17 @@ module Datadog
17
17
  module TestVisibility
18
18
  # Common behavior for CI tests
19
19
  class Component
20
- attr_reader :test_suite_level_visibility_enabled
20
+ attr_reader :test_suite_level_visibility_enabled, :logical_test_session_name
21
21
 
22
22
  def initialize(
23
23
  test_suite_level_visibility_enabled: false,
24
- codeowners: Codeowners::Parser.new(Git::LocalRepository.root).parse
24
+ codeowners: Codeowners::Parser.new(Git::LocalRepository.root).parse,
25
+ logical_test_session_name: nil
25
26
  )
26
27
  @test_suite_level_visibility_enabled = test_suite_level_visibility_enabled
27
28
  @context = Context.new
28
29
  @codeowners = codeowners
30
+ @logical_test_session_name = logical_test_session_name
29
31
  end
30
32
 
31
33
  def start_test_session(service: nil, tags: {}, total_tests_count: 0)
@@ -152,6 +154,9 @@ module Datadog
152
154
  Telemetry.test_session_started(test_session)
153
155
  Telemetry.event_created(test_session)
154
156
 
157
+ # sets logical test session name if none provided by the user
158
+ override_logical_test_session_name!(test_session) if logical_test_session_name.nil?
159
+
155
160
  # signal Remote::Component to configure the library
156
161
  remote.configure(test_session)
157
162
  end
@@ -269,6 +274,14 @@ module Datadog
269
274
  end
270
275
  end
271
276
 
277
+ def override_logical_test_session_name!(test_session)
278
+ @logical_test_session_name = test_session.test_command
279
+ ci_job_name = test_session.ci_job_name
280
+ if ci_job_name
281
+ @logical_test_session_name = "#{ci_job_name}-#{@logical_test_session_name}"
282
+ end
283
+ end
284
+
272
285
  def test_optimisation
273
286
  Datadog.send(:components).test_optimisation
274
287
  end
@@ -11,6 +11,8 @@ require_relative "../ext/app_types"
11
11
  require_relative "../ext/environment"
12
12
  require_relative "../ext/test"
13
13
 
14
+ require_relative "../utils/test_run"
15
+
14
16
  require_relative "../span"
15
17
  require_relative "../test"
16
18
  require_relative "../test_session"
@@ -203,6 +205,8 @@ module Datadog
203
205
 
204
206
  ci_span.set_tags(tags)
205
207
  ci_span.set_tags(@environment_tags)
208
+
209
+ ci_span.set_metric(Ext::Test::METRIC_CPU_COUNT, Utils::TestRun.virtual_cpu_count)
206
210
  end
207
211
 
208
212
  # PROPAGATING CONTEXT FROM TOP-LEVEL TO THE LOWER LEVELS
@@ -53,6 +53,13 @@ module Datadog
53
53
  def remove_test_finished_callback
54
54
  end
55
55
 
56
+ def test_suite_level_visibility_enabled
57
+ false
58
+ end
59
+
60
+ def logical_test_session_name
61
+ end
62
+
56
63
  private
57
64
 
58
65
  def skip_tracing(block = nil)
@@ -34,9 +34,7 @@ module Datadog
34
34
  1,
35
35
  {
36
36
  Ext::Telemetry::TAG_AUTO_INJECTED => "false", # ruby doesn't support auto injection yet
37
- Ext::Telemetry::TAG_PROVIDER =>
38
- test_session.get_tag(Ext::Environment::TAG_PROVIDER_NAME) ||
39
- Ext::Telemetry::Provider::UNSUPPORTED
37
+ Ext::Telemetry::TAG_PROVIDER => test_session.ci_provider || Ext::Telemetry::Provider::UNSUPPORTED
40
38
  }
41
39
  )
42
40
  end
@@ -3,6 +3,7 @@
3
3
  require "datadog/core/environment/identity"
4
4
 
5
5
  require_relative "serializers/factories/test_level"
6
+ require_relative "../ext/app_types"
6
7
  require_relative "../ext/telemetry"
7
8
  require_relative "../ext/transport"
8
9
  require_relative "../transport/event_platform_transport"
@@ -51,7 +52,12 @@ module Datadog
51
52
  end
52
53
 
53
54
  def encode_span(trace, span)
54
- serializer = serializers_factory.serializer(trace, span, options: {itr_correlation_id: itr&.correlation_id})
55
+ serializer = serializers_factory.serializer(
56
+ trace,
57
+ span,
58
+ options: {itr_correlation_id: test_optimisation&.correlation_id}
59
+ )
60
+
55
61
  if serializer.valid?
56
62
  encoded = encoder.encode(serializer)
57
63
  return nil if event_too_large?(span, encoded)
@@ -75,7 +81,7 @@ module Datadog
75
81
  packer.write(1)
76
82
 
77
83
  packer.write("metadata")
78
- packer.write_map_header(1)
84
+ packer.write_map_header(1 + Ext::AppTypes::CI_SPAN_TYPES.size)
79
85
 
80
86
  packer.write("*")
81
87
  metadata_fields_count = dd_env ? 4 : 3
@@ -95,12 +101,24 @@ module Datadog
95
101
  packer.write("library_version")
96
102
  packer.write(Datadog::CI::VERSION::STRING)
97
103
 
104
+ Ext::AppTypes::CI_SPAN_TYPES.each do |ci_span_type|
105
+ packer.write(ci_span_type)
106
+ packer.write_map_header(1)
107
+
108
+ packer.write(Ext::Test::METADATA_TAG_TEST_SESSION_NAME)
109
+ packer.write(test_visibility&.logical_test_session_name)
110
+ end
111
+
98
112
  packer.write("events")
99
113
  end
100
114
 
101
- def itr
115
+ def test_optimisation
102
116
  @test_optimisation ||= Datadog::CI.send(:test_optimisation)
103
117
  end
118
+
119
+ def test_visibility
120
+ @test_visibility ||= Datadog::CI.send(:test_visibility)
121
+ end
104
122
  end
105
123
  end
106
124
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "etc"
4
+
3
5
  module Datadog
4
6
  module CI
5
7
  module Utils
@@ -34,6 +36,12 @@ module Datadog
34
36
  end
35
37
  res
36
38
  end
39
+
40
+ def self.virtual_cpu_count
41
+ return @virtual_cpu_count if defined?(@virtual_cpu_count)
42
+
43
+ @virtual_cpu_count = ::Etc.nprocessors
44
+ end
37
45
  end
38
46
  end
39
47
  end
@@ -4,7 +4,7 @@ module Datadog
4
4
  module CI
5
5
  module VERSION
6
6
  MAJOR = 1
7
- MINOR = 5
7
+ MINOR = 6
8
8
  PATCH = 0
9
9
  PRE = nil
10
10
  BUILD = nil
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.5.0
4
+ version: 1.6.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-09-18 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: datadog