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.
This commit is contained in:
Yorick Peterse 2016-06-14 14:35:25 +02:00
parent 82090d291f
commit ab91f1226f
No known key found for this signature in database
GPG key ID: EDD30D2BEB691AC9
2 changed files with 23 additions and 8 deletions

View file

@ -66,7 +66,11 @@ module Gitlab
def sample_objects
sample = Allocations.to_hash
counts = sample.each_with_object({}) do |(klass, count), hash|
hash[klass.name] = count
name = klass.name
next unless name
hash[name] = count
end
# Symbols aren't allocated so we'll need to add those manually.

View file

@ -72,14 +72,25 @@ describe Gitlab::Metrics::Sampler do
end
end
describe '#sample_objects' do
it 'adds a metric containing the amount of allocated objects' do
expect(sampler).to receive(:add_metric).
with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)).
at_least(:once).
and_call_original
if Gitlab::Metrics.mri?
describe '#sample_objects' do
it 'adds a metric containing the amount of allocated objects' do
expect(sampler).to receive(:add_metric).
with(/object_counts/, an_instance_of(Hash), an_instance_of(Hash)).
at_least(:once).
and_call_original
sampler.sample_objects
sampler.sample_objects
end
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