Class: Datadog::CI::Transport::EventPlatformTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/transport/event_platform_transport.rb

Constant Summary collapse

DEFAULT_MAX_PAYLOAD_SIZE =
5 * 1024 * 1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api:, max_payload_size: DEFAULT_MAX_PAYLOAD_SIZE) ⇒ EventPlatformTransport

Returns a new instance of EventPlatformTransport.



19
20
21
22
# File 'lib/datadog/ci/transport/event_platform_transport.rb', line 19

def initialize(api:, max_payload_size: DEFAULT_MAX_PAYLOAD_SIZE)
  @api = api
  @max_payload_size = max_payload_size
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



16
17
18
# File 'lib/datadog/ci/transport/event_platform_transport.rb', line 16

def api
  @api
end

#max_payload_sizeObject (readonly)

Returns the value of attribute max_payload_size.



16
17
18
# File 'lib/datadog/ci/transport/event_platform_transport.rb', line 16

def max_payload_size
  @max_payload_size
end

Instance Method Details

#send_events(events) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/datadog/ci/transport/event_platform_transport.rb', line 24

def send_events(events)
  return [] if events.nil? || events.empty?

  Datadog.logger.debug { "[#{self.class.name}] Sending #{events.count} events..." }

  encoded_events = []
  # @type var serialization_duration_ms: Float
  serialization_duration_ms = Core::Utils::Time.measure(:float_millisecond) do
    encoded_events = encode_events(events)
    if encoded_events.empty?
      Datadog.logger.debug { "[#{self.class.name}] Empty encoded events list, skipping send" }
      return []
    end
  end

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

  responses = []

  Datadog::Core::Chunker.chunk_by_size(encoded_events, max_payload_size).map do |chunk|
    encoded_payload = pack_events(chunk)
    Datadog.logger.debug do
      "[#{self.class.name}] Send chunk of #{chunk.count} events; payload size #{encoded_payload.size}"
    end
    Telemetry.endpoint_payload_events_count(chunk.count, endpoint: telemetry_endpoint_tag)

    response = send_payload(encoded_payload)

    Telemetry.endpoint_payload_requests(
      1,
      endpoint: telemetry_endpoint_tag, compressed: response.request_compressed
    )
    Telemetry.endpoint_payload_requests_ms(response.duration_ms, endpoint: telemetry_endpoint_tag)
    Telemetry.endpoint_payload_bytes(response.request_size, endpoint: telemetry_endpoint_tag)

    # 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
  end

  responses
end