Commit f410d5e9 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'mailroom-redis-db' into 'master'

Add redis db to the mail_room option hash

See merge request gitlab-org/gitlab!71575
parents 86885670 1c534adf
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
:delivery_method: sidekiq :delivery_method: sidekiq
:delivery_options: :delivery_options:
:redis_url: <%= config[:redis_url].to_json %> :redis_url: <%= config[:redis_url].to_json %>
:redis_db: <%= config[:redis_db] %>
:namespace: <%= Gitlab::Redis::Queues::SIDEKIQ_NAMESPACE %> :namespace: <%= Gitlab::Redis::Queues::SIDEKIQ_NAMESPACE %>
:queue: <%= config[:queue] %> :queue: <%= config[:queue] %>
:worker: <%= config[:worker] %> :worker: <%= config[:worker] %>
......
...@@ -71,7 +71,8 @@ module Gitlab ...@@ -71,7 +71,8 @@ module Gitlab
def redis_config def redis_config
gitlab_redis_queues = Gitlab::Redis::Queues.new(rails_env) 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? if gitlab_redis_queues.sentinels?
config[:sentinels] = gitlab_redis_queues.sentinels config[:sentinels] = gitlab_redis_queues.sentinels
......
...@@ -96,6 +96,8 @@ module Gitlab ...@@ -96,6 +96,8 @@ module Gitlab
end end
def instrumentation_class def instrumentation_class
return unless defined?(::Gitlab::Instrumentation::Redis)
"::Gitlab::Instrumentation::Redis::#{store_name}".constantize "::Gitlab::Instrumentation::Redis::#{store_name}".constantize
end end
end end
...@@ -112,6 +114,10 @@ module Gitlab ...@@ -112,6 +114,10 @@ module Gitlab
raw_config_hash[:url] raw_config_hash[:url]
end end
def db
redis_store_options[:db]
end
def sentinels def sentinels
raw_config_hash[:sentinels] raw_config_hash[:sentinels]
end end
......
...@@ -93,7 +93,7 @@ RSpec.describe Gitlab::MailRoom do ...@@ -93,7 +93,7 @@ RSpec.describe Gitlab::MailRoom do
end end
describe 'setting up redis settings' do 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 before do
allow(Gitlab::Redis::Queues).to receive(:new).and_return(fake_redis_queues) allow(Gitlab::Redis::Queues).to receive(:new).and_return(fake_redis_queues)
...@@ -103,6 +103,7 @@ RSpec.describe Gitlab::MailRoom do ...@@ -103,6 +103,7 @@ RSpec.describe Gitlab::MailRoom do
config = described_class.enabled_configs.first config = described_class.enabled_configs.first
expect(config[:redis_url]).to eq('localhost') expect(config[:redis_url]).to eq('localhost')
expect(config[:redis_db]).to eq(99)
expect(config[:sentinels]).to eq('yes, them') expect(config[:sentinels]).to eq('yes, them')
end end
end end
......
...@@ -9,10 +9,24 @@ RSpec.describe Gitlab::Redis::Queues do ...@@ -9,10 +9,24 @@ RSpec.describe Gitlab::Redis::Queues do
include_examples "redis_shared_examples" include_examples "redis_shared_examples"
describe '#raw_config_hash' do describe '#raw_config_hash' do
it 'has a legacy default URL' do before do
expect(subject).to receive(:fetch_config) { false } 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 end
end end
...@@ -255,6 +255,28 @@ RSpec.shared_examples "redis_shared_examples" do ...@@ -255,6 +255,28 @@ RSpec.shared_examples "redis_shared_examples" do
end end
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 describe '#sentinels' do
subject { described_class.new(rails_env).sentinels } 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