Commit ab91f122 authored by Yorick Peterse's avatar Yorick Peterse

Filter out classes without names in the sampler

We can't do a lot with classes without names as we can't filter by them,
have no idea where they come from, etc. As such it's best to just ignore
these.
parent 82090d29
...@@ -66,7 +66,11 @@ module Gitlab ...@@ -66,7 +66,11 @@ module Gitlab
def sample_objects def sample_objects
sample = Allocations.to_hash sample = Allocations.to_hash
counts = sample.each_with_object({}) do |(klass, count), hash| counts = sample.each_with_object({}) do |(klass, count), hash|
hash[klass.name] = count name = klass.name
next unless name
hash[name] = count
end end
# Symbols aren't allocated so we'll need to add those manually. # Symbols aren't allocated so we'll need to add those manually.
......
...@@ -72,14 +72,25 @@ describe Gitlab::Metrics::Sampler do ...@@ -72,14 +72,25 @@ describe Gitlab::Metrics::Sampler do
end end
end end
describe '#sample_objects' do if Gitlab::Metrics.mri?
it 'adds a metric containing the amount of allocated objects' do describe '#sample_objects' do
expect(sampler).to receive(:add_metric). it 'adds a metric containing the amount of allocated objects' do
with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)). expect(sampler).to receive(:add_metric).
at_least(:once). with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)).
and_call_original at_least(:once).
and_call_original
sampler.sample_objects
end
sampler.sample_objects it 'ignores classes without a name' do
expect(Allocations).to receive(:to_hash).and_return({ Class.new => 4 })
expect(sampler).not_to receive(:add_metric).
with('object_counts', an_instance_of(Hash), type: nil)
sampler.sample_objects
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment