Commit c9f0070b authored by Pawel Chojnacki's avatar Pawel Chojnacki

Make subscriber tests pass, after refactoring metrics

parent a300787f
......@@ -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
)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
......@@ -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)
......
......@@ -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')
......
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