diff options
author | Ryan Cobb <rcobb@gitlab.com> | 2019-04-24 11:41:54 -0600 |
---|---|---|
committer | Ryan Cobb <rcobb@gitlab.com> | 2019-04-24 13:01:51 -0600 |
commit | 174a03dfc284781d811df1874ce3cf11d451a8f5 (patch) | |
tree | 2cdd5c937bdb337476a729cba1e789514186c5f1 /spec | |
parent | 4c248c05cbd1356199cc96775b68fbbde64d4d5d (diff) | |
download | gitlab-ce-174a03dfc284781d811df1874ce3cf11d451a8f5.tar.gz |
Move process specific metrics to ruby sampler
These metrics are not unicorn specific and can be used across ruby
processes
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb | 7 |
2 files changed, 25 insertions, 8 deletions
diff --git a/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb index 7972ff253fe..0fafcb8e380 100644 --- a/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb +++ b/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb @@ -10,8 +10,11 @@ describe Gitlab::Metrics::Samplers::RubySampler do describe '#sample' do it 'samples various statistics' do - expect(Gitlab::Metrics::System).to receive(:memory_usage) + expect(Gitlab::Metrics::System).to receive(:cpu_time) expect(Gitlab::Metrics::System).to receive(:file_descriptor_count) + expect(Gitlab::Metrics::System).to receive(:memory_usage) + expect(Gitlab::Metrics::System).to receive(:process_start_time) + expect(Gitlab::Metrics::System).to receive(:max_open_file_descriptors) expect(sampler).to receive(:sample_gc) sampler.sample @@ -34,6 +37,27 @@ describe Gitlab::Metrics::Samplers::RubySampler do sampler.sample end + it 'adds a metric containing the processes total cpu time' do + expect(Gitlab::Metrics::System).to receive(:cpu_time).and_return(0.51) + expect(sampler.metrics[:process_cpu_seconds_total]).to receive(:set).with({}, 0.51) + + sampler.sample + end + + it 'adds a metric containing the process start time' do + expect(Gitlab::Metrics::System).to receive(:process_start_time).and_return(12345) + expect(sampler.metrics[:process_start_time_seconds]).to receive(:set).with({}, 12345) + + sampler.sample + end + + it 'adds a metric containing the process max file descriptors' do + expect(Gitlab::Metrics::System).to receive(:max_open_file_descriptors).and_return(1024) + expect(sampler.metrics[:process_max_fds]).to receive(:set).with({}, 1024) + + sampler.sample + end + it 'clears any GC profiles' do expect(GC::Profiler).to receive(:clear) diff --git a/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb index 4470dc3ee93..0edbfc869a6 100644 --- a/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb +++ b/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb @@ -80,22 +80,15 @@ describe Gitlab::Metrics::Samplers::UnicornSampler do context 'additional metrics' do let(:cpu_time) { 3.14 } - let(:process_start_time) { 19100.24 } - let(:process_max_fds) { 1024 } let(:unicorn_workers) { 2 } before do allow(unicorn).to receive(:listener_names).and_return([""]) allow(::Gitlab::Metrics::System).to receive(:cpu_time).and_return(cpu_time) - allow(::Gitlab::Metrics::System).to receive(:process_start_time).and_return(process_start_time) - allow(::Gitlab::Metrics::System).to receive(:max_open_file_descriptors).and_return(process_max_fds) allow(subject).to receive(:unicorn_workers_count).and_return(unicorn_workers) end it "sets additional metrics" do - expect(subject.metrics[:process_cpu_seconds_total]).to receive(:set).with({ pid: nil }, cpu_time) - expect(subject.metrics[:process_start_time_seconds]).to receive(:set).with({ pid: nil }, process_start_time) - expect(subject.metrics[:process_max_fds]).to receive(:set).with({ pid: nil }, process_max_fds) expect(subject.metrics[:unicorn_workers]).to receive(:set).with({}, unicorn_workers) subject.sample |