Skip to content

Commit

Permalink
Refactor crashtracking to use AgentSettings#url
Browse files Browse the repository at this point in the history
The behavior from the old `AgentBaseUrl` is now contained in
`AgentSettings` so we can clean up the extra logic.
  • Loading branch information
ivoanjo committed Jan 2, 2025
1 parent 6ada623 commit 65c92d2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 139 deletions.
16 changes: 0 additions & 16 deletions lib/datadog/core/crashtracking/agent_base_url.rb

This file was deleted.

4 changes: 1 addition & 3 deletions lib/datadog/core/crashtracking/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'libdatadog'

require_relative 'tag_builder'
require_relative 'agent_base_url'
require_relative '../utils/only_once'
require_relative '../utils/at_fork_monkey_patch'

Expand Down Expand Up @@ -31,8 +30,7 @@ class Component

def self.build(settings, agent_settings, logger:)
tags = TagBuilder.call(settings)
agent_base_url = AgentBaseUrl.resolve(agent_settings)
logger.warn('Missing agent base URL; cannot enable crash tracking') unless agent_base_url
agent_base_url = agent_settings.url

ld_library_path = ::Libdatadog.ld_library_path
logger.warn('Missing ld_library_path; cannot enable crash tracking') unless ld_library_path
Expand Down
10 changes: 0 additions & 10 deletions sig/datadog/core/crashtracking/agent_base_url.rbs

This file was deleted.

83 changes: 0 additions & 83 deletions spec/datadog/core/crashtracking/agent_base_url_spec.rb

This file was deleted.

34 changes: 7 additions & 27 deletions spec/datadog/core/crashtracking/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

describe '.build' do
let(:settings) { Datadog::Core::Configuration::Settings.new }
let(:agent_settings) { double('agent_settings') }
let(:agent_settings) do
instance_double(Datadog::Core::Configuration::AgentSettingsResolver::AgentSettings)
end
let(:tags) { { 'tag1' => 'value1' } }
let(:agent_base_url) { 'agent_base_url' }
let(:ld_library_path) { 'ld_library_path' }
Expand All @@ -19,8 +21,7 @@
it 'creates a new instance of Component and starts it' do
expect(Datadog::Core::Crashtracking::TagBuilder).to receive(:call).with(settings)
.and_return(tags)
expect(Datadog::Core::Crashtracking::AgentBaseUrl).to receive(:resolve).with(agent_settings)
.and_return(agent_base_url)
expect(agent_settings).to receive(:url).and_return(agent_base_url)
expect(::Libdatadog).to receive(:ld_library_path)
.and_return(ld_library_path)
expect(::Libdatadog).to receive(:path_to_crashtracking_receiver_binary)
Expand All @@ -42,32 +43,13 @@
end
end

context 'when missing `agent_base_url`' do
let(:agent_base_url) { nil }

it 'returns nil' do
expect(Datadog::Core::Crashtracking::TagBuilder).to receive(:call).with(settings)
.and_return(tags)
expect(Datadog::Core::Crashtracking::AgentBaseUrl).to receive(:resolve).with(agent_settings)
.and_return(agent_base_url)
expect(::Libdatadog).to receive(:ld_library_path)
.and_return(ld_library_path)
expect(::Libdatadog).to receive(:path_to_crashtracking_receiver_binary)
.and_return(path_to_crashtracking_receiver_binary)
expect(logger).to receive(:warn).with(/cannot enable crash tracking/)

expect(described_class.build(settings, agent_settings, logger: logger)).to be_nil
end
end

context 'when missing `ld_library_path`' do
let(:ld_library_path) { nil }

it 'returns nil' do
expect(Datadog::Core::Crashtracking::TagBuilder).to receive(:call).with(settings)
.and_return(tags)
expect(Datadog::Core::Crashtracking::AgentBaseUrl).to receive(:resolve).with(agent_settings)
.and_return(agent_base_url)
expect(agent_settings).to receive(:url).and_return(agent_base_url)
expect(::Libdatadog).to receive(:ld_library_path)
.and_return(ld_library_path)
expect(::Libdatadog).to receive(:path_to_crashtracking_receiver_binary)
Expand All @@ -84,8 +66,7 @@
it 'returns nil' do
expect(Datadog::Core::Crashtracking::TagBuilder).to receive(:call).with(settings)
.and_return(tags)
expect(Datadog::Core::Crashtracking::AgentBaseUrl).to receive(:resolve).with(agent_settings)
.and_return(agent_base_url)
expect(agent_settings).to receive(:url).and_return(agent_base_url)
expect(::Libdatadog).to receive(:ld_library_path)
.and_return(ld_library_path)
expect(::Libdatadog).to receive(:path_to_crashtracking_receiver_binary)
Expand All @@ -102,8 +83,7 @@
it 'returns an instance of Component that failed to start' do
expect(Datadog::Core::Crashtracking::TagBuilder).to receive(:call).with(settings)
.and_return(tags)
expect(Datadog::Core::Crashtracking::AgentBaseUrl).to receive(:resolve).with(agent_settings)
.and_return(agent_base_url)
expect(agent_settings).to receive(:url).and_return(agent_base_url)
expect(::Libdatadog).to receive(:ld_library_path)
.and_return(ld_library_path)
expect(::Libdatadog).to receive(:path_to_crashtracking_receiver_binary)
Expand Down

0 comments on commit 65c92d2

Please sign in to comment.