diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-10-24 11:57:29 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-11-02 18:18:16 +0100 |
commit | c9f0070b649cac40eb7a93639726aee63a1f4cc8 (patch) | |
tree | e947f94fedf9130b24f53f8334a5461b2b7e73bf | |
parent | a300787fa99faccb7002a3a8df6f703b08e1a090 (diff) | |
download | gitlab-ce-c9f0070b649cac40eb7a93639726aee63a1f4cc8.tar.gz |
Make subscriber tests pass, after refactoring metrics
6 files changed, 11 insertions, 11 deletions
diff --git a/lib/gitlab/metrics/subscribers/action_view.rb b/lib/gitlab/metrics/subscribers/action_view.rb index 891fa92e3f7..3da474fc1ec 100644 --- a/lib/gitlab/metrics/subscribers/action_view.rb +++ b/lib/gitlab/metrics/subscribers/action_view.rb @@ -28,7 +28,7 @@ module Gitlab values = values_for(event) tags = tags_for(event) - self.metric_view_rendering_duration_seconds.observe( + metric_view_rendering_duration_seconds.observe( current_transaction.labels.merge(tags), event.duration ) diff --git a/lib/gitlab/metrics/subscribers/rails_cache.rb b/lib/gitlab/metrics/subscribers/rails_cache.rb index 7383e384d66..efd3c9daf79 100644 --- a/lib/gitlab/metrics/subscribers/rails_cache.rb +++ b/lib/gitlab/metrics/subscribers/rails_cache.rb @@ -15,7 +15,7 @@ module Gitlab if event.payload[:hit] current_transaction.increment(:cache_read_hit_count, 1, false) else - self.metric_cache_misses_total.increment(current_transaction.labels) + metric_cache_misses_total.increment(current_transaction.labels) current_transaction.increment(:cache_read_miss_count, 1, false) end end @@ -41,14 +41,14 @@ module Gitlab def cache_generate(event) return unless current_transaction - self.metric_cache_misses_total.increment(current_transaction.labels) + metric_cache_misses_total.increment(current_transaction.labels) current_transaction.increment(:cache_read_miss_count, 1) end def observe(key, duration) return unless current_transaction - self.metric_cache_operation_duration_seconds.observe(current_transaction.labels.merge({ operation: key }), duration / 1000.0) + metric_cache_operation_duration_seconds.observe(current_transaction.labels.merge({ operation: key }), duration / 1000.0) current_transaction.increment(:cache_duration, duration, false) current_transaction.increment(:cache_count, 1, false) current_transaction.increment("cache_#{key}_duration".to_sym, duration, false) diff --git a/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb b/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb index b2887911194..eca75a4fac1 100644 --- a/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb @@ -32,7 +32,7 @@ describe Gitlab::Metrics::Subscribers::ActionView do end it 'observes view rendering time' do - expect(described_class.metric_view_rendering_duration_seconds) + expect(subscriber.send(:metric_view_rendering_duration_seconds)) .to receive(:observe) .with({ view: 'app/views/x.html.haml' }, 2.1) diff --git a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb index ef2945970c1..9b3698fb4a8 100644 --- a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb @@ -25,7 +25,7 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do expect(subscriber).to receive(:current_transaction) .at_least(:once) .and_return(transaction) - expect(described_class.metric_sql_duration_seconds).to receive(:observe).with({}, 0.002) + expect(subscriber.send(:metric_sql_duration_seconds)).to receive(:observe).with({}, 0.002) subscriber.sql(event) end diff --git a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb index 4203be40332..58e28592cf9 100644 --- a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb @@ -58,7 +58,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do end it 'increments the cache_read_miss total' do - expect(described_class.metric_cache_misses_total).to receive(:increment).with({}) + expect(subscriber.send(:metric_cache_misses_total)).to receive(:increment).with({}) subscriber.cache_read(event) end @@ -74,7 +74,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do end it 'does not increment cache_read_miss total' do - expect(described_class.metric_cache_misses_total).not_to receive(:increment).with({}) + expect(subscriber.send(:metric_cache_misses_total)).not_to receive(:increment).with({}) subscriber.cache_read(event) end @@ -157,7 +157,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do end it 'increments the cache_read_miss total' do - expect(described_class.metric_cache_misses_total).to receive(:increment).with({}) + expect(subscriber.send(:metric_cache_misses_total)).to receive(:increment).with({}) subscriber.cache_generate(event) end @@ -196,7 +196,7 @@ describe Gitlab::Metrics::Subscribers::RailsCache do end it 'observes cache metric' do - expect(described_class.metric_cache_operation_duration_seconds) + expect(subscriber.send(:metric_cache_operation_duration_seconds)) .to receive(:observe) .with(transaction.labels.merge(operation: :delete), event.duration / 1000.0) diff --git a/spec/lib/gitlab/middleware/rails_queue_duration_spec.rb b/spec/lib/gitlab/middleware/rails_queue_duration_spec.rb index e64c4884fef..14f2c3cb86f 100644 --- a/spec/lib/gitlab/middleware/rails_queue_duration_spec.rb +++ b/spec/lib/gitlab/middleware/rails_queue_duration_spec.rb @@ -34,7 +34,7 @@ describe Gitlab::Middleware::RailsQueueDuration do it 'observes rails queue duration metrics and calls the app when the header is present' do env['HTTP_GITLAB_WORKHORSE_PROXY_START'] = '2000000000' - expect(described_class.metric_rails_queue_duration_seconds).to receive(:observe).with(transaction.labels, 1) + expect(middleware.send(:metric_rails_queue_duration_seconds)).to receive(:observe).with(transaction.labels, 1) Timecop.freeze(Time.at(3)) do expect(middleware.call(env)).to eq('yay') |