diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-22 15:06:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-22 15:06:20 +0300 |
commit | b1bcdba89bc241e2cede910f26cf3f5fff8d7901 (patch) | |
tree | 41b45ec9ff1ba56c93b29b00435495e7e5abf02b /spec/lib/gitlab/sidekiq_middleware | |
parent | 30dc5b50569db30fef06cc7ab66e7341161b3c70 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/sidekiq_middleware')
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware/metrics_spec.rb | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/spec/lib/gitlab/sidekiq_middleware/metrics_spec.rb b/spec/lib/gitlab/sidekiq_middleware/metrics_spec.rb index 806112fcb16..ec4c8560f22 100644 --- a/spec/lib/gitlab/sidekiq_middleware/metrics_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/metrics_spec.rb @@ -3,25 +3,37 @@ require 'spec_helper' describe Gitlab::SidekiqMiddleware::Metrics do - describe '#call' do - let(:middleware) { described_class.new } - let(:worker) { double(:worker) } - - let(:completion_seconds_metric) { double('completion seconds metric') } - let(:user_execution_seconds_metric) { double('user execution seconds metric') } - let(:failed_total_metric) { double('failed total metric') } - let(:retried_total_metric) { double('retried total metric') } - let(:running_jobs_metric) { double('running jobs metric') } + let(:middleware) { described_class.new } + + let(:concurrency_metric) { double('concurrency metric') } + let(:completion_seconds_metric) { double('completion seconds metric') } + let(:user_execution_seconds_metric) { double('user execution seconds metric') } + let(:failed_total_metric) { double('failed total metric') } + let(:retried_total_metric) { double('retried total metric') } + let(:running_jobs_metric) { double('running jobs metric') } + + before do + allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_completion_seconds, anything, anything, anything).and_return(completion_seconds_metric) + allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_cpu_seconds, anything, anything, anything).and_return(user_execution_seconds_metric) + allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_failed_total, anything).and_return(failed_total_metric) + allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_retried_total, anything).and_return(retried_total_metric) + allow(Gitlab::Metrics).to receive(:gauge).with(:sidekiq_running_jobs, anything, {}, :all).and_return(running_jobs_metric) + allow(Gitlab::Metrics).to receive(:gauge).with(:sidekiq_concurrency, anything, {}, :all).and_return(concurrency_metric) + + allow(running_jobs_metric).to receive(:increment) + allow(concurrency_metric).to receive(:set) + end - before do - allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_completion_seconds, anything, anything, anything).and_return(completion_seconds_metric) - allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_cpu_seconds, anything, anything, anything).and_return(user_execution_seconds_metric) - allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_failed_total, anything).and_return(failed_total_metric) - allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_retried_total, anything).and_return(retried_total_metric) - allow(Gitlab::Metrics).to receive(:gauge).with(:sidekiq_running_jobs, anything, {}, :livesum).and_return(running_jobs_metric) + describe '#initialize' do + it 'sets general metrics' do + expect(concurrency_metric).to receive(:set).with({}, Sidekiq.options[:concurrency].to_i) - allow(running_jobs_metric).to receive(:increment) + middleware end + end + + describe '#call' do + let(:worker) { double(:worker) } it 'yields block' do allow(completion_seconds_metric).to receive(:observe) @@ -30,7 +42,7 @@ describe Gitlab::SidekiqMiddleware::Metrics do expect { |b| middleware.call(worker, {}, :test, &b) }.to yield_control.once end - it 'sets metrics' do + it 'sets queue specific metrics' do labels = { queue: :test } allow(middleware).to receive(:get_thread_cputime).and_return(1, 3) |