diff --git a/lib/datadog/ci/test_optimisation/telemetry.rb b/lib/datadog/ci/test_optimisation/telemetry.rb index 05ef6dde..8c37b3cf 100644 --- a/lib/datadog/ci/test_optimisation/telemetry.rb +++ b/lib/datadog/ci/test_optimisation/telemetry.rb @@ -3,6 +3,7 @@ require_relative "../ext/telemetry" require_relative "../ext/test" require_relative "../utils/telemetry" +require_relative "../test_visibility/telemetry" module Datadog module CI @@ -25,12 +26,30 @@ def self.code_coverage_files(count) Utils::Telemetry.distribution(Ext::Telemetry::METRIC_CODE_COVERAGE_FILES, count.to_f) end + def self.itr_skipped + Utils::Telemetry.inc(Ext::Telemetry::METRIC_ITR_SKIPPED, 1, tags_for_itr_metrics) + end + + def self.itr_forced_run + Utils::Telemetry.inc(Ext::Telemetry::METRIC_ITR_FORCED_RUN, 1, tags_for_itr_metrics) + end + + def self.itr_unskippable + Utils::Telemetry.inc(Ext::Telemetry::METRIC_ITR_UNSKIPPABLE, 1, tags_for_itr_metrics) + end + def self.tags_for_test(test) { Ext::Telemetry::TAG_TEST_FRAMEWORK => test.get_tag(Ext::Test::TAG_FRAMEWORK), Ext::Telemetry::TAG_LIBRARY => Ext::Telemetry::Library::CUSTOM } end + + def self.tags_for_itr_metrics + { + Ext::Telemetry::TAG_EVENT_TYPE => Ext::Telemetry::EventType::TEST + } + end end end end diff --git a/sig/datadog/ci/test_optimisation/telemetry.rbs b/sig/datadog/ci/test_optimisation/telemetry.rbs index 3263719f..d5f9f3c6 100644 --- a/sig/datadog/ci/test_optimisation/telemetry.rbs +++ b/sig/datadog/ci/test_optimisation/telemetry.rbs @@ -11,6 +11,8 @@ module Datadog def self.code_coverage_files: (Integer count) -> void def self.tags_for_test: (Datadog::CI::Test test) -> ::Hash[String, String] + + def self.tags_for_itr_metrics: () -> ::Hash[String, String] end end end diff --git a/spec/datadog/ci/test_optimisation/telemetry_spec.rb b/spec/datadog/ci/test_optimisation/telemetry_spec.rb index 5a76cb5d..91ff6692 100644 --- a/spec/datadog/ci/test_optimisation/telemetry_spec.rb +++ b/spec/datadog/ci/test_optimisation/telemetry_spec.rb @@ -82,4 +82,55 @@ it { code_coverage_files } end + + describe ".itr_skipped" do + subject(:itr_skipped) { described_class.itr_skipped } + + before do + expect(Datadog::CI::Utils::Telemetry).to receive(:inc) + .with(Datadog::CI::Ext::Telemetry::METRIC_ITR_SKIPPED, 1, expected_tags) + end + + let(:expected_tags) do + { + Datadog::CI::Ext::Telemetry::TAG_EVENT_TYPE => Datadog::CI::Ext::Telemetry::EventType::TEST + } + end + + it { itr_skipped } + end + + describe ".itr_forced_run" do + subject(:itr_forced_run) { described_class.itr_forced_run } + + before do + expect(Datadog::CI::Utils::Telemetry).to receive(:inc) + .with(Datadog::CI::Ext::Telemetry::METRIC_ITR_FORCED_RUN, 1, expected_tags) + end + + let(:expected_tags) do + { + Datadog::CI::Ext::Telemetry::TAG_EVENT_TYPE => Datadog::CI::Ext::Telemetry::EventType::TEST + } + end + + it { itr_forced_run } + end + + describe ".itr_unskippable" do + subject(:itr_unskippable) { described_class.itr_unskippable } + + before do + expect(Datadog::CI::Utils::Telemetry).to receive(:inc) + .with(Datadog::CI::Ext::Telemetry::METRIC_ITR_UNSKIPPABLE, 1, expected_tags) + end + + let(:expected_tags) do + { + Datadog::CI::Ext::Telemetry::TAG_EVENT_TYPE => Datadog::CI::Ext::Telemetry::EventType::TEST + } + end + + it { itr_unskippable } + end end