Skip to content

Commit

Permalink
implement endpoint_payload.requests_errors metric
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 25, 2024
1 parent 74b265b commit e49ea43
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/datadog/ci/transport/event_platform_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def send_events(events)
# HTTP layer could send events and exhausted retries (if any)
unless response.ok?
Telemetry.endpoint_payload_dropped(chunk.count, endpoint: telemetry_endpoint_tag)
Telemetry.endpoint_payload_requests_errors(
1,
endpoint: telemetry_endpoint_tag,
error_type: response.telemetry_error_type,
status_code: response.code
)
end

responses << response
Expand Down
9 changes: 9 additions & 0 deletions lib/datadog/ci/transport/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def self.endpoint_payload_bytes(bytesize, endpoint:)
)
end

def self.endpoint_payload_requests_errors(count, endpoint:, error_type:, status_code:)
tags = tags(endpoint: endpoint)

tags[Ext::Telemetry::TAG_ERROR_TYPE] = error_type if error_type
tags[Ext::Telemetry::TAG_STATUS_CODE] = status_code.to_s if status_code

Utils::Telemetry.inc(Ext::Telemetry::METRIC_ENDPOINT_PAYLOAD_REQUESTS_ERRORS, count, tags)
end

def self.tags(endpoint:)
{Ext::Telemetry::TAG_ENDPOINT => endpoint}
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/transport/telemetry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module Datadog

def self.endpoint_payload_bytes: (Integer | Float bytesize, endpoint: String) -> void

def self.endpoint_payload_requests_errors: (Integer count, endpoint: String, error_type: String?, status_code: Integer?) -> void

def self.tags: (endpoint: String) -> Hash[String, String]
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/datadog/ci/test_visibility/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
end

it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.dropped", 1
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests_errors", 1
end

it "tags telemetry metric with test_cycle endpoint" do
Expand Down Expand Up @@ -161,6 +162,7 @@
end

it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.dropped", 4
it_behaves_like "emits telemetry metric", :inc, "endpoint_payload.requests_errors", 1
end

context "when some spans are broken" do
Expand Down
38 changes: 38 additions & 0 deletions spec/datadog/ci/transport/telemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,42 @@
subject
end
end

describe ".endpoint_payload_requests_errors" do
subject { described_class.endpoint_payload_requests_errors(count, endpoint: endpoint, error_type: error_type, status_code: status_code) }

let(:count) { 1 }
let(:endpoint) { "test_cycle" }
let(:error_type) { "error" }
let(:status_code) { 500 }

it "increments the endpoint payload requests errors metric" do
expect(Datadog::CI::Utils::Telemetry).to receive(:inc).with(
Datadog::CI::Ext::Telemetry::METRIC_ENDPOINT_PAYLOAD_REQUESTS_ERRORS,
count,
{
Datadog::CI::Ext::Telemetry::TAG_ENDPOINT => endpoint,
Datadog::CI::Ext::Telemetry::TAG_ERROR_TYPE => error_type,
Datadog::CI::Ext::Telemetry::TAG_STATUS_CODE => status_code
}
)

subject
end

context "when error type and status code are not provided" do
let(:error_type) { nil }
let(:status_code) { nil }

it "increments the endpoint payload requests errors metric without error type and status code tags" do
expect(Datadog::CI::Utils::Telemetry).to receive(:inc).with(
Datadog::CI::Ext::Telemetry::METRIC_ENDPOINT_PAYLOAD_REQUESTS_ERRORS,
count,
{Datadog::CI::Ext::Telemetry::TAG_ENDPOINT => endpoint}
)

subject
end
end
end
end

0 comments on commit e49ea43

Please sign in to comment.