Skip to content

Commit 41c5624

Browse files
committed
fix profiler enablement reporting
1 parent 0323cda commit 41c5624

File tree

6 files changed

+59
-33
lines changed

6 files changed

+59
-33
lines changed

lib/datadog/core/telemetry/event/app_started.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def products(components)
5555
enabled: components.settings.appsec.enabled,
5656
},
5757
profiler: {
58-
enabled: !!components.profiler&.enabled?,
58+
enabled: !!components.profiler,
5959
},
6060
dynamic_instrumentation: {
6161
enabled: !!components.dynamic_instrumentation,

lib/datadog/profiling.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def self.allocation_count
6161
end
6262

6363
def self.enabled?
64-
profiler = Datadog.send(:components).profiler
65-
!!profiler&.enabled?
64+
!!Datadog.send(:components).profiler
6665
end
6766

6867
def self.wait_until_running(timeout_seconds: 5)

lib/datadog/profiling/profiler.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ def initialize(worker:, scheduler:)
1717
@scheduler = scheduler
1818
end
1919

20-
def enabled?
21-
scheduler.running?
22-
end
23-
2420
def start
2521
after_fork! do
2622
worker.reset_after_fork

spec/datadog/core/telemetry/integration/telemetry_spec.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,61 @@
468468
end
469469
end
470470

471+
describe 'app-started event' do
472+
context 'when profiling is enabled' do
473+
http_server do |http_server|
474+
http_server.mount_proc('/telemetry/proxy/api/v2/apmtelemetry', &handler_proc)
475+
end
476+
477+
before do
478+
Datadog.configure do |c|
479+
c.agent.port = http_server_port
480+
c.telemetry.enabled = true
481+
482+
c.profiling.enabled = true
483+
end
484+
end
485+
486+
after do
487+
Datadog.configuration.reset!
488+
end
489+
490+
let(:settings) do
491+
Datadog.configuration
492+
end
493+
494+
let(:component) { Datadog.send(:components).telemetry }
495+
496+
it 'reports profiling as being enabled' do
497+
component.flush
498+
expect(sent_payloads.length).to eq 3
499+
500+
payload = sent_payloads[0]
501+
expect(payload.fetch(:payload)).to include(
502+
'request_type' => 'app-started',
503+
)
504+
expect(payload.fetch(:payload).dig('payload', 'products')).to include(
505+
'profiler' => {'enabled' => true},
506+
)
507+
508+
# For sanity checking verify that the remaining events are as we
509+
# expect them to be.
510+
payload = sent_payloads[1]
511+
expect(payload.fetch(:payload)).to include(
512+
'request_type' => 'app-dependencies-loaded',
513+
)
514+
515+
payload = sent_payloads[2]
516+
expect(payload.fetch(:payload)).to include(
517+
'request_type' => 'message-batch',
518+
)
519+
expect(payload.fetch(:payload).fetch('payload').first).to include(
520+
'request_type' => 'app-integrations-change',
521+
)
522+
end
523+
end
524+
end
525+
471526
context 'when process forks' do
472527
# The mode is irrelevant but we need settings from the context.
473528
include_context 'agent mode'

spec/datadog/profiling/profiler_spec.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@
1313
let(:worker) { instance_double(Datadog::Profiling::Collectors::CpuAndWallTimeWorker) }
1414
let(:scheduler) { instance_double(Datadog::Profiling::Scheduler) }
1515

16-
describe '.enabled?' do
17-
subject(:enabled?) { profiler.enabled? }
18-
19-
let(:scheduler) { instance_double('Datadog::Profiling::Scheduler', running?: running) }
20-
21-
context 'when the profiler is running' do
22-
let(:running) { true }
23-
it { is_expected.to be(true) }
24-
end
25-
26-
context 'when the profiler is not running' do
27-
let(:running) { false }
28-
it { is_expected.to be(false) }
29-
end
30-
end
31-
3216
describe "#start" do
3317
subject(:start) { profiler.start }
3418

spec/datadog/profiling_spec.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,9 @@
7272
end
7373

7474
context 'when a profiler is available' do
75-
let(:profiler) { instance_double('Datadog::Profiling::Profiler', enabled?: enabled) }
75+
let(:profiler) { instance_double(Datadog::Profiling::Profiler) }
7676

77-
context 'when the profiler is enabled' do
78-
let(:enabled) { true }
79-
it { is_expected.to be(true) }
80-
end
81-
82-
context 'when the profiler is not enabled' do
83-
let(:enabled) { false }
84-
it { is_expected.to be(false) }
85-
end
77+
it { is_expected.to be(true) }
8678
end
8779
end
8880

0 commit comments

Comments
 (0)