Skip to content

Commit

Permalink
some of the skippable HTTP client metrics, fix a lot of typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 29, 2024
1 parent 7ddb104 commit fed5e67
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/ci/git/upload_packfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def call(filepath:)
compressed: http_response.request_compressed
)
Utils::Telemetry.distribution(Ext::Telemetry::METRIC_GIT_REQUESTS_OBJECT_PACK_MS, http_response.duration_ms)
Utils::Telemetry.distribution(Ext::Telemetry::METRIC_GIT_REQUESTS_OBJECT_PACK_BYTES, http_response.request_size)
Utils::Telemetry.distribution(Ext::Telemetry::METRIC_GIT_REQUESTS_OBJECT_PACK_BYTES, http_response.request_size.to_f)

unless http_response.ok?
Transport::Telemetry.api_requests_errors(
Expand Down
12 changes: 12 additions & 0 deletions lib/datadog/ci/test_optimisation/skippable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ def fetch_skippable_tests(test_session)
payload: request_payload
)

Transport::Telemetry.api_requests(
Ext::Telemetry::METRIC_ITR_SKIPPABLE_TESTS_REQUEST,
1,
compressed: http_response.request_compressed
)
Utils::Telemetry.distribution(Ext::Telemetry::METRIC_ITR_SKIPPABLE_TESTS_REQUEST_MS, http_response.duration_ms)
Utils::Telemetry.distribution(
Ext::Telemetry::METRIC_ITR_SKIPPABLE_TESTS_RESPONSE_BYTES,
http_response.response_size.to_f,
{Ext::Telemetry::TAG_RESPONSE_COMPRESSED => http_response.gzipped_content?.to_s}
)

Response.new(http_response)
end

Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/ci/transport/adapters/net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def payload
@decompressed_payload = Gzip.decompress(http_response.body)
end

def response_size
http_response.body.bytesize
end

def header(name)
http_response[name]
end
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/git/search_commits.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Datadog

def request_payload: (String repository_url, Array[String] commits) -> String

def parse_json_response: (Datadog::Core::Transport::Response response) -> Hash[String, untyped]
def parse_json_response: (Datadog::CI::Transport::Adapters::Net::Response response) -> Hash[String, untyped]

def extract_commits: (Hash[String, untyped] response) -> Set[String]
end
Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/ci/test_optimisation/skippable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ module Datadog
@config_tags: Hash[String, String]

class Response
@http_response: Datadog::Core::Transport::HTTP::Adapters::Net::Response?
@http_response: Datadog::CI::Transport::Adapters::Net::Response?
@json: Hash[String, untyped]?

def initialize: (Datadog::Core::Transport::HTTP::Adapters::Net::Response? http_response) -> void
def initialize: (Datadog::CI::Transport::Adapters::Net::Response? http_response) -> void

def ok?: () -> bool

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

def telemetry_error_type: () -> String?

def response_size: () -> Integer

def trace_count: () -> 0

def inspect: () -> ::String
Expand Down
8 changes: 0 additions & 8 deletions sig/datadog/ci/transport/http.rbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
class SimpleDelegator
@decompressed_payload: String

def __getobj__: () -> Datadog::Core::Transport::Response
def gzipped?: (String payload) -> bool
def payload: () -> String
end

module Datadog
module CI
module Transport
Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/ci/transport/remote_settings_api.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module Datadog
module Transport
class RemoteSettingsApi
class Response
@http_response: Datadog::Core::Transport::HTTP::Adapters::Net::Response?
@http_response: Datadog::CI::Transport::Adapters::Net::Response?
@json: Hash[String, untyped]?

def initialize: (Datadog::Core::Transport::HTTP::Adapters::Net::Response? http_response) -> void
def initialize: (Datadog::CI::Transport::Adapters::Net::Response? http_response) -> void

def ok?: () -> bool

Expand Down
36 changes: 30 additions & 6 deletions spec/datadog/ci/test_optimisation/skippable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
require_relative "../../../../lib/datadog/ci/test_optimisation/skippable"

RSpec.describe Datadog::CI::TestOptimisation::Skippable do
include_context "Telemetry spy"

let(:api) { spy("api") }
let(:dd_env) { "ci" }
let(:config_tags) { {} }

subject(:client) { described_class.new(api: api, dd_env: dd_env, config_tags: config_tags) }

describe "#fetch_skippable_tests" do
subject { client.fetch_skippable_tests(test_session) }

let(:service) { "service" }
let(:tracer_span) do
Datadog::Tracing::SpanOperation.new("session", service: service).tap do |span|
Expand All @@ -30,7 +34,7 @@
let(:path) { Datadog::CI::Ext::Transport::DD_API_SKIPPABLE_TESTS_PATH }

it "requests the skippable tests" do
client.fetch_skippable_tests(test_session)
subject

expect(api).to have_received(:api_request) do |args|
expect(args[:path]).to eq(path)
Expand Down Expand Up @@ -90,7 +94,11 @@
}
}
]
}.to_json
}.to_json,
request_compressed: false,
duration_ms: 1.2,
gzipped_content?: false,
response_size: 100
)
end

Expand All @@ -99,14 +107,22 @@
expect(response.correlation_id).to eq("correlation_id_123")
expect(response.tests).to eq(Set.new(["test_suite_name.test_name.string"]))
end

it_behaves_like "emits telemetry metric", :inc, "itr_skippable_tests.request", 1
it_behaves_like "emits telemetry metric", :distribution, "itr_skippable_tests.request_ms"
it_behaves_like "emits telemetry metric", :distribution, "itr_skippable_tests.response_bytes"
end

context "when response is not OK" do
let(:http_response) do
double(
"http_response",
ok?: false,
payload: ""
payload: "",
request_compressed: false,
duration_ms: 1.2,
gzipped_content?: false,
response_size: 100
)
end

Expand All @@ -122,7 +138,11 @@
double(
"http_response",
ok?: true,
payload: "not json"
payload: "not json",
request_compressed: false,
duration_ms: 1.2,
gzipped_content?: false,
response_size: 100
)
end

Expand Down Expand Up @@ -155,7 +175,11 @@
"runtime.architecture" => "amd64"
}
}
}.to_json
}.to_json,
request_compressed: false,
duration_ms: 1.2,
gzipped_content?: false,
response_size: 100
)
end

Expand Down Expand Up @@ -186,7 +210,7 @@
end

it "requests the skippable tests with custom configurations" do
client.fetch_skippable_tests(test_session)
subject

expect(api).to have_received(:api_request) do |args|
data = JSON.parse(args[:payload])["data"]
Expand Down
1 change: 1 addition & 0 deletions spec/datadog/ci/transport/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
expect(response.payload).to eq("sample payload")
expect(response.request_compressed).to eq(false)
expect(response.request_size).to eq(payload.bytesize)
expect(response.response_size).to eq(response_payload.bytesize)
expect(response.duration_ms).to be > 0
expect(response.telemetry_error_type).to be_nil
end
Expand Down

0 comments on commit fed5e67

Please sign in to comment.