Skip to content

Commit

Permalink
helpers for ITR metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 26, 2024
1 parent 5c61e76 commit c5c2e56
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/datadog/ci/test_optimisation/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/test_optimisation/telemetry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions spec/datadog/ci/test_optimisation/telemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c5c2e56

Please sign in to comment.