Skip to content

Commit

Permalink
implement endpoint_payload.requests metric
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 25, 2024
1 parent 97835e1 commit 3cbb9f8
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/datadog/ci/transport/event_platform_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def send_events(events)
end
end

Telemetry.endpoint_payload_serialization_ms(serialization_duration_ms, endpoint: telemetry_endpoint_tag)
Telemetry.events_enqueued_for_serialization(encoded_events.count)
Telemetry.endpoint_payload_serialization_ms(serialization_duration_ms, endpoint: telemetry_endpoint_tag)

responses = []

Expand All @@ -51,6 +51,11 @@ def send_events(events)

response = send_payload(encoded_payload)

Telemetry.endpoint_payload_requests(
1,
endpoint: telemetry_endpoint_tag, compressed: response.request_compressed
)

# HTTP layer could send events and exhausted retries (if any)
unless response.ok?
Telemetry.endpoint_payload_dropped(chunk.count, endpoint: telemetry_endpoint_tag)
Expand Down
17 changes: 15 additions & 2 deletions lib/datadog/ci/transport/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,21 @@ def self.endpoint_payload_dropped(count, endpoint:)
)
end

def self.tags(endpoint:)
{Ext::Telemetry::TAG_ENDPOINT => endpoint}
def self.endpoint_payload_requests(count, endpoint:, compressed:)
Utils::Telemetry.inc(
Ext::Telemetry::METRIC_ENDPOINT_PAYLOAD_REQUESTS,
count,
tags(endpoint: endpoint, request_compressed: compressed)
)
end

def self.tags(endpoint:, request_compressed: false)
# @type var tags: Hash[String, String]
tags = {Ext::Telemetry::TAG_ENDPOINT => endpoint}

tags[Ext::Telemetry::TAG_REQUEST_COMPRESSED] = "true" if request_compressed

tags
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion sig/datadog/ci/transport/telemetry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module Datadog

def self.endpoint_payload_dropped: (Integer count, endpoint: String) -> void

def self.tags: (endpoint: String) -> Hash[String, String]
def self.endpoint_payload_requests: (Integer count, endpoint: String, compressed: bool) -> void

def self.tags: (endpoint: String, ?request_compressed: bool) -> Hash[String, String]
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/datadog/ci/test_optimisation/coverage/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
it_behaves_like "emits telemetry metric", :inc, "events_enqueued_for_serialization", 1
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_count", 1
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_serialization_ms"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests"

it "tags event with code_coverage endpoint" do
subject
Expand Down Expand Up @@ -96,6 +97,7 @@
it_behaves_like "emits telemetry metric", :inc, "events_enqueued_for_serialization", 2
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_count", 2
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_serialization_ms"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests"

context "when some events are invalid" do
let(:events) do
Expand Down Expand Up @@ -135,6 +137,7 @@
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_count", 1
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_serialization_ms"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.dropped", 1
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests"
end

context "when chunking is used" do
Expand All @@ -151,6 +154,7 @@
it_behaves_like "emits telemetry metric", :inc, "events_enqueued_for_serialization", 2
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_count", 1
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_serialization_ms"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests"
end

context "when max_payload-size is too small" do
Expand Down
4 changes: 4 additions & 0 deletions spec/datadog/ci/test_visibility/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
it_behaves_like "emits telemetry metric", :inc, "events_enqueued_for_serialization", 1
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_count", 1
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_serialization_ms"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests"

context "when HTTP response is not OK" do
before do
Expand Down Expand Up @@ -148,6 +149,7 @@
it_behaves_like "emits telemetry metric", :inc, "events_enqueued_for_serialization", 4
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_count", 4
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_serialization_ms"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests"

context "when HTTP response is not OK" do
before do
Expand Down Expand Up @@ -193,6 +195,7 @@
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_count", 3
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_serialization_ms"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.dropped"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests"
end

context "when chunking is used" do
Expand All @@ -210,6 +213,7 @@
it_behaves_like "emits telemetry metric", :inc, "events_enqueued_for_serialization", 4
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_count"
it_behaves_like "emits telemetry metric", :distribution, "endpoint_payload.events_serialization_ms"
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests"
end

context "when max_payload-size is too small" do
Expand Down
35 changes: 35 additions & 0 deletions spec/datadog/ci/transport/telemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,39 @@
subject
end
end

describe ".endpoint_payload_requests" do
subject { described_class.endpoint_payload_requests(count, endpoint: endpoint, compressed: compressed) }

let(:count) { 1 }
let(:endpoint) { "test_cycle" }
let(:compressed) { true }

it "increments the endpoint payload requests metric" do
expect(Datadog::CI::Utils::Telemetry).to receive(:inc).with(
Datadog::CI::Ext::Telemetry::METRIC_ENDPOINT_PAYLOAD_REQUESTS,
count,
{
Datadog::CI::Ext::Telemetry::TAG_ENDPOINT => endpoint,
Datadog::CI::Ext::Telemetry::TAG_REQUEST_COMPRESSED => "true"
}
)

subject
end

context "when not compressed" do
let(:compressed) { false }

it "incremenets metric without request compressed tag" do
expect(Datadog::CI::Utils::Telemetry).to receive(:inc).with(
Datadog::CI::Ext::Telemetry::METRIC_ENDPOINT_PAYLOAD_REQUESTS,
count,
{Datadog::CI::Ext::Telemetry::TAG_ENDPOINT => endpoint}
)

subject
end
end
end
end

0 comments on commit 3cbb9f8

Please sign in to comment.