Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only report gc_time metric if profiler is enabled #877

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changesets/support-temporarily-disabling-gc-profiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

Support temporarily disabling GC profiling without reporting inaccurate `gc_time` metric durations. The MRI probe's `gc_time` will not report any value when the `GC::Profiler.enabled?` returns `false`.
6 changes: 4 additions & 2 deletions lib/appsignal/probes/mri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def call
)

set_gauge("thread_count", Thread.list.size)
gauge_delta(:gc_time, @gc_profiler.total_time) do |gc_time|
set_gauge("gc_time", gc_time) if gc_time > 0
if GC::Profiler.enabled?
gauge_delta(:gc_time, @gc_profiler.total_time) do |gc_time|
set_gauge("gc_time", gc_time) if gc_time > 0
end
end

gc_stats = GC.stat
Expand Down
35 changes: 35 additions & 0 deletions spec/lib/appsignal/probes/mri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def set_gauge(*args) # rubocop:disable Naming/AccessorMethodName
let(:hostname) { nil }
before do
allow(gc_profiler_mock).to receive(:total_time)
allow(GC::Profiler).to receive(:enabled?).and_return(true)
end

it "should track vm metrics" do
Expand Down Expand Up @@ -70,6 +71,40 @@ def set_gauge(*args) # rubocop:disable Naming/AccessorMethodName
end
end

context "when GC profiling is disabled" do
it "does not report a gc_time metric" do
allow(GC::Profiler).to receive(:enabled?).and_return(false)
expect(gc_profiler_mock).to_not receive(:total_time)
probe.call # Normal call, create a cache
probe.call # Report delta value based on cached value
metrics = appsignal_mock.gauges.map { |(key)| key }
expect(metrics).to_not include("gc_time")
end

it "does not report a gc_time metric while disable" do
# While enabled
allow(GC::Profiler).to receive(:enabled?).and_return(true)
expect(gc_profiler_mock).to receive(:total_time).and_return(10, 15)
probe.call # Normal call, create a cache
probe.call # Report delta value based on cached value
expect_gauges([["gc_time", 5]])

# While disabled
allow(GC::Profiler).to receive(:enabled?).and_return(false)
probe.call # Call twice to make sure any caches resets wouldn't mess up the assertion
probe.call
# Does not include any newly reported metrics
expect_gauges([["gc_time", 5]])

# When enabled after being disabled for a while, it only reports the
# newly reported time since it was renabled
allow(GC::Profiler).to receive(:enabled?).and_return(true)
expect(gc_profiler_mock).to receive(:total_time).and_return(25)
probe.call
expect_gauges([["gc_time", 5], ["gc_time", 10]])
end
end

it "tracks GC run count" do
expect(GC).to receive(:count).and_return(10, 15)
expect(GC).to receive(:stat).and_return(
Expand Down