Commit 0952ac82 authored by Yorick Peterse's avatar Yorick Peterse

Symbolize load balancer configuration keys

This ensures that if database.yml uses strings as the configuration
keys, we still honor the custom configuration settings; instead of using
default ones.

Changelog: fixed
parent 5d90d345
......@@ -11,7 +11,7 @@ module Gitlab
# Creates a configuration object for the given ActiveRecord model.
def self.for_model(model)
cfg = model.connection_db_config.configuration_hash
cfg = model.connection_db_config.configuration_hash.deep_symbolize_keys
lb_cfg = cfg[:load_balancing] || {}
config = new(model)
......@@ -35,7 +35,7 @@ module Gitlab
config.hosts = hosts
end
discover = (lb_cfg[:discover] || {}).symbolize_keys
discover = lb_cfg[:discover] || {}
# We iterate over the known/default keys so we don't end up with
# random keys in our configuration hash.
......
......@@ -69,6 +69,42 @@ RSpec.describe Gitlab::Database::LoadBalancing::Configuration do
expect(config.pool_size).to eq(4)
end
end
context 'when the load balancing configuration uses strings as the keys' do
let(:configuration_hash) do
{
pool: 4,
load_balancing: {
'max_replication_difference' => 1,
'max_replication_lag_time' => 2,
'replica_check_interval' => 3,
'hosts' => %w[foo bar],
'discover' => {
'record' => 'foo.example.com'
}
}
}
end
it 'uses the custom configuration settings' do
config = described_class.for_model(model)
expect(config.hosts).to eq(%w[foo bar])
expect(config.max_replication_difference).to eq(1)
expect(config.max_replication_lag_time).to eq(2.0)
expect(config.replica_check_interval).to eq(3.0)
expect(config.service_discovery).to eq(
nameserver: 'localhost',
port: 8600,
record: 'foo.example.com',
record_type: 'A',
interval: 60,
disconnect_timeout: 120,
use_tcp: false
)
expect(config.pool_size).to eq(4)
end
end
end
describe '#load_balancing_enabled?' do
......
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