diff --git a/config/mail_room.yml b/config/mail_room.yml index 25bda294a137d49a29bb84f3560bb5b65eeb1a1c..895438dcc4e4789685a769af2e36ff84d92e3a14 100644 --- a/config/mail_room.yml +++ b/config/mail_room.yml @@ -29,6 +29,7 @@ :delivery_method: sidekiq :delivery_options: :redis_url: <%= config[:redis_url].to_json %> + :redis_db: <%= config[:redis_db] %> :namespace: <%= Gitlab::Redis::Queues::SIDEKIQ_NAMESPACE %> :queue: <%= config[:queue] %> :worker: <%= config[:worker] %> diff --git a/lib/gitlab/mail_room.rb b/lib/gitlab/mail_room.rb index 0633efc6b0c48abea7239993f76fa42fafadeb3c..75d27ed8cc1d956ee8100e1bebc980f737bd8966 100644 --- a/lib/gitlab/mail_room.rb +++ b/lib/gitlab/mail_room.rb @@ -71,7 +71,8 @@ def merged_configs(config_key) def redis_config gitlab_redis_queues = Gitlab::Redis::Queues.new(rails_env) - config = { redis_url: gitlab_redis_queues.url } + + config = { redis_url: gitlab_redis_queues.url, redis_db: gitlab_redis_queues.db } if gitlab_redis_queues.sentinels? config[:sentinels] = gitlab_redis_queues.sentinels diff --git a/lib/gitlab/redis/wrapper.rb b/lib/gitlab/redis/wrapper.rb index db1e24a32015c9c683ce198ffb60ffe8b43c7a7a..7b8040381468c6c8adb443949f1c12e6ea78d1bc 100644 --- a/lib/gitlab/redis/wrapper.rb +++ b/lib/gitlab/redis/wrapper.rb @@ -96,6 +96,8 @@ def config_fallback end def instrumentation_class + return unless defined?(::Gitlab::Instrumentation::Redis) + "::Gitlab::Instrumentation::Redis::#{store_name}".constantize end end @@ -112,6 +114,10 @@ def url raw_config_hash[:url] end + def db + redis_store_options[:db] + end + def sentinels raw_config_hash[:sentinels] end diff --git a/spec/lib/gitlab/mail_room/mail_room_spec.rb b/spec/lib/gitlab/mail_room/mail_room_spec.rb index a42da4ad3e0300d545ab9008ab41667029f60764..0bd1a27c65eb181549be02780c89616da21eef81 100644 --- a/spec/lib/gitlab/mail_room/mail_room_spec.rb +++ b/spec/lib/gitlab/mail_room/mail_room_spec.rb @@ -93,7 +93,7 @@ end describe 'setting up redis settings' do - let(:fake_redis_queues) { double(url: "localhost", sentinels: "yes, them", sentinels?: true) } + let(:fake_redis_queues) { double(url: "localhost", db: 99, sentinels: "yes, them", sentinels?: true) } before do allow(Gitlab::Redis::Queues).to receive(:new).and_return(fake_redis_queues) @@ -103,6 +103,7 @@ config = described_class.enabled_configs.first expect(config[:redis_url]).to eq('localhost') + expect(config[:redis_db]).to eq(99) expect(config[:sentinels]).to eq('yes, them') end end diff --git a/spec/lib/gitlab/redis/queues_spec.rb b/spec/lib/gitlab/redis/queues_spec.rb index 2e396cde3bf1c04f2f2ae16ef4c63fc3fb6298a2..a0f73a654e7f51ff0b45d9ca049a0059aadfd8b8 100644 --- a/spec/lib/gitlab/redis/queues_spec.rb +++ b/spec/lib/gitlab/redis/queues_spec.rb @@ -9,10 +9,24 @@ include_examples "redis_shared_examples" describe '#raw_config_hash' do - it 'has a legacy default URL' do - expect(subject).to receive(:fetch_config) { false } + before do + expect(subject).to receive(:fetch_config) { config } + end + + context 'when the config url is blank' do + let(:config) { nil } + + it 'has a legacy default URL' do + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6381' ) + end + end + + context 'when the config url is present' do + let(:config) { { url: 'redis://localhost:1111' } } - expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6381' ) + it 'sets the configured url' do + expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:1111' ) + end end end end diff --git a/spec/support/redis/redis_shared_examples.rb b/spec/support/redis/redis_shared_examples.rb index 09bb33632055b6562f5f134facda37586fbbb5c2..dd916aea3e8805775c9d89f0e69476d06142fce3 100644 --- a/spec/support/redis/redis_shared_examples.rb +++ b/spec/support/redis/redis_shared_examples.rb @@ -255,6 +255,28 @@ end end + describe '#db' do + let(:rails_env) { 'development' } + + subject { described_class.new(rails_env).db } + + context 'with old format' do + let(:config_file_name) { config_old_format_host } + + it 'returns the correct db' do + expect(subject).to eq(redis_database) + end + end + + context 'with new format' do + let(:config_file_name) { config_new_format_host } + + it 'returns the correct db' do + expect(subject).to eq(redis_database) + end + end + end + describe '#sentinels' do subject { described_class.new(rails_env).sentinels }