Skip to content

Commit

Permalink
Test visibility serializer factory and serializers accept options has…
Browse files Browse the repository at this point in the history
…h that will be used for storing ITR correlation id
  • Loading branch information
anmarchenko committed Apr 24, 2024
1 parent d0cfdc9 commit de33d47
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 40 deletions.
5 changes: 3 additions & 2 deletions lib/datadog/ci/test_visibility/serializers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ class Base
"duration"
].freeze

attr_reader :trace, :span, :meta
attr_reader :trace, :span, :meta, :options

def initialize(trace, span)
def initialize(trace, span, options: {})
@trace = trace
@span = span
@options = options

@meta = @span.meta.reject { |key, _| Ext::Test::TRANSIENT_TAGS.include?(key) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module Factories
module TestLevel
module_function

def serializer(trace, span)
def serializer(trace, span, options: {})
case span.type
when Datadog::CI::Ext::AppTypes::TYPE_TEST
Serializers::TestV1.new(trace, span)
Serializers::TestV1.new(trace, span, options: options)
else
Serializers::Span.new(trace, span)
Serializers::Span.new(trace, span, options: options)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ module Factories
module TestSuiteLevel
module_function

def serializer(trace, span)
def serializer(trace, span, options: {})
case span.type
when Datadog::CI::Ext::AppTypes::TYPE_TEST
Serializers::TestV2.new(trace, span)
Serializers::TestV2.new(trace, span, options: options)
when Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION
Serializers::TestSession.new(trace, span)
Serializers::TestSession.new(trace, span, options: options)
when Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE
Serializers::TestModule.new(trace, span)
Serializers::TestModule.new(trace, span, options: options)
when Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE
Serializers::TestSuite.new(trace, span)
Serializers::TestSuite.new(trace, span, options: options)
else
Serializers::Span.new(trace, span)
Serializers::Span.new(trace, span, options: options)
end
end
end
Expand Down
14 changes: 10 additions & 4 deletions sig/datadog/ci/test_visibility/serializers/base.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ module Datadog
CONTENT_FIELDS: Array[String | Hash[String, String]]
REQUIRED_FIELDS: Array[String]

@content_fields_count: Integer
@start: Integer
@duration: Integer
@trace: Datadog::Tracing::TraceSegment
@span: Datadog::Tracing::Span
@options: Hash[Symbol, untyped]

@meta: Hash[untyped, untyped]
@errors: Hash[String, Set[String]]
@validated: bool

@content_fields_count: Integer
@start: Integer
@duration: Integer

attr_reader trace: Datadog::Tracing::TraceSegment
attr_reader span: Datadog::Tracing::Span
attr_reader meta: Hash[untyped, untyped]
attr_reader options: Hash[Symbol, untyped]

def initialize: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span) -> void
def initialize: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span, ?options: Hash[Symbol, untyped]) -> void

def to_msgpack: (?untyped? packer) -> untyped

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Datadog
module Serializers
module Factories
module TestLevel
def self?.serializer: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span) -> Datadog::CI::TestVisibility::Serializers::Base
def self?.serializer: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span, ?options: Hash[Symbol, untyped]) -> Datadog::CI::TestVisibility::Serializers::Base
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Datadog
module Serializers
module Factories
module TestSuiteLevel
def self?.serializer: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span) -> Datadog::CI::TestVisibility::Serializers::Base
def self?.serializer: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span, ?options: Hash[Symbol, untyped]) -> Datadog::CI::TestVisibility::Serializers::Base
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,45 @@
produce_test_session_trace(with_http_span: true)
end

subject { described_class.serializer(trace_for_span(ci_span), ci_span) }

describe ".convert_trace_to_serializable_events" do
context "with a session span" do
let(:ci_span) { test_session_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSession) }
end

context "with a module span" do
let(:ci_span) { test_module_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestModule) }
end

context "with a suite span" do
let(:ci_span) { first_test_suite_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSuite) }
context "without options" do
subject { described_class.serializer(trace_for_span(ci_span), ci_span) }

describe ".convert_trace_to_serializable_events" do
context "with a session span" do
let(:ci_span) { test_session_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSession) }
end

context "with a module span" do
let(:ci_span) { test_module_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestModule) }
end

context "with a suite span" do
let(:ci_span) { first_test_suite_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSuite) }
end

context "with a test span" do
let(:ci_span) { first_test_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestV2) }
end

context "with a http request span" do
let(:ci_span) { first_custom_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::Span) }
end
end
end

context "with a test span" do
let(:ci_span) { first_test_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestV2) }
end
context "with options" do
let(:ci_span) { first_test_span }
subject { described_class.serializer(trace_for_span(ci_span), ci_span, options: {custom: "option"}) }

context "with a http request span" do
let(:ci_span) { first_custom_span }
it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::Span) }
describe ".serializer" do
it "passes options to the serializer" do
expect(subject.options).to eq({custom: "option"})
end
end
end
end

0 comments on commit de33d47

Please sign in to comment.