Skip to content

Commit

Permalink
implement ITR metrics for internal telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 26, 2024
1 parent c5c2e56 commit 9cd40ca
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/datadog/ci/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "json"

require_relative "span"
require_relative "test_optimisation/telemetry"
require_relative "utils/test_run"

module Datadog
Expand Down Expand Up @@ -80,9 +81,13 @@ def skipped_by_itr?
#
# @return [void]
def itr_unskippable!
TestOptimisation::Telemetry.itr_unskippable
set_tag(Ext::Test::TAG_ITR_UNSKIPPABLE, "true")

if skipped_by_itr?
clear_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR)

TestOptimisation::Telemetry.itr_forced_run
set_tag(Ext::Test::TAG_ITR_FORCED_RUN, "true")
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/ci/test_optimisation/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def count_skipped_test(test)
end

@mutex.synchronize do
Telemetry.itr_skipped

@skipped_tests_count += 1
end
end
Expand Down
6 changes: 6 additions & 0 deletions sig/datadog/ci/test_optimisation/telemetry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module Datadog

def self.code_coverage_files: (Integer count) -> void

def self.itr_skipped: () -> void

def self.itr_forced_run: () -> void

def self.itr_unskippable: () -> void

def self.tags_for_test: (Datadog::CI::Test test) -> ::Hash[String, String]

def self.tags_for_itr_metrics: () -> ::Hash[String, String]
Expand Down
2 changes: 2 additions & 0 deletions spec/datadog/ci/test_optimisation/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@
.from(0)
.to(1)
end

it_behaves_like "emits telemetry metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_ITR_SKIPPED, 1
end

context "test is not skipped" do
Expand Down
21 changes: 14 additions & 7 deletions spec/datadog/ci/test_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

RSpec.describe Datadog::CI::Test do
include_context "Telemetry spy"

let(:tracer_span) { instance_double(Datadog::Tracing::SpanOperation, finish: true) }
let(:test_visibility) { spy("test_visibility") }
subject(:ci_test) { described_class.new(tracer_span) }
Expand Down Expand Up @@ -120,30 +122,35 @@
end

describe "#itr_unskippable!" do
subject { ci_test.itr_unskippable! }

context "when test is not skipped by ITR" do
before do
allow(ci_test).to receive(:skipped_by_itr?).and_return(false)
expect(tracer_span).to receive(:set_tag).with(Datadog::CI::Ext::Test::TAG_ITR_UNSKIPPABLE, "true")
end

it "sets unskippable tag" do
expect(tracer_span).to receive(:set_tag).with(Datadog::CI::Ext::Test::TAG_ITR_UNSKIPPABLE, "true")

ci_test.itr_unskippable!
subject
end

it_behaves_like "emits telemetry metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_ITR_UNSKIPPABLE, 1
end

context "when test is skipped by ITR" do
before do
allow(ci_test).to receive(:skipped_by_itr?).and_return(true)
end

it "sets unskippable tag, removes skipped by ITR tag, and sets forced run tag" do
expect(tracer_span).to receive(:set_tag).with(Datadog::CI::Ext::Test::TAG_ITR_UNSKIPPABLE, "true")
expect(tracer_span).to receive(:clear_tag).with(Datadog::CI::Ext::Test::TAG_ITR_SKIPPED_BY_ITR)
expect(tracer_span).to receive(:set_tag).with(Datadog::CI::Ext::Test::TAG_ITR_FORCED_RUN, "true")
end

ci_test.itr_unskippable!
it "sets unskippable tag, removes skipped by ITR tag, and sets forced run tag" do
subject
end

it_behaves_like "emits telemetry metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_ITR_UNSKIPPABLE, 1
it_behaves_like "emits telemetry metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_ITR_FORCED_RUN, 1
end
end

Expand Down

0 comments on commit 9cd40ca

Please sign in to comment.