Update redis-sentinel support to handle multiple sentinels

If there are multiple sentinels we would like to configure the
coordination backend to use all of them. This change makes that
possible by constructing a coordination url that lists all the
sentinel hosts: one in the netloc portion of the url and the rest
as sentinel_fallback parameters. If no sentinel hosts are provided,
none are used. If only one is provided, only the first host is set,
no fallbacks.

This change also ensures that the configured sentinel port is respected
in the generated sentinel configurations and in the ceilometer
coordination url and that redis slaves bind to an appropriate host.

This URL format will be present in the forthcoming tooz 0.11.

Change-Id: I49edd2143b800ee1c3020fc04ed5ad817ddffe6c
This commit is contained in:
Chris Dent
2015-01-12 16:12:01 +00:00
parent ed13378732
commit 5a19134459
4 changed files with 30 additions and 6 deletions

View File

@@ -249,6 +249,21 @@ def create_manifest(config, messages):
manifestdata = getManifestTemplate(get_mq(config, "ceilometer"))
manifestdata += getManifestTemplate("ceilometer")
if config['CONFIG_CEILOMETER_COORDINATION_BACKEND'] == 'redis':
# Determine if we need to configure multiple sentinel hosts as
# fallbacks for use in coordination url.
sentinel_hosts = split_hosts(config['CONFIG_REDIS_SENTINEL_HOSTS'])
sentinel_port = config['CONFIG_REDIS_SENTINEL_PORT']
sentinel_contact = config['CONFIG_REDIS_SENTINEL_CONTACT_HOST']
if len(sentinel_hosts) > 1:
sentinel_fallbacks = '&'.join(['sentinel_fallback=%s:%s' %
(host, sentinel_port)
for host in sentinel_hosts
if host != sentinel_contact])
else:
sentinel_fallbacks = ''
config['CONFIG_REDIS_SENTINEL_FALLBACKS'] = sentinel_fallbacks
fw_details = dict()
key = "ceilometer_api"
fw_details.setdefault(key, {})

View File

@@ -6,10 +6,16 @@ if $config_ceilometer_coordination_backend == 'redis' {
$redis_host = hiera('CONFIG_REDIS_MASTER_HOST')
$redis_port = hiera('CONFIG_REDIS_PORT')
$sentinel_host = hiera('CONFIG_REDIS_SENTINEL_CONTACT_HOST')
$sentinel_fallbacks = hiera('CONFIG_REDIS_SENTINEL_FALLBACKS')
if $sentinel_host != '' {
$master_name = hiera('CONFIG_REDIS_MASTER_NAME')
$sentinel_port = hiera('CONFIG_REDIS_SENTINEL_PORT')
$coordination_url = "redis://${sentinel_host}:${sentinel_port}?sentinel=${master_name}"
$base_coordination_url = "redis://${sentinel_host}:${sentinel_port}?sentinel=${master_name}"
if $sentinel_fallbacks != '' {
$coordination_url = "${base_coordination_url}&${sentinel_fallbacks}"
} else {
$coordination_url = $base_coordination_url
}
} else {
$coordination_url = "redis://${redis_host}:${redis_port}"
}

View File

@@ -2,10 +2,13 @@ $redis_master_host = hiera('CONFIG_REDIS_MASTER_HOST')
$redis_master_port = hiera('CONFIG_REDIS_PORT')
$redis_master_name = hiera('CONFIG_REDIS_MASTER_NAME')
$redis_sentinel_quorum = hiera('CONFIG_REDIS_SENTINEL_QUORUM')
$redis_sentinel_port = hiera('CONFIG_REDIS_SENTINEL_PORT')
class { 'redis::sentinel':
master_name => "${redis_master_name}",
redis_host => $redis_master_host,
redis_port => $redis_master_port,
quorum => $redis_sentinel_quorum,
master_name => "${redis_master_name}",
redis_host => $redis_master_host,
redis_port => $redis_master_port,
quorum => $redis_sentinel_quorum,
sentinel_port => $redis_sentinel_port,
log_file => '/var/log/redis/sentinel.log',
}

View File

@@ -3,7 +3,7 @@ $redis_port = hiera('CONFIG_REDIS_PORT')
$redis_master_host = hiera('CONFIG_REDIS_MASTER_HOST')
class { 'redis':
bind => $redis_host,
bind => '0.0.0.0',
port => $redis_port,
appendonly => true,
daemonize => false,