Skip to content

Commit

Permalink
Track new Ruby 3.2 VM cache metrics
Browse files Browse the repository at this point in the history
In Ruby 3.2 the `class_serial` and `global_constant_state` VM metrics
were removed in favor of the new `constant_cache_invalidations` and
`constant_cache_misses` metrics.

Report these new metrics when available. This does not require an update
to the "Ruby (VM) metrics" magic dashboard definition.

ruby/ruby@13bd617
ruby/ruby@6068da8
  • Loading branch information
tombruijn committed Dec 7, 2022
1 parent 87b6ed5 commit 2b1964d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changesets/track-new-ruby-3-2-vm-cache-metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "change"
---

Track new Ruby 3.2 VM cache metrics. In Ruby 3.2 the `class_serial` and `global_constant_state` metrics are no longer reported for the "Ruby (VM) metrics" magic dashboard, because Ruby 3.2 removed these metrics. Instead we will now report the new `constant_cache_invalidations` and `constant_cache_misses` metrics reported by Ruby 3.2.
43 changes: 32 additions & 11 deletions lib/appsignal/probes/mri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,38 @@ def initialize(appsignal: Appsignal, gc_profiler: Appsignal::GarbageCollection.p
def call
stat = RubyVM.stat

set_gauge(
"ruby_vm",
stat[:class_serial],
:metric => :class_serial
)

set_gauge(
"ruby_vm",
stat[:constant_cache] ? stat[:constant_cache].values.sum : stat[:global_constant_state],
:metric => :global_constant_state
)
constant_cache_invalidations = stat[:constant_cache_invalidations]
if constant_cache_invalidations
set_gauge(
"ruby_vm",
constant_cache_invalidations,
:metric => :constant_cache_invalidations
)
end

constant_cache_misses = stat[:constant_cache_misses]
if constant_cache_misses
set_gauge(
"ruby_vm",
constant_cache_misses,
:metric => :constant_cache_misses
)
end

class_serial = stat[:class_serial]
if class_serial
set_gauge("ruby_vm", class_serial, :metric => :class_serial)
end

global_constant_state =
stat[:constant_cache] ? stat[:constant_cache].values.sum : stat[:global_constant_state]
if global_constant_state
set_gauge(
"ruby_vm",
global_constant_state,
:metric => :global_constant_state
)
end

set_gauge("thread_count", Thread.list.size)
if Appsignal::GarbageCollection.enabled?
Expand Down
11 changes: 8 additions & 3 deletions spec/lib/appsignal/probes/mri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ def set_gauge(*args) # rubocop:disable Naming/AccessorMethodName
allow(GC::Profiler).to receive(:enabled?).and_return(true)
end

it "should track vm metrics" do
it "should track vm cache metrics" do
probe.call
expect_gauge_value("ruby_vm", :tags => { :metric => :class_serial })
expect_gauge_value("ruby_vm", :tags => { :metric => :global_constant_state })
if DependencyHelper.ruby_3_2_or_newer?
expect_gauge_value("ruby_vm", :tags => { :metric => :constant_cache_invalidations })
expect_gauge_value("ruby_vm", :tags => { :metric => :constant_cache_misses })
else
expect_gauge_value("ruby_vm", :tags => { :metric => :class_serial })
expect_gauge_value("ruby_vm", :tags => { :metric => :global_constant_state })
end
end

it "tracks thread counts" do
Expand Down
4 changes: 4 additions & 0 deletions spec/support/helpers/dependency_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def ruby_3_1_or_newer?
ruby_version >= Gem::Version.new("3.1.0")
end

def ruby_3_2_or_newer?
ruby_version >= Gem::Version.new("3.2.0")
end

def running_jruby?
Appsignal::System.jruby?
end
Expand Down

0 comments on commit 2b1964d

Please sign in to comment.