diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 18:19:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-20 18:19:03 +0300 |
commit | 14bd84b61276ef29b97d23642d698de769bacfd2 (patch) | |
tree | f9eba90140c1bd874211dea17750a0d422c04080 /spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb | |
parent | 891c388697b2db0d8ee0c8358a9bdbf6dc56d581 (diff) |
Add latest changes from gitlab-org/gitlab@15-10-stable-eev15.10.0-rc42
Diffstat (limited to 'spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb')
-rw-r--r-- | spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb index 59bfe2042fa..1731da9b752 100644 --- a/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb @@ -6,13 +6,14 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do let(:env) { {} } let(:transaction) { Gitlab::Metrics::WebTransaction.new(env) } let(:subscriber) { described_class.new } - - let(:event) { double(:event, duration: 15.2, payload: { key: %w[a b c] }) } + let(:store) { 'Gitlab::CustomStore' } + let(:store_label) { 'CustomStore' } + let(:event) { double(:event, duration: 15.2, payload: { key: %w[a b c], store: store }) } describe '#cache_read' do it 'increments the cache_read duration' do expect(subscriber).to receive(:observe) - .with(:read, event.duration) + .with(:read, event) subscriber.cache_read(event) end @@ -27,7 +28,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do let(:event) { double(:event, duration: 15.2, payload: { hit: true }) } context 'when super operation is fetch' do - let(:event) { double(:event, duration: 15.2, payload: { hit: true, super_operation: :fetch }) } + let(:event) { double(:event, duration: 15.2, payload: { hit: true, super_operation: :fetch, store: store }) } it 'does not increment cache read miss total' do expect(transaction).not_to receive(:increment) @@ -39,7 +40,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do end context 'with miss event' do - let(:event) { double(:event, duration: 15.2, payload: { hit: false }) } + let(:event) { double(:event, duration: 15.2, payload: { hit: false, store: store }) } it 'increments the cache_read_miss total' do expect(transaction).to receive(:increment) @@ -51,7 +52,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do end context 'when super operation is fetch' do - let(:event) { double(:event, duration: 15.2, payload: { hit: false, super_operation: :fetch }) } + let(:event) { double(:event, duration: 15.2, payload: { hit: false, super_operation: :fetch, store: store }) } it 'does not increment cache read miss total' do expect(transaction).not_to receive(:increment) @@ -92,7 +93,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do it 'observes read_multi duration' do expect(subscriber).to receive(:observe) - .with(:read_multi, event.duration) + .with(:read_multi, event) subject end @@ -101,7 +102,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do describe '#cache_write' do it 'observes write duration' do expect(subscriber).to receive(:observe) - .with(:write, event.duration) + .with(:write, event) subscriber.cache_write(event) end @@ -110,7 +111,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do describe '#cache_delete' do it 'observes delete duration' do expect(subscriber).to receive(:observe) - .with(:delete, event.duration) + .with(:delete, event) subscriber.cache_delete(event) end @@ -119,7 +120,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do describe '#cache_exist?' do it 'observes the exists duration' do expect(subscriber).to receive(:observe) - .with(:exists, event.duration) + .with(:exists, event) subscriber.cache_exist?(event) end @@ -179,7 +180,7 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do it 'returns' do expect(transaction).not_to receive(:increment) - subscriber.observe(:foo, 15.2) + subscriber.observe(:foo, event) end end @@ -192,17 +193,17 @@ RSpec.describe Gitlab::Metrics::Subscribers::RailsCache do it 'observes cache metric' do expect(subscriber.send(:metric_cache_operation_duration_seconds)) .to receive(:observe) - .with({ operation: :delete }, event.duration / 1000.0) + .with({ operation: :delete, store: store_label }, event.duration / 1000.0) - subscriber.observe(:delete, event.duration) + subscriber.observe(:delete, event) end it 'increments the operations total' do expect(transaction) .to receive(:increment) - .with(:gitlab_cache_operations_total, 1, { operation: :delete }) + .with(:gitlab_cache_operations_total, 1, { operation: :delete, store: store_label }) - subscriber.observe(:delete, event.duration) + subscriber.observe(:delete, event) end end end |