Commit 9f999994 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'yorick/symbolize-config-keys' into 'master'

Symbolize load balancer configuration keys

See merge request gitlab-org/gitlab!69995
parents 8db928a8 0952ac82
......@@ -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