Commit 1c534adf authored by Jarka Košanová's avatar Jarka Košanová

Add redis db to the mail_room option hash

- change code to send the db option
- change mail_room configuration file
parent e92fdefd
......@@ -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] %>
......
......@@ -71,7 +71,8 @@ module Gitlab
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
......
......@@ -96,6 +96,8 @@ module Gitlab
end
def instrumentation_class
return unless defined?(::Gitlab::Instrumentation::Redis)
"::Gitlab::Instrumentation::Redis::#{store_name}".constantize
end
end
......@@ -112,6 +114,10 @@ module Gitlab
raw_config_hash[:url]
end
def db
redis_store_options[:db]
end
def sentinels
raw_config_hash[:sentinels]
end
......
......@@ -93,7 +93,7 @@ RSpec.describe Gitlab::MailRoom do
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 @@ RSpec.describe Gitlab::MailRoom do
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
......
......@@ -9,10 +9,24 @@ RSpec.describe Gitlab::Redis::Queues do
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' } }
it 'sets the configured url' do
expect(subject.send(:raw_config_hash)).to eq(url: 'redis://localhost:1111' )
end
end
end
end
......@@ -255,6 +255,28 @@ RSpec.shared_examples "redis_shared_examples" do
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 }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment