summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb')
-rw-r--r--spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb71
1 files changed, 70 insertions, 1 deletions
diff --git a/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb b/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb
index 25506d63091..5b0ad63ee72 100644
--- a/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb
+++ b/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
require 'rspec-parameterized'
-describe Gitlab::Instrumentation::RedisInterceptor, :clean_gitlab_redis_shared_state, :request_store do
+RSpec.describe Gitlab::Instrumentation::RedisInterceptor, :clean_gitlab_redis_shared_state, :request_store do
using RSpec::Parameterized::TableSyntax
describe 'read and write' do
@@ -42,4 +42,73 @@ describe Gitlab::Instrumentation::RedisInterceptor, :clean_gitlab_redis_shared_s
end
end
end
+
+ describe 'counting' do
+ let(:instrumentation_class) { Gitlab::Redis::SharedState.instrumentation_class }
+
+ it 'counts successful requests' do
+ expect(instrumentation_class).to receive(:instance_count_request).and_call_original
+
+ Gitlab::Redis::SharedState.with { |redis| redis.call(:get, 'foobar') }
+ end
+
+ it 'counts exceptions' do
+ expect(instrumentation_class).to receive(:instance_count_exception)
+ .with(instance_of(Redis::CommandError)).and_call_original
+ expect(instrumentation_class).to receive(:instance_count_request).and_call_original
+
+ expect do
+ Gitlab::Redis::SharedState.with do |redis|
+ redis.call(:auth, 'foo', 'bar')
+ end
+ end.to raise_exception(Redis::CommandError)
+ end
+ end
+
+ describe 'latency' do
+ let(:instrumentation_class) { Gitlab::Redis::SharedState.instrumentation_class }
+
+ describe 'commands in the apdex' do
+ where(:command) do
+ [
+ [[:get, 'foobar']],
+ [%w[GET foobar]]
+ ]
+ end
+
+ with_them do
+ it 'measures requests we want in the apdex' do
+ expect(instrumentation_class).to receive(:instance_observe_duration).with(a_value > 0)
+ .and_call_original
+
+ Gitlab::Redis::SharedState.with { |redis| redis.call(*command) }
+ end
+ end
+ end
+
+ describe 'commands not in the apdex' do
+ where(:command) do
+ [
+ [%w[brpop foobar 0.01]],
+ [%w[blpop foobar 0.01]],
+ [%w[brpoplpush foobar bazqux 0.01]],
+ [%w[bzpopmin foobar 0.01]],
+ [%w[bzpopmax foobar 0.01]],
+ [%w[xread block 1 streams mystream 0-0]],
+ [%w[xreadgroup group mygroup myconsumer block 1 streams foobar 0-0]]
+ ]
+ end
+
+ with_them do
+ it 'skips requests we do not want in the apdex' do
+ expect(instrumentation_class).not_to receive(:instance_observe_duration)
+
+ begin
+ Gitlab::Redis::SharedState.with { |redis| redis.call(*command) }
+ rescue Gitlab::Instrumentation::RedisClusterValidator::CrossSlotError, ::Redis::CommandError
+ end
+ end
+ end
+ end
+ end
end