Skip to content

Commit

Permalink
rename Telemetry::Client to Telemetry::Component to better reflect it…
Browse files Browse the repository at this point in the history
…s purpose
  • Loading branch information
anmarchenko committed Jun 14, 2024
1 parent c03e392 commit 39bd8eb
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 55 deletions.
4 changes: 2 additions & 2 deletions lib/datadog/core/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require_relative '../diagnostics/health'
require_relative '../logger'
require_relative '../runtime/metrics'
require_relative '../telemetry/client'
require_relative '../telemetry/component'
require_relative '../workers/runtime_metrics'

require_relative '../remote/component'
Expand Down Expand Up @@ -62,7 +62,7 @@ def build_telemetry(settings, agent_settings, logger)
logger.debug { "Telemetry disabled. Agent network adapter not supported: #{agent_settings.adapter}" }
end

Telemetry::Client.new(
Telemetry::Component.new(
enabled: enabled,
heartbeat_interval_seconds: settings.telemetry.heartbeat_interval_seconds,
dependency_collection: settings.telemetry.dependency_collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Datadog
module Core
module Telemetry
# Telemetry entrypoint, coordinates sending telemetry events at various points in app lifecycle.
class Client
class Component
attr_reader :enabled

include Core::Utils::Forking
Expand Down Expand Up @@ -39,7 +39,6 @@ def started!
return if !@enabled || forked?

@worker.start

@worker.enqueue(Event::AppDependenciesLoaded.new) if @dependency_collection

@started = true
Expand Down
6 changes: 3 additions & 3 deletions lib/datadog/core/telemetry/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def started!
if res.not_found? # Telemetry is only supported by agent versions 7.34 and up
Datadog.logger.debug('Agent does not support telemetry; disabling future telemetry events.')
self.enabled = false
end

if res.ok?
elsif res.ok?
Datadog.logger.debug('Telemetry app-started event is successfully sent')
@sent_started_event = true
else
Datadog.logger.debug('Error sending telemetry app-started event, retry after heartbeat interval...')
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Datadog
module Core
module Telemetry
class Client
class Component
@enabled: bool
@dependency_collection: bool
@started: bool
Expand Down
18 changes: 9 additions & 9 deletions spec/datadog/core/configuration/components_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'datadog/core/diagnostics/environment_logger'
require 'datadog/core/diagnostics/health'
require 'datadog/core/logger'
require 'datadog/core/telemetry/client'
require 'datadog/core/telemetry/component'
require 'datadog/core/runtime/metrics'
require 'datadog/core/workers/runtime_metrics'
require 'datadog/statsd'
Expand All @@ -33,7 +33,7 @@

let(:profiler_setup_task) { Datadog::Profiling.supported? ? instance_double(Datadog::Profiling::Tasks::Setup) : nil }
let(:remote) { instance_double(Datadog::Core::Remote::Component, start: nil, shutdown!: nil) }
let(:telemetry) { instance_double(Datadog::Core::Telemetry::Client) }
let(:telemetry) { instance_double(Datadog::Core::Telemetry::Component) }

let(:environment_logger_extra) { { hello: 123, world: '456' } }

Expand All @@ -46,7 +46,7 @@
end
allow(Datadog::Statsd).to receive(:new) { instance_double(Datadog::Statsd) }
allow(Datadog::Core::Remote::Component).to receive(:new).and_return(remote)
allow(Datadog::Core::Telemetry::Client).to receive(:new).and_return(telemetry)
allow(Datadog::Core::Telemetry::Component).to receive(:new).and_return(telemetry)
end

around do |example|
Expand Down Expand Up @@ -223,7 +223,7 @@
let(:logger) { instance_double(Logger) }

context 'given settings' do
let(:telemetry_client) { instance_double(Datadog::Core::Telemetry::Client) }
let(:telemetry) { instance_double(Datadog::Core::Telemetry::Component) }
let(:expected_options) do
{ enabled: enabled, heartbeat_interval_seconds: heartbeat_interval_seconds,
dependency_collection: dependency_collection }
Expand All @@ -233,16 +233,16 @@
let(:dependency_collection) { true }

before do
expect(Datadog::Core::Telemetry::Client).to receive(:new).with(expected_options).and_return(telemetry_client)
expect(Datadog::Core::Telemetry::Component).to receive(:new).with(expected_options).and_return(telemetry)
allow(settings.telemetry).to receive(:enabled).and_return(enabled)
end

it { is_expected.to be(telemetry_client) }
it { is_expected.to be(telemetry) }

context 'with :enabled true' do
let(:enabled) { double('enabled') }

it { is_expected.to be(telemetry_client) }
it { is_expected.to be(telemetry) }

context 'and :unix agent adapter' do
let(:expected_options) do
Expand All @@ -255,7 +255,7 @@

it 'does not enable telemetry for unsupported non-http transport' do
expect(logger).to receive(:debug)
is_expected.to be(telemetry_client)
is_expected.to be(telemetry)
end
end
end
Expand Down Expand Up @@ -1108,7 +1108,7 @@
let(:runtime_metrics) { instance_double(Datadog::Core::Runtime::Metrics, statsd: statsd) }
let(:health_metrics) { instance_double(Datadog::Core::Diagnostics::Health::Metrics, statsd: statsd) }
let(:statsd) { instance_double(::Datadog::Statsd) }
let(:telemetry) { instance_double(Datadog::Core::Telemetry::Client) }
let(:telemetry) { instance_double(Datadog::Core::Telemetry::Component) }

before do
allow(replacement).to receive(:tracer).and_return(tracer)
Expand Down
20 changes: 10 additions & 10 deletions spec/datadog/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

RSpec.describe Datadog::Core::Configuration do
let(:default_log_level) { ::Logger::INFO }
let(:telemetry_client) { instance_double(Datadog::Core::Telemetry::Client) }
let(:telemetry) { instance_double(Datadog::Core::Telemetry::Component) }

before do
allow(telemetry_client).to receive(:started!)
allow(telemetry_client).to receive(:stop!)
allow(telemetry_client).to receive(:emit_closing!)
allow(Datadog::Core::Telemetry::Client).to receive(:new).and_return(telemetry_client)
allow(telemetry).to receive(:started!)
allow(telemetry).to receive(:stop!)
allow(telemetry).to receive(:emit_closing!)
allow(Datadog::Core::Telemetry::Component).to receive(:new).and_return(telemetry)
allow(Datadog::Core::Remote::Component).to receive(:build)
end

Expand Down Expand Up @@ -43,7 +43,7 @@
it do
# We cannot mix `expect().to_not` with `expect().to(...).ordered`.
# One way around that is to force the method to raise an error if it's ever called.
allow(telemetry_client).to receive(:started!).and_raise('Should not be called')
allow(telemetry).to receive(:started!).and_raise('Should not be called')

# Components should have changed
expect { configure }
Expand Down Expand Up @@ -84,7 +84,7 @@
.with(test_class.configuration)

expect(new_components).to_not have_received(:shutdown!)
expect(telemetry_client).to have_received(:started!)
expect(telemetry).to have_received(:started!)
end
end
end
Expand Down Expand Up @@ -501,7 +501,7 @@
describe '#components' do
context 'when components are not initialized' do
it 'initializes the components' do
expect(telemetry_client).to receive(:started!)
expect(telemetry).to receive(:started!)

test_class.send(:components)

Expand All @@ -510,7 +510,7 @@

context 'when allow_initialization is false' do
it 'does not initialize the components' do
expect(telemetry_client).to_not receive(:started!)
expect(telemetry).to_not receive(:started!)

test_class.send(:components, allow_initialization: false)

Expand All @@ -527,7 +527,7 @@
it 'returns the components without touching the COMPONENTS_WRITE_LOCK' do
described_class.const_get(:COMPONENTS_WRITE_LOCK).lock

expect(telemetry_client).to_not receive(:started!)
expect(telemetry).to_not receive(:started!)
expect(test_class.send(:components)).to_not be_nil
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'

require 'datadog/core/telemetry/client'
require 'datadog/core/telemetry/component'

RSpec.describe Datadog::Core::Telemetry::Client do
subject(:client) do
RSpec.describe Datadog::Core::Telemetry::Component do
subject(:telemetry) do
described_class.new(
enabled: enabled,
heartbeat_interval_seconds: heartbeat_interval_seconds,
Expand All @@ -27,54 +27,54 @@

describe '#initialize' do
after do
client.stop!
telemetry.stop!
end

context 'with default parameters' do
subject(:client) do
subject(:telemetry) do
described_class.new(
heartbeat_interval_seconds: heartbeat_interval_seconds,
dependency_collection: dependency_collection
)
end

it { is_expected.to be_a_kind_of(described_class) }
it { expect(client.enabled).to be(true) }
it { expect(telemetry.enabled).to be(true) }
end

context 'when :enabled is false' do
let(:enabled) { false }
it { is_expected.to be_a_kind_of(described_class) }
it { expect(client.enabled).to be(false) }
it { expect(telemetry.enabled).to be(false) }
end

context 'when enabled' do
let(:enabled) { true }

it { is_expected.to be_a_kind_of(described_class) }
it { expect(client.enabled).to be(true) }
it { expect(telemetry.enabled).to be(true) }
end
end

describe '#disable!' do
after do
client.stop!
telemetry.stop!
end

it { expect { client.disable! }.to change { client.enabled }.from(true).to(false) }
it { expect { telemetry.disable! }.to change { telemetry.enabled }.from(true).to(false) }

it 'disables worker' do
client.disable!
telemetry.disable!

expect(worker).to have_received(:"enabled=").with(false)
end
end

describe '#started!' do
subject(:started!) { client.started! }
subject(:started!) { telemetry.started! }

after do
client.stop!
telemetry.stop!
end

context 'when disabled' do
Expand Down Expand Up @@ -114,9 +114,9 @@
before { skip 'Fork not supported on current platform' unless Process.respond_to?(:fork) }

it do
client
telemetry
expect_in_fork do
client.started!
telemetry.started!

expect(worker).to_not have_received(:start)
end
Expand All @@ -125,10 +125,10 @@
end

describe '#emit_closing!' do
subject(:emit_closing!) { client.emit_closing! }
subject(:emit_closing!) { telemetry.emit_closing! }

after do
client.stop!
telemetry.stop!
end

context 'when disabled' do
Expand All @@ -155,9 +155,9 @@
before { skip 'Fork not supported on current platform' unless Process.respond_to?(:fork) }

it do
client
telemetry
expect_in_fork do
client.started!
telemetry.started!

expect(worker).not_to have_received(:enqueue)
end
Expand All @@ -166,7 +166,7 @@
end

describe '#stop!' do
subject(:stop!) { client.stop! }
subject(:stop!) { telemetry.stop! }

it 'stops worker once' do
stop!
Expand All @@ -177,10 +177,10 @@
end

describe '#integrations_change!' do
subject(:integrations_change!) { client.integrations_change! }
subject(:integrations_change!) { telemetry.integrations_change! }

after do
client.stop!
telemetry.stop!
end

context 'when disabled' do
Expand All @@ -207,9 +207,9 @@
before { skip 'Fork not supported on current platform' unless Process.respond_to?(:fork) }

it do
client
telemetry
expect_in_fork do
client.started!
telemetry.started!

expect(worker).not_to have_received(:enqueue)
end
Expand All @@ -218,11 +218,11 @@
end

describe '#client_configuration_change!' do
subject(:client_configuration_change!) { client.client_configuration_change!(changes) }
subject(:client_configuration_change!) { telemetry.client_configuration_change!(changes) }
let(:changes) { double('changes') }

after do
client.stop!
telemetry.stop!
end

context 'when disabled' do
Expand All @@ -249,9 +249,9 @@
before { skip 'Fork not supported on current platform' unless Process.respond_to?(:fork) }

it do
client
telemetry
expect_in_fork do
client.started!
telemetry.started!

expect(worker).not_to have_received(:enqueue)
end
Expand Down

0 comments on commit 39bd8eb

Please sign in to comment.