Skip to content

Commit

Permalink
move agent settings resolving from telemetry transport initializer to…
Browse files Browse the repository at this point in the history
… a factory method
  • Loading branch information
anmarchenko committed Jul 11, 2024
1 parent 6b8e4b1 commit c46f299
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/core/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def build_telemetry(settings, agent_settings, logger)
end

Telemetry::Component.new(
http_transport: Datadog::Core::Telemetry::Http::Transport.new,
http_transport: Datadog::Core::Telemetry::Http::Transport.build_agent_transport,
enabled: enabled,
metrics_enabled: enabled && settings.telemetry.metrics_enabled,
heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds,
Expand Down
21 changes: 15 additions & 6 deletions lib/datadog/core/telemetry/http/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ module Http
# Class to send telemetry data to Telemetry API
# Currently only supports the HTTP protocol.
class Transport
def self.build_agent_transport
agent_settings = Configuration::AgentSettingsResolver.call(Datadog.configuration)

Transport.new(
host: agent_settings.hostname,
port: agent_settings.port,
path: Http::Ext::AGENT_ENDPOINT
)
end

attr_reader \
:host,
:port,
:ssl,
:path

def initialize
agent_settings = Configuration::AgentSettingsResolver.call(Datadog.configuration)
@host = agent_settings.hostname
@port = agent_settings.port
@ssl = false
@path = Http::Ext::AGENT_ENDPOINT
def initialize(host:, port:, path:, ssl: false)
@host = host
@port = port
@ssl = ssl
@path = path
end

def request(request_type:, payload:)
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/core/telemetry/http/transport.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Datadog

attr_reader path: String

def initialize: () -> void
def initialize: (host: String, port: Integer, path: String, ?ssl: bool) -> void

def request: (request_type: String, payload: String) -> Datadog::Core::Telemetry::Http::Adapters::Net::response

Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/core/telemetry/http/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
require 'datadog/core/telemetry/http/adapters/net'

RSpec.describe Datadog::Core::Telemetry::Http::Transport do
subject(:transport) { described_class.new }
subject(:transport) { described_class.build_agent_transport }

let(:hostname) { 'foo' }
let(:port) { 1234 }

describe '#initialize' do
describe '.build_agent_transport' do
before do
Datadog.configuration.agent.host = hostname
Datadog.configuration.agent.port = port
Expand Down

0 comments on commit c46f299

Please sign in to comment.