Add redis db to the mail_room option hash

- change code to send the db option
- change mail_room configuration file
This commit is contained in:
Jarka Košanová 2021-10-01 17:13:09 +02:00
parent e92fdefdb4
commit 1c534adfb1
6 changed files with 50 additions and 5 deletions

View file

@ -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] %>

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:6381' )
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' } }
it 'sets the configured url' do
expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:1111' )
end
end
end
end

View file

@ -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 }