Skip to content

Commit

Permalink
configure ITR runner when instantiating the CI component
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Feb 29, 2024
1 parent 1169f66 commit 7d5bb6f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
16 changes: 12 additions & 4 deletions lib/datadog/ci/configuration/components.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative "../ext/settings"
require_relative "../itr/runner"
require_relative "../test_visibility/flush"
require_relative "../test_visibility/recorder"
require_relative "../test_visibility/null_recorder"
Expand Down Expand Up @@ -59,13 +60,23 @@ def activate_ci!(settings)
writer_options[:buffer_size] = 10_000

settings.tracing.test_mode.async = true
else
# only legacy APM protocol is supported, so no test suite level visibility
settings.ci.force_test_level_visibility = true

# ITR is not supported with APM protocol
settings.ci.itr_enabled = false
end

settings.tracing.test_mode.writer_options = writer_options

itr = Datadog::CI::ITR::Runner.new(enabled: settings.ci.itr_enabled)
itr.configure

# CI visibility recorder global instance
@ci_recorder = TestVisibility::Recorder.new(
test_suite_level_visibility_enabled: !settings.ci.force_test_level_visibility
test_suite_level_visibility_enabled: !settings.ci.force_test_level_visibility,
itr: itr
)
end

Expand Down Expand Up @@ -95,9 +106,6 @@ def build_test_visibility_api(settings)
Datadog.logger.debug(
"Old agent version detected, no evp_proxy support. Forcing test level visibility mode"
)

# CI visibility is still enabled but in legacy test level visibility mode
settings.ci.force_test_level_visibility = true
end
end

Expand Down
7 changes: 6 additions & 1 deletion lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ class Recorder

def initialize(
test_suite_level_visibility_enabled: false,
codeowners: Codeowners::Parser.new(Utils::Git.root).parse
codeowners: Codeowners::Parser.new(Utils::Git.root).parse,
itr: nil
)
@test_suite_level_visibility_enabled = test_suite_level_visibility_enabled

@environment_tags = Ext::Environment.tags(ENV).freeze
@local_context = Context::Local.new
@global_context = Context::Global.new

@codeowners = codeowners

raise ArgumentError, "ITR runner is required" unless itr
@itr = itr
end

def start_test_session(service: nil, tags: {})
Expand Down
3 changes: 2 additions & 1 deletion sig/datadog/ci/test_visibility/recorder.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ module Datadog
@environment_tags: Hash[String, String]
@local_context: Datadog::CI::TestVisibility::Context::Local
@global_context: Datadog::CI::TestVisibility::Context::Global
@itr: Datadog::CI::ITR::Runner
@codeowners: Datadog::CI::Codeowners::Matcher

attr_reader environment_tags: Hash[String, String]
attr_reader test_suite_level_visibility_enabled: bool

def initialize: (?test_suite_level_visibility_enabled: bool, ?codeowners: Datadog::CI::Codeowners::Matcher) -> void
def initialize: (?test_suite_level_visibility_enabled: bool, ?codeowners: Datadog::CI::Codeowners::Matcher, ?itr: Datadog::CI::ITR::Runner?) -> void

def trace_test: (String span_name, String test_suite_name, ?service: String?, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Test span) -> untyped } -> untyped

Expand Down
29 changes: 29 additions & 0 deletions spec/datadog/ci/configuration/components_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

require_relative "../../../../lib/datadog/ci/configuration/components"

RSpec.describe Datadog::CI::Configuration::Components do
context "when used to extend Datadog::Core::Configuration::Components" do
subject(:components) do
Expand Down Expand Up @@ -50,6 +54,10 @@
.to receive(:agentless_url)
.and_return(agentless_url)

allow(settings.ci)
.to receive(:itr_enabled)
.and_return(itr_enabled)

allow(settings)
.to receive(:site)
.and_return(dd_site)
Expand Down Expand Up @@ -91,6 +99,12 @@
allow(settings.ci)
.to receive(:force_test_level_visibility=)

allow(settings.ci)
.to receive(:itr_enabled=)

allow(Datadog.logger)
.to receive(:debug)

allow(Datadog.logger)
.to receive(:warn)

Expand All @@ -110,6 +124,7 @@
let(:force_test_level_visibility) { false }
let(:evp_proxy_v2_supported) { false }
let(:evp_proxy_v4_supported) { false }
let(:itr_enabled) { false }

context "is enabled" do
let(:enabled) { true }
Expand Down Expand Up @@ -186,6 +201,10 @@
.to have_received(:force_test_level_visibility=)
.with(true)

expect(settings.ci)
.to have_received(:itr_enabled=)
.with(false)

expect(settings.tracing.test_mode).to have_received(:writer_options=) do |options|
expect(options[:transport]).to be_nil
end
Expand Down Expand Up @@ -245,6 +264,16 @@
end
end
end

context "and when itr" do
context "is enabled" do
let(:itr_enabled) { true }

it "configures ITR" do
expect(Datadog.logger).to have_received(:debug).with("Sending ITR settings request...")
end
end
end
end

context "is disabled" do
Expand Down
10 changes: 10 additions & 0 deletions spec/datadog/ci/test_visibility/recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
end
end

describe "#initialize" do
context "no ITR runner is provided" do
subject { described_class.new }

it "raises an error" do
expect { subject }.to raise_error(ArgumentError, "ITR runner is required")
end
end
end

context "when test suite level visibility is disabled" do
let(:service) { "my-service" }
let(:tags) { {"test.framework" => "my-framework", "my.tag" => "my_value"} }
Expand Down

0 comments on commit 7d5bb6f

Please sign in to comment.