-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e67e2c
commit 8b3c39f
Showing
5 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,7 +86,7 @@ module EventType | |
end | ||
|
||
module Library | ||
BUILTIN = "builtin" | ||
CUSTOM = "custom" | ||
end | ||
|
||
module Endpoint | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../ext/telemetry" | ||
require_relative "../ext/test" | ||
require_relative "../utils/telemetry" | ||
|
||
module Datadog | ||
module CI | ||
module TestOptimisation | ||
# Telemetry for test optimisation component | ||
module Telemetry | ||
def self.code_coverage_started(test) | ||
Utils::Telemetry.inc(Ext::Telemetry::METRIC_CODE_COVERAGE_STARTED, 1, tags_for_test(test)) | ||
end | ||
|
||
def self.code_coverage_finished(test) | ||
Utils::Telemetry.inc(Ext::Telemetry::METRIC_CODE_COVERAGE_FINISHED, 1, tags_for_test(test)) | ||
end | ||
|
||
def self.code_coverage_is_empty | ||
Utils::Telemetry.inc(Ext::Telemetry::METRIC_CODE_COVERAGE_IS_EMPTY, 1) | ||
end | ||
|
||
def self.code_coverage_files(count) | ||
Utils::Telemetry.distribution(Ext::Telemetry::METRIC_CODE_COVERAGE_FILES, count.to_f) | ||
end | ||
|
||
def self.code_coverage_errors | ||
Utils::Telemetry.inc(Ext::Telemetry::METRIC_CODE_COVERAGE_ERRORS, 1) | ||
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 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,7 @@ module Datadog | |
end | ||
|
||
module Library | ||
BUILTIN: "builtin" | ||
CUSTOM: "custom" | ||
end | ||
|
||
module Endpoint | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Datadog | ||
module CI | ||
module TestOptimisation | ||
module Telemetry | ||
def self.code_coverage_started: (Datadog::CI::Test test) -> void | ||
|
||
def self.code_coverage_finished: (Datadog::CI::Test test) -> void | ||
|
||
def self.code_coverage_is_empty: () -> void | ||
|
||
def self.code_coverage_files: (Integer count) -> void | ||
|
||
def self.code_coverage_errors: () -> void | ||
|
||
def self.tags_for_test: (Datadog::CI::Test test) -> ::Hash[String, String] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../../../lib/datadog/ci/test_optimisation/telemetry" | ||
|
||
RSpec.describe Datadog::CI::TestOptimisation::Telemetry do | ||
describe ".code_coverage_started" do | ||
subject(:code_coverage_started) { described_class.code_coverage_started(test) } | ||
|
||
before do | ||
expect(Datadog::CI::Utils::Telemetry).to receive(:inc) | ||
.with(Datadog::CI::Ext::Telemetry::METRIC_CODE_COVERAGE_STARTED, 1, expected_tags) | ||
end | ||
|
||
let(:test) do | ||
Datadog::Tracing::SpanOperation.new( | ||
"test", | ||
type: Datadog::CI::Ext::AppTypes::TYPE_TEST, | ||
tags: { | ||
Datadog::CI::Ext::Test::TAG_FRAMEWORK => "rspec" | ||
} | ||
) | ||
end | ||
|
||
let(:expected_tags) do | ||
{ | ||
Datadog::CI::Ext::Telemetry::TAG_TEST_FRAMEWORK => "rspec", | ||
Datadog::CI::Ext::Telemetry::TAG_LIBRARY => Datadog::CI::Ext::Telemetry::Library::CUSTOM | ||
} | ||
end | ||
|
||
it { code_coverage_started } | ||
end | ||
|
||
describe ".code_coverage_finished" do | ||
subject(:code_coverage_finished) { described_class.code_coverage_finished(test) } | ||
|
||
before do | ||
expect(Datadog::CI::Utils::Telemetry).to receive(:inc) | ||
.with(Datadog::CI::Ext::Telemetry::METRIC_CODE_COVERAGE_FINISHED, 1, expected_tags) | ||
end | ||
|
||
let(:test) do | ||
Datadog::Tracing::SpanOperation.new( | ||
"test", | ||
type: Datadog::CI::Ext::AppTypes::TYPE_TEST, | ||
tags: { | ||
Datadog::CI::Ext::Test::TAG_FRAMEWORK => "rspec" | ||
} | ||
) | ||
end | ||
|
||
let(:expected_tags) do | ||
{ | ||
Datadog::CI::Ext::Telemetry::TAG_TEST_FRAMEWORK => "rspec", | ||
Datadog::CI::Ext::Telemetry::TAG_LIBRARY => Datadog::CI::Ext::Telemetry::Library::CUSTOM | ||
} | ||
end | ||
|
||
it { code_coverage_finished } | ||
end | ||
|
||
describe ".code_coverage_is_empty" do | ||
subject(:code_coverage_is_empty) { described_class.code_coverage_is_empty } | ||
|
||
before do | ||
expect(Datadog::CI::Utils::Telemetry).to receive(:inc) | ||
.with(Datadog::CI::Ext::Telemetry::METRIC_CODE_COVERAGE_IS_EMPTY, 1) | ||
end | ||
|
||
it { code_coverage_is_empty } | ||
end | ||
|
||
describe ".code_coverage_files" do | ||
subject(:code_coverage_files) { described_class.code_coverage_files(count) } | ||
|
||
let(:count) { 42 } | ||
|
||
before do | ||
expect(Datadog::CI::Utils::Telemetry).to receive(:distribution) | ||
.with(Datadog::CI::Ext::Telemetry::METRIC_CODE_COVERAGE_FILES, count.to_f) | ||
end | ||
|
||
it { code_coverage_files } | ||
end | ||
|
||
describe ".code_coverage_errors" do | ||
subject(:code_coverage_errors) { described_class.code_coverage_errors } | ||
|
||
before do | ||
expect(Datadog::CI::Utils::Telemetry).to receive(:inc) | ||
.with(Datadog::CI::Ext::Telemetry::METRIC_CODE_COVERAGE_ERRORS, 1) | ||
end | ||
|
||
it { code_coverage_errors } | ||
end | ||
end |