From d3a50716ee81095d8324628814d8e11aed599c4e Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 30 Jul 2024 10:27:55 +0200 Subject: [PATCH 1/3] constants for provider tags --- lib/datadog/ci/ext/environment.rb | 17 +++++++++++++++++ .../ci/ext/environment/providers/appveyor.rb | 2 +- .../environment/providers/aws_code_pipeline.rb | 2 +- .../ci/ext/environment/providers/azure.rb | 2 +- .../ci/ext/environment/providers/bitbucket.rb | 2 +- .../ci/ext/environment/providers/bitrise.rb | 2 +- .../ci/ext/environment/providers/buddy.rb | 2 +- .../ci/ext/environment/providers/buildkite.rb | 2 +- .../ci/ext/environment/providers/circleci.rb | 2 +- .../ci/ext/environment/providers/codefresh.rb | 2 +- .../environment/providers/github_actions.rb | 2 +- .../ci/ext/environment/providers/gitlab.rb | 2 +- .../ci/ext/environment/providers/jenkins.rb | 2 +- .../ci/ext/environment/providers/teamcity.rb | 2 +- .../ci/ext/environment/providers/travis.rb | 2 +- lib/datadog/ci/ext/telemetry.rb | 18 ++++++++++++++++++ sig/datadog/ci/ext/environment.rbs | 17 +++++++++++++++++ sig/datadog/ci/ext/telemetry.rbs | 18 ++++++++++++++++++ 18 files changed, 84 insertions(+), 14 deletions(-) diff --git a/lib/datadog/ci/ext/environment.rb b/lib/datadog/ci/ext/environment.rb index d301cf92..e2d3f8cb 100644 --- a/lib/datadog/ci/ext/environment.rb +++ b/lib/datadog/ci/ext/environment.rb @@ -23,6 +23,23 @@ module Environment TAG_NODE_NAME = "ci.node.name" TAG_CI_ENV_VARS = "_dd.ci.env_vars" + module Provider + APPVEYOR = "appveyor" + AZURE = "azurepipelines" + AWS = "awscodepipeline" + BITBUCKET = "bitbucket" + BITRISE = "bitrise" + BUDDYCI = "buddy" + BUILDKITE = "buildkite" + CIRCLECI = "circleci" + CODEFRESH = "codefresh" + GITHUB = "github" + GITLAB = "gitlab" + JENKINS = "jenkins" + TEAMCITY = "teamcity" + TRAVISCI = "travisci" + end + POSSIBLE_BUNDLE_LOCATIONS = %w[vendor/bundle .bundle].freeze module_function diff --git a/lib/datadog/ci/ext/environment/providers/appveyor.rb b/lib/datadog/ci/ext/environment/providers/appveyor.rb index 3b9a3b9d..ba9aad33 100644 --- a/lib/datadog/ci/ext/environment/providers/appveyor.rb +++ b/lib/datadog/ci/ext/environment/providers/appveyor.rb @@ -15,7 +15,7 @@ def self.handles?(env) end def provider_name - "appveyor" + Provider::APPVEYOR end def pipeline_url diff --git a/lib/datadog/ci/ext/environment/providers/aws_code_pipeline.rb b/lib/datadog/ci/ext/environment/providers/aws_code_pipeline.rb index 5a70efd4..e80d54e2 100644 --- a/lib/datadog/ci/ext/environment/providers/aws_code_pipeline.rb +++ b/lib/datadog/ci/ext/environment/providers/aws_code_pipeline.rb @@ -17,7 +17,7 @@ def self.handles?(env) end def provider_name - "awscodepipeline" + Provider::AWS end def pipeline_id diff --git a/lib/datadog/ci/ext/environment/providers/azure.rb b/lib/datadog/ci/ext/environment/providers/azure.rb index e65f2ca9..bb3245fc 100644 --- a/lib/datadog/ci/ext/environment/providers/azure.rb +++ b/lib/datadog/ci/ext/environment/providers/azure.rb @@ -17,7 +17,7 @@ def self.handles?(env) end def provider_name - "azurepipelines" + Provider::AZURE end def pipeline_url diff --git a/lib/datadog/ci/ext/environment/providers/bitbucket.rb b/lib/datadog/ci/ext/environment/providers/bitbucket.rb index f4a618fb..82471fcc 100644 --- a/lib/datadog/ci/ext/environment/providers/bitbucket.rb +++ b/lib/datadog/ci/ext/environment/providers/bitbucket.rb @@ -16,7 +16,7 @@ def self.handles?(env) # overridden methods def provider_name - "bitbucket" + Provider::BITBUCKET end def pipeline_id diff --git a/lib/datadog/ci/ext/environment/providers/bitrise.rb b/lib/datadog/ci/ext/environment/providers/bitrise.rb index 7a7cb304..120196b9 100644 --- a/lib/datadog/ci/ext/environment/providers/bitrise.rb +++ b/lib/datadog/ci/ext/environment/providers/bitrise.rb @@ -15,7 +15,7 @@ def self.handles?(env) end def provider_name - "bitrise" + Provider::BITRISE end def pipeline_id diff --git a/lib/datadog/ci/ext/environment/providers/buddy.rb b/lib/datadog/ci/ext/environment/providers/buddy.rb index 82a23ada..c30fb710 100644 --- a/lib/datadog/ci/ext/environment/providers/buddy.rb +++ b/lib/datadog/ci/ext/environment/providers/buddy.rb @@ -15,7 +15,7 @@ def self.handles?(env) end def provider_name - "buddy" + Provider::BUDDYCI end def pipeline_id diff --git a/lib/datadog/ci/ext/environment/providers/buildkite.rb b/lib/datadog/ci/ext/environment/providers/buildkite.rb index 7b39eb62..76150d2f 100644 --- a/lib/datadog/ci/ext/environment/providers/buildkite.rb +++ b/lib/datadog/ci/ext/environment/providers/buildkite.rb @@ -17,7 +17,7 @@ def self.handles?(env) end def provider_name - "buildkite" + Provider::BUILDKITE end def job_url diff --git a/lib/datadog/ci/ext/environment/providers/circleci.rb b/lib/datadog/ci/ext/environment/providers/circleci.rb index 444e6dd1..c63b52ba 100644 --- a/lib/datadog/ci/ext/environment/providers/circleci.rb +++ b/lib/datadog/ci/ext/environment/providers/circleci.rb @@ -17,7 +17,7 @@ def self.handles?(env) end def provider_name - "circleci" + Provider::CIRCLECI end def job_url diff --git a/lib/datadog/ci/ext/environment/providers/codefresh.rb b/lib/datadog/ci/ext/environment/providers/codefresh.rb index 9ebe334e..0e111e40 100644 --- a/lib/datadog/ci/ext/environment/providers/codefresh.rb +++ b/lib/datadog/ci/ext/environment/providers/codefresh.rb @@ -17,7 +17,7 @@ def self.handles?(env) end def provider_name - "codefresh" + Provider::CODEFRESH end def job_name diff --git a/lib/datadog/ci/ext/environment/providers/github_actions.rb b/lib/datadog/ci/ext/environment/providers/github_actions.rb index cd805673..24c544b4 100644 --- a/lib/datadog/ci/ext/environment/providers/github_actions.rb +++ b/lib/datadog/ci/ext/environment/providers/github_actions.rb @@ -19,7 +19,7 @@ def self.handles?(env) end def provider_name - "github" + Provider::GITHUB end def job_name diff --git a/lib/datadog/ci/ext/environment/providers/gitlab.rb b/lib/datadog/ci/ext/environment/providers/gitlab.rb index e0581083..228cc8c1 100644 --- a/lib/datadog/ci/ext/environment/providers/gitlab.rb +++ b/lib/datadog/ci/ext/environment/providers/gitlab.rb @@ -15,7 +15,7 @@ def self.handles?(env) end def provider_name - "gitlab" + Provider::GITLAB end def job_name diff --git a/lib/datadog/ci/ext/environment/providers/jenkins.rb b/lib/datadog/ci/ext/environment/providers/jenkins.rb index 7bfa22b4..10b8f909 100644 --- a/lib/datadog/ci/ext/environment/providers/jenkins.rb +++ b/lib/datadog/ci/ext/environment/providers/jenkins.rb @@ -18,7 +18,7 @@ def self.handles?(env) end def provider_name - "jenkins" + Provider::JENKINS end def pipeline_id diff --git a/lib/datadog/ci/ext/environment/providers/teamcity.rb b/lib/datadog/ci/ext/environment/providers/teamcity.rb index 8ce5a664..adb4feea 100644 --- a/lib/datadog/ci/ext/environment/providers/teamcity.rb +++ b/lib/datadog/ci/ext/environment/providers/teamcity.rb @@ -15,7 +15,7 @@ def self.handles?(env) end def provider_name - "teamcity" + Provider::TEAMCITY end def job_name diff --git a/lib/datadog/ci/ext/environment/providers/travis.rb b/lib/datadog/ci/ext/environment/providers/travis.rb index b6c60c12..eae93c5f 100644 --- a/lib/datadog/ci/ext/environment/providers/travis.rb +++ b/lib/datadog/ci/ext/environment/providers/travis.rb @@ -15,7 +15,7 @@ def self.handles?(env) end def provider_name - "travisci" + Provider::TRAVISCI end def job_url diff --git a/lib/datadog/ci/ext/telemetry.rb b/lib/datadog/ci/ext/telemetry.rb index 589efc6b..cbd6bb71 100644 --- a/lib/datadog/ci/ext/telemetry.rb +++ b/lib/datadog/ci/ext/telemetry.rb @@ -110,6 +110,24 @@ module Command GET_OBJECTS = "get_objects" PACK_OBJECTS = "pack_objects" end + + module Provider + APPVEYOR = "appveyor" + AWS = "aws" + AZURE = "azp" + BITBUCKET = "bitbucket" + BITRISE = "bitrise" + BUDDYCI = "buddyci" + BUILDKITE = "buildkite" + CIRCLECI = "circleci" + CODEFRESH = "codefresh" + GITHUB = "githubactions" + GITLAB = "gitlab" + JENKINS = "jenkins" + TEAMCITY = "teamcity" + TRAVISCI = "travisci" + UNSUPPORTED = "unsupported" + end end end end diff --git a/sig/datadog/ci/ext/environment.rbs b/sig/datadog/ci/ext/environment.rbs index 04e04368..85b082f7 100644 --- a/sig/datadog/ci/ext/environment.rbs +++ b/sig/datadog/ci/ext/environment.rbs @@ -31,6 +31,23 @@ module Datadog PROVIDERS: ::Array[Array[String | Symbol]] + module Provider + APPVEYOR: "appveyor" + AWS: "awscodepipeline" + AZURE: "azurepipelines" + BITBUCKET: "bitbucket" + BITRISE: "bitrise" + BUDDYCI: "buddy" + BUILDKITE: "buildkite" + CIRCLECI: "circleci" + CODEFRESH: "codefresh" + GITHUB: "github" + GITLAB: "gitlab" + JENKINS: "jenkins" + TEAMCITY: "teamcity" + TRAVISCI: "travisci" + end + def self?.tags: (untyped env) -> Hash[String, String] def self?.ensure_post_conditions: (Hash[String, String] tags) -> void diff --git a/sig/datadog/ci/ext/telemetry.rbs b/sig/datadog/ci/ext/telemetry.rbs index f3c41744..30e6d0c0 100644 --- a/sig/datadog/ci/ext/telemetry.rbs +++ b/sig/datadog/ci/ext/telemetry.rbs @@ -162,6 +162,24 @@ module Datadog PACK_OBJECTS: "pack_objects" end + + module Provider + APPVEYOR: "appveyor" + AWS: "aws" + AZURE: "azp" + BITBUCKET: "bitbucket" + BITRISE: "bitrise" + BUDDYCI: "buddyci" + BUILDKITE: "buildkite" + CIRCLECI: "circleci" + CODEFRESH: "codefresh" + GITHUB: "githubactions" + GITLAB: "gitlab" + JENKINS: "jenkins" + TEAMCITY: "teamcity" + TRAVISCI: "travisci" + UNSUPPORTED: "unsupported" + end end end end From 0a12ac314d8fde6f991c0a5bc2c9addbc3bf9827 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 30 Jul 2024 10:48:51 +0200 Subject: [PATCH 2/3] add helper method to emit test_session metric --- lib/datadog/ci/test_visibility/telemetry.rb | 31 ++++++++++++++++ sig/datadog/ci/test_visibility/telemetry.rbs | 2 ++ .../ci/test_visibility/telemetry_spec.rb | 35 +++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/lib/datadog/ci/test_visibility/telemetry.rb b/lib/datadog/ci/test_visibility/telemetry.rb index 397df3e5..7220ba02 100644 --- a/lib/datadog/ci/test_visibility/telemetry.rb +++ b/lib/datadog/ci/test_visibility/telemetry.rb @@ -18,6 +18,23 @@ module Telemetry Ext::AppTypes::TYPE_TEST_SESSION => Ext::Telemetry::EventType::SESSION }.freeze + PROVIDER_TAG_TO_TELEMETRY_PROVIDER_TAG = { + Ext::Environment::Provider::APPVEYOR => Ext::Telemetry::Provider::APPVEYOR, + Ext::Environment::Provider::AWS => Ext::Telemetry::Provider::AWS, + Ext::Environment::Provider::AZURE => Ext::Telemetry::Provider::AZURE, + Ext::Environment::Provider::BITBUCKET => Ext::Telemetry::Provider::BITBUCKET, + Ext::Environment::Provider::BITRISE => Ext::Telemetry::Provider::BITRISE, + Ext::Environment::Provider::BUDDYCI => Ext::Telemetry::Provider::BUDDYCI, + Ext::Environment::Provider::BUILDKITE => Ext::Telemetry::Provider::BUILDKITE, + Ext::Environment::Provider::CIRCLECI => Ext::Telemetry::Provider::CIRCLECI, + Ext::Environment::Provider::CODEFRESH => Ext::Telemetry::Provider::CODEFRESH, + Ext::Environment::Provider::GITHUB => Ext::Telemetry::Provider::GITHUB, + Ext::Environment::Provider::GITLAB => Ext::Telemetry::Provider::GITLAB, + Ext::Environment::Provider::JENKINS => Ext::Telemetry::Provider::JENKINS, + Ext::Environment::Provider::TEAMCITY => Ext::Telemetry::Provider::TEAMCITY, + Ext::Environment::Provider::TRAVISCI => Ext::Telemetry::Provider::TRAVISCI + }.freeze + def self.event_created(span) Utils::Telemetry.inc(Ext::Telemetry::METRIC_EVENT_CREATED, 1, event_tags_from_span(span)) end @@ -28,6 +45,20 @@ def self.event_finished(span) Utils::Telemetry.inc(Ext::Telemetry::METRIC_EVENT_FINISHED, 1, tags) end + def self.test_session_started(test_session) + Utils::Telemetry.inc( + Ext::Telemetry::METRIC_TEST_SESSION, + 1, + { + Ext::Telemetry::TAG_AUTO_INJECTED => "false", # ruby doesn't support auto injection yet + Ext::Telemetry::TAG_PROVIDER => PROVIDER_TAG_TO_TELEMETRY_PROVIDER_TAG.fetch( + test_session.get_tag(Ext::Environment::TAG_PROVIDER_NAME), + Ext::Telemetry::Provider::UNSUPPORTED + ) + } + ) + end + def self.event_tags_from_span(span) # base tags for span # @type var tags: Hash[String, String] diff --git a/sig/datadog/ci/test_visibility/telemetry.rbs b/sig/datadog/ci/test_visibility/telemetry.rbs index 2f6ab2f4..f58a5629 100644 --- a/sig/datadog/ci/test_visibility/telemetry.rbs +++ b/sig/datadog/ci/test_visibility/telemetry.rbs @@ -4,6 +4,8 @@ module Datadog module Telemetry SPAN_TYPE_TO_TELEMETRY_EVENT_TYPE: ::Hash[String, String] + PROVIDER_TAG_TO_TELEMETRY_PROVIDER_TAG: ::Hash[String, String] + def self.event_created: (Datadog::CI::Span span) -> void def self.event_finished: (Datadog::CI::Span span) -> void diff --git a/spec/datadog/ci/test_visibility/telemetry_spec.rb b/spec/datadog/ci/test_visibility/telemetry_spec.rb index 2c75e45f..51a604a2 100644 --- a/spec/datadog/ci/test_visibility/telemetry_spec.rb +++ b/spec/datadog/ci/test_visibility/telemetry_spec.rb @@ -206,4 +206,39 @@ it { event_finished } end end + + describe ".test_session_started" do + subject(:test_session_started) { described_class.test_session_started(test_session) } + + let(:provider_tag) { "github" } + let(:expected_provider_telemetry_tag) { Datadog::CI::Ext::Telemetry::Provider::GITHUB } + + let(:test_session) do + instance_double( + Datadog::CI::TestSession, + get_tag: provider_tag + ) + end + + before do + expect(Datadog::CI::Utils::Telemetry).to receive(:inc) + .with( + Datadog::CI::Ext::Telemetry::METRIC_TEST_SESSION, + 1, + { + Datadog::CI::Ext::Telemetry::TAG_AUTO_INJECTED => "false", + Datadog::CI::Ext::Telemetry::TAG_PROVIDER => expected_provider_telemetry_tag + } + ) + end + + it { test_session_started } + + context "when provider is not supported" do + let(:provider_tag) { nil } + let(:expected_provider_telemetry_tag) { Datadog::CI::Ext::Telemetry::Provider::UNSUPPORTED } + + it { test_session_started } + end + end end From 052dac8c7a229b9ee48f862745e1f75c322f8f00 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 30 Jul 2024 10:52:18 +0200 Subject: [PATCH 3/3] emit test_session metric when test session started --- lib/datadog/ci/test_visibility/component.rb | 1 + sig/datadog/ci/test_visibility/telemetry.rbs | 2 ++ spec/datadog/ci/test_visibility/component_spec.rb | 1 + 3 files changed, 4 insertions(+) diff --git a/lib/datadog/ci/test_visibility/component.rb b/lib/datadog/ci/test_visibility/component.rb index d070c1d4..06dedcb5 100644 --- a/lib/datadog/ci/test_visibility/component.rb +++ b/lib/datadog/ci/test_visibility/component.rb @@ -144,6 +144,7 @@ def itr_enabled? # DOMAIN EVENTS def on_test_session_started(test_session) Telemetry.event_created(test_session) + Telemetry.test_session_started(test_session) # finds and instruments additional test libraries that we support (ex: selenium-webdriver) Contrib.auto_instrument_on_session_start! diff --git a/sig/datadog/ci/test_visibility/telemetry.rbs b/sig/datadog/ci/test_visibility/telemetry.rbs index f58a5629..8ccc83b5 100644 --- a/sig/datadog/ci/test_visibility/telemetry.rbs +++ b/sig/datadog/ci/test_visibility/telemetry.rbs @@ -10,6 +10,8 @@ module Datadog def self.event_finished: (Datadog::CI::Span span) -> void + def self.test_session_started: (Datadog::CI::TestSession span) -> void + def self.event_tags_from_span: (Datadog::CI::Span span) -> ::Hash[String, String] def self.add_browser_tags!: (Datadog::CI::Span span, ::Hash[String, String] tags) -> void diff --git a/spec/datadog/ci/test_visibility/component_spec.rb b/spec/datadog/ci/test_visibility/component_spec.rb index 5a00e1a5..c7379fbd 100644 --- a/spec/datadog/ci/test_visibility/component_spec.rb +++ b/spec/datadog/ci/test_visibility/component_spec.rb @@ -436,6 +436,7 @@ end end it_behaves_like "emits telemetry metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_EVENT_CREATED + it_behaves_like "emits telemetry metric", :inc, Datadog::CI::Ext::Telemetry::METRIC_TEST_SESSION end describe "#start_test_module" do