Skip to content

Commit

Permalink
set _dd.host.vcpu_count metric for all CI events
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 20, 2024
1 parent a2bd1ac commit 576529e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/datadog/ci/ext/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ module Test
# common tags that are serialized directly in msgpack header in metadata field
METADATA_TAG_TEST_SESSION_NAME = "test_session.name"

# internal metric with the number of virtual CPUs
METRIC_CPU_COUNT = "_dd.host.vcpu_count"

# tags that are common for the whole session and can be inherited from the test session
INHERITABLE_TAGS = [TAG_FRAMEWORK, TAG_FRAMEWORK_VERSION].freeze

Expand Down
7 changes: 7 additions & 0 deletions lib/datadog/ci/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def clear_tag(key)
tracer_span.clear_tag(key)
end

# Gets metric value by key.
# @param [String] key the key of the metric.
# @return [Numeric] value the value of the metric.
def get_metric(key)
tracer_span.get_metric(key)
end

# Sets metric value by key.
# @param [String] key the key of the metric.
# @param [Numeric] value the value of the metric.
Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/ci/test_visibility/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
require_relative "../ext/environment"
require_relative "../ext/test"

require_relative "../utils/test_run"

require_relative "../span"
require_relative "../test"
require_relative "../test_session"
Expand Down Expand Up @@ -203,6 +205,8 @@ def set_initial_tags(ci_span, tags)

ci_span.set_tags(tags)
ci_span.set_tags(@environment_tags)

ci_span.set_metric(Ext::Test::METRIC_CPU_COUNT, Utils::TestRun.virtual_cpu_count)
end

# PROPAGATING CONTEXT FROM TOP-LEVEL TO THE LOWER LEVELS
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/ext/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ module Datadog

METADATA_TAG_TEST_SESSION_NAME: "test_session.name"

METRIC_CPU_COUNT: "_dd.host.vcpu_count"

module Status
PASS: "pass"

Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/span.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module Datadog

def clear_tag: (String key) -> void

def get_metric: (String key) -> Numeric?

def set_metric: (String key, untyped value) -> void

def set_tags: (Hash[untyped, untyped] tags) -> void
Expand Down
1 change: 1 addition & 0 deletions spec/datadog/ci/test_visibility/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
expect(span_under_test).to have_test_tag(tag)
end
expect(span_under_test).to have_test_tag(:command, test_command)
expect(span_under_test.get_metric(Datadog::CI::Ext::Test::METRIC_CPU_COUNT)).to eq(Etc.nprocessors)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
)
expect(metrics).to eq(
{"_dd.top_level" => 1.0, "memory_allocations" => 16}
{"_dd.top_level" => 1.0, "memory_allocations" => 16, "_dd.host.vcpu_count" => Etc.nprocessors}
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
expect(meta["_test.session_id"]).to be_nil
expect(meta["_test.module_id"]).to be_nil

expect(metrics).to eq({"_dd.top_level" => 1, "memory_allocations" => 16})
expect(metrics).to eq({"_dd.top_level" => 1, "memory_allocations" => 16, "_dd.host.vcpu_count" => Etc.nprocessors})
end
end

Expand Down

0 comments on commit 576529e

Please sign in to comment.