Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIVIS-9014] implement "why this test was skipped" feature by adding ITR correlation to test events #165

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Test visibility serializer factory and serializers accept options has…
…h that will be used for storing ITR correlation id
anmarchenko committed Apr 24, 2024
commit de33d477fdf369b2005dbe0c1c7fc5fc4812f001
5 changes: 3 additions & 2 deletions lib/datadog/ci/test_visibility/serializers/base.rb
Original file line number Diff line number Diff line change
@@ -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) }

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions sig/datadog/ci/test_visibility/serializers/base.rbs
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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