diff options
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r-- | spec/lib/gitlab/metrics/boot_time_tracker_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/subscribers/rack_attack_spec.rb | 27 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb | 31 |
3 files changed, 18 insertions, 44 deletions
diff --git a/spec/lib/gitlab/metrics/boot_time_tracker_spec.rb b/spec/lib/gitlab/metrics/boot_time_tracker_spec.rb index 8a17fa8dd2e..3175c0a6b32 100644 --- a/spec/lib/gitlab/metrics/boot_time_tracker_spec.rb +++ b/spec/lib/gitlab/metrics/boot_time_tracker_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'fast_spec_helper' +require 'spec_helper' -RSpec.describe Gitlab::Metrics::BootTimeTracker do +RSpec.describe Gitlab::Metrics::BootTimeTracker, feature_category: :metrics do let(:logger) { double('logger') } let(:gauge) { double('gauge') } diff --git a/spec/lib/gitlab/metrics/subscribers/rack_attack_spec.rb b/spec/lib/gitlab/metrics/subscribers/rack_attack_spec.rb index 9f939d0d7d6..13965bf1244 100644 --- a/spec/lib/gitlab/metrics/subscribers/rack_attack_spec.rb +++ b/spec/lib/gitlab/metrics/subscribers/rack_attack_spec.rb @@ -32,33 +32,6 @@ RSpec.describe Gitlab::Metrics::Subscribers::RackAttack, :request_store do end end - describe '#redis' do - it 'accumulates per-request RackAttack cache usage' do - freeze_time do - subscriber.redis( - ActiveSupport::Notifications::Event.new( - 'redis.rack_attack', Time.current, Time.current + 1.second, '1', { operation: 'fetch' } - ) - ) - subscriber.redis( - ActiveSupport::Notifications::Event.new( - 'redis.rack_attack', Time.current, Time.current + 2.seconds, '1', { operation: 'write' } - ) - ) - subscriber.redis( - ActiveSupport::Notifications::Event.new( - 'redis.rack_attack', Time.current, Time.current + 3.seconds, '1', { operation: 'read' } - ) - ) - end - - expect(Gitlab::SafeRequestStore[:rack_attack_instrumentation]).to eql( - rack_attack_redis_count: 3, - rack_attack_redis_duration_s: 6.0 - ) - end - end - shared_examples 'log into auth logger' do context 'when matched throttle does not require user information' do let(:event) do 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 |