Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/metrics/subscribers')
-rw-r--r--spec/lib/gitlab/metrics/subscribers/action_view_spec.rb6
-rw-r--r--spec/lib/gitlab/metrics/subscribers/active_record_spec.rb17
-rw-r--r--spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb69
3 files changed, 28 insertions, 64 deletions
diff --git a/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb b/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb
index 161527c01aa..adbc474343f 100644
--- a/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb
+++ b/spec/lib/gitlab/metrics/subscribers/action_view_spec.rb
@@ -22,15 +22,15 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActionView do
describe '#render_template' do
it 'tracks rendering of a template' do
expect(transaction).to receive(:increment)
- .with(:view_duration, 2.1)
+ .with(:gitlab_transaction_view_duration_total, 2.1)
subscriber.render_template(event)
end
it 'observes view rendering time' do
- expect(described_class.gitlab_view_rendering_duration_seconds)
+ expect(transaction)
.to receive(:observe)
- .with({ view: 'app/views/x.html.haml' }, 2.1)
+ .with(:gitlab_view_rendering_duration_seconds, 2.1, { view: "app/views/x.html.haml" })
subscriber.render_template(event)
end
diff --git a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
index 2fd5dd1d83b..a31686b8061 100644
--- a/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
+++ b/spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
@@ -37,10 +37,11 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
it 'increments only db count value' do
described_class::DB_COUNTERS.each do |counter|
+ prometheus_counter = "gitlab_transaction_#{counter}_total".to_sym
if expected_counters[counter] > 0
- expect(transaction).to receive(:increment).with(counter, 1)
+ expect(transaction).to receive(:increment).with(prometheus_counter, 1)
else
- expect(transaction).not_to receive(:increment).with(counter, 1)
+ expect(transaction).not_to receive(:increment).with(prometheus_counter, 1)
end
end
@@ -74,10 +75,18 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
expect(subscriber).to receive(:current_transaction)
.at_least(:once)
.and_return(transaction)
- expect(described_class.send(:gitlab_sql_duration_seconds)).to receive(:observe).with({}, 0.002)
+ expect(transaction).to receive(:observe).with(:gitlab_sql_duration_seconds, 0.002)
+
subscriber.sql(event)
end
+ it 'marks the current thread as using the database' do
+ # since it would already have been toggled by other specs
+ Thread.current[:uses_db_connection] = nil
+
+ expect { subscriber.sql(event) }.to change { Thread.current[:uses_db_connection] }.from(nil).to(true)
+ end
+
context 'with read query' do
let(:expected_counters) do
{
@@ -217,7 +226,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::ActiveRecord do
end
it 'skips schema/begin/commit sql commands' do
- expect(subscriber).to receive(:current_transaction)
+ allow(subscriber).to receive(:current_transaction)
.at_least(:once)
.and_return(transaction)
diff --git a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
index f7ac719c16a..9aba6ac293c 100644
--- a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
+++ b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
@@ -26,21 +26,12 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do
context 'with hit event' do
let(:event) { double(:event, duration: 15.2, payload: { hit: true }) }
- it 'increments the cache_read_hit count' do
- expect(transaction).to receive(:increment)
- .with(:cache_read_hit_count, 1, false)
- expect(transaction).to receive(:increment)
- .with(any_args).at_least(1) # Other calls
-
- subscriber.cache_read(event)
- end
-
context 'when super operation is fetch' do
let(:event) { double(:event, duration: 15.2, payload: { hit: true, super_operation: :fetch }) }
- it 'does not increment cache read miss' do
+ it 'does not increment cache read miss total' do
expect(transaction).not_to receive(:increment)
- .with(:cache_read_hit_count, 1)
+ .with(:gitlab_cache_misses_total, 1)
subscriber.cache_read(event)
end
@@ -50,33 +41,21 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do
context 'with miss event' do
let(:event) { double(:event, duration: 15.2, payload: { hit: false }) }
- it 'increments the cache_read_miss count' do
+ it 'increments the cache_read_miss total' do
expect(transaction).to receive(:increment)
- .with(:cache_read_miss_count, 1, false)
+ .with(:gitlab_cache_misses_total, 1)
expect(transaction).to receive(:increment)
.with(any_args).at_least(1) # Other calls
subscriber.cache_read(event)
end
- it 'increments the cache_read_miss total' do
- expect(subscriber.send(:metric_cache_misses_total)).to receive(:increment).with({})
-
- subscriber.cache_read(event)
- end
-
context 'when super operation is fetch' do
let(:event) { double(:event, duration: 15.2, payload: { hit: false, super_operation: :fetch }) }
- it 'does not increment cache read miss' do
+ it 'does not increment cache read miss total' do
expect(transaction).not_to receive(:increment)
- .with(:cache_read_miss_count, 1)
-
- subscriber.cache_read(event)
- end
-
- it 'does not increment cache_read_miss total' do
- expect(subscriber.send(:metric_cache_misses_total)).not_to receive(:increment).with({})
+ .with(:gitlab_cache_misses_total, 1)
subscriber.cache_read(event)
end
@@ -129,7 +108,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do
it 'increments the cache_read_hit count' do
expect(transaction).to receive(:increment)
- .with(:cache_read_hit_count, 1)
+ .with(:gitlab_transaction_cache_read_hit_count_total, 1)
subscriber.cache_fetch_hit(event)
end
@@ -146,25 +125,17 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do
end
context 'with a transaction' do
- let(:metric_cache_misses_total) { double('metric_cache_misses_total', increment: nil) }
-
before do
- allow(subscriber).to receive(:metric_cache_misses_total).and_return(metric_cache_misses_total)
allow(subscriber).to receive(:current_transaction)
.and_return(transaction)
end
- it 'increments the cache_fetch_miss count' do
+ it 'increments the cache_fetch_miss count and cache_read_miss total' do
+ expect(transaction).to receive(:increment).with(:gitlab_cache_misses_total, 1)
expect(transaction).to receive(:increment)
- .with(:cache_read_miss_count, 1)
-
- subscriber.cache_generate(event)
- end
+ .with(:gitlab_transaction_cache_read_miss_count_total, 1)
- it 'increments the cache_read_miss total' do
subscriber.cache_generate(event)
-
- expect(metric_cache_misses_total).to have_received(:increment).with({})
end
end
end
@@ -184,22 +155,6 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do
.and_return(transaction)
end
- it 'increments the total and specific cache duration' do
- expect(transaction).to receive(:increment)
- .with(:cache_duration, event.duration, false)
-
- expect(transaction).to receive(:increment)
- .with(:cache_count, 1, false)
-
- expect(transaction).to receive(:increment)
- .with(:cache_delete_duration, event.duration, false)
-
- expect(transaction).to receive(:increment)
- .with(:cache_delete_count, 1, false)
-
- subscriber.observe(:delete, event.duration)
- end
-
it 'observes cache metric' do
expect(subscriber.send(:metric_cache_operation_duration_seconds))
.to receive(:observe)
@@ -209,9 +164,9 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do
end
it 'increments the operations total' do
- expect(subscriber.send(:metric_cache_operations_total))
+ expect(transaction)
.to receive(:increment)
- .with(transaction.labels.merge(operation: :delete))
+ .with(:gitlab_cache_operations_total, 1, { operation: :delete })
subscriber.observe(:delete, event.duration)
end