Skip to content

Commit

Permalink
add .virtual_cpu_count method to Utils::TestRun to report it as inter…
Browse files Browse the repository at this point in the history
…nal metric
  • Loading branch information
anmarchenko committed Sep 20, 2024
1 parent b8f49d9 commit a2bd1ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/datadog/ci/utils/test_run.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "etc"

module Datadog
module CI
module Utils
Expand Down Expand Up @@ -34,6 +36,12 @@ def self.custom_configuration(env_tags)
end
res
end

def self.virtual_cpu_count
return @virtual_cpu_count if defined?(@virtual_cpu_count)

@virtual_cpu_count = ::Etc.nprocessors
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions sig/datadog/ci/utils/test_run.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Datadog
module Utils
module TestRun
self.@command: String
self.@virtual_cpu_count: Integer

def self.command: () -> String

Expand All @@ -11,7 +12,13 @@ module Datadog
def self.test_parameters: (?arguments: Hash[untyped, untyped], ?metadata: Hash[untyped, untyped]) -> String

def self.custom_configuration: (Hash[String, String]? env_tags) -> Hash[String, String]

def self.virtual_cpu_count: () -> Integer
end
end
end
end

module Etc
def self.nprocessors: () -> Integer
end
6 changes: 6 additions & 0 deletions spec/datadog/ci/utils/test_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@
it { is_expected.to eq({"tag1" => "value1", "tag2" => "value2"}) }
end
end

describe ".virtual_cpu_count" do
subject { described_class.virtual_cpu_count }

it { is_expected.to eq(::Etc.nprocessors) }
end
end

0 comments on commit a2bd1ac

Please sign in to comment.