storage: autoconfigure coordination_url

This makes the storage leverage the indexer URL by default, avoiding
user mistake of not configuring it properly and making it work by
default for multi node environment. Wouhouh!

Change-Id: I8ef35d9e118e2d2a6a87ce6db15a2212df7f355d
This commit is contained in:
Julien Danjou 2016-01-21 17:35:13 +01:00
parent f4e6f52832
commit 0fd52b5820
9 changed files with 31 additions and 29 deletions

View File

@ -226,11 +226,9 @@ function configure_gnocchi {
# Install the configuration files
cp $GNOCCHI_DIR/etc/gnocchi/* $GNOCCHI_CONF_DIR
iniset $GNOCCHI_CONF storage coordination_url "$GNOCCHI_COORDINATOR_URL"
if [ "${GNOCCHI_COORDINATOR_URL:0:7}" == "file://" ]; then
gnocchi_locks_dir=${GNOCCHI_COORDINATOR_URL:7}
[ ! -d $gnocchi_locks_dir ] && sudo mkdir -m 755 -p ${gnocchi_locks_dir}
sudo chown $STACK_USER $gnocchi_locks_dir
if [ -n "$GNOCCHI_COORDINATOR_URL" ]; then
iniset $GNOCCHI_CONF storage coordination_url "$GNOCCHI_COORDINATOR_URL"
fi
# Configure auth token middleware

View File

@ -11,7 +11,6 @@ GNOCCHI_LOG_DIR=/var/log/gnocchi
GNOCCHI_AUTH_CACHE_DIR=${GNOCCHI_AUTH_CACHE_DIR:-/var/cache/gnocchi}
GNOCCHI_WSGI_DIR=${GNOCCHI_WSGI_DIR:-/var/www/gnocchi}
GNOCCHI_DATA_DIR=${GNOCCHI_DATA_DIR:-${DATA_DIR}/gnocchi}
GNOCCHI_COORDINATOR_URL=${GNOCCHI_COORDINATOR_URL:-file://${GNOCCHI_DATA_DIR}/locks}
# Toggle for deploying Gnocchi under HTTPD + mod_wsgi
GNOCCHI_USE_MOD_WSGI=${GNOCCHI_USE_MOD_WSGI:-${ENABLE_HTTPD_MOD_WSGI_SERVICES}}

View File

@ -103,12 +103,13 @@ To ensure consistency across all *gnocchi-api* and *gnocchi-metricd* workers,
these drivers need a distributed locking mechanism. This is provided by the
'coordinator' of the `tooz`_ library.
By default, the configured backend for `tooz`_ is `file`, this allows locking
across workers on the same node.
By default, the configured backend for `tooz`_ is the same as the indexer
(*PostgreSQL* or *MySQL*). This allows locking across workers from different
nodes.
In a multi-nodes deployment, the coordinator needs to be changed via
the storage/coordination_url configuration options to one of the other
`tooz backends`_.
For a more robust multi-nodes deployment, the coordinator may be changed via
the `storage.coordination_url` configuration option to one of the other `tooz
backends`_.
For example to use Redis backend::

View File

@ -1,5 +1,6 @@
# Copyright (c) 2013 Mirantis Inc.
# Copyright (c) 2016 Red Hat, Inc.
# Copyright (c) 2015 eNovance
# Copyright (c) 2013 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -21,6 +22,7 @@ from oslo_config import cfg
from oslo_db import options as db_options
from oslo_log import log
from oslo_policy import opts as policy_opts
from six.moves.urllib import parse as urlparse
from gnocchi import archive_policy
from gnocchi import opts
@ -57,6 +59,19 @@ def prepare_service(args=None, conf=None,
conf(args, project='gnocchi', validate_default_values=True,
default_config_files=default_config_files)
# If no coordination URL is provided, default to using the indexer as
# coordinator
if conf.storage.coordination_url is None:
parsed = urlparse.urlparse(conf.indexer.url)
proto, _, _ = parsed.scheme.partition("+")
parsed = list(parsed)
# Set proto without the + part
parsed[0] = proto
conf.set_default("coordination_url",
urlparse.urlunparse(parsed),
"storage")
log.setup(conf, 'gnocchi')
conf.log_opt_values(LOG, logging.DEBUG)

View File

@ -35,8 +35,7 @@ OPTS = [
'pre-aggregation needs.'),
cfg.StrOpt('coordination_url',
secret=True,
help='Coordination driver URL',
default="file:///var/lib/gnocchi/locks"),
help='Coordination driver URL'),
]

View File

@ -347,17 +347,13 @@ class TestCase(base.BaseTestCase):
self.index = indexer.get_driver(self.conf)
self.index.connect()
self.conf.set_override('coordination_url',
os.getenv("GNOCCHI_COORDINATION_URL", "ipc://"),
'storage')
# NOTE(jd) So, some driver, at least SQLAlchemy, can't create all
# their tables in a single transaction even with the
# checkfirst=True, so what we do here is we force the upgrade code
# path to be sequential to avoid race conditions as the tests run
# in parallel.
self.coord = coordination.get_coordinator(
os.getenv("GNOCCHI_COORDINATION_URL", "ipc://"),
self.conf.storage.coordination_url,
str(uuid.uuid4()).encode('ascii'))
self.coord.start()

View File

@ -95,10 +95,6 @@ class ConfigFixture(fixture.GabbiFixture):
# and thus should override conf settings.
if 'DEVSTACK_GATE_TEMPEST' not in os.environ:
conf.set_override('driver', 'file', 'storage')
conf.set_override(
'coordination_url',
os.getenv("GNOCCHI_COORDINATION_URL", "ipc://"),
'storage')
conf.set_override('policy_file',
os.path.abspath('etc/gnocchi/policy.json'),
group="oslo_policy")

View File

@ -5,7 +5,6 @@ set -x
GNOCCHI_TEST_INDEXER_DRIVER=${GNOCCHI_TEST_INDEXER_DRIVER:-postgresql}
source $(which overtest) $GNOCCHI_TEST_INDEXER_DRIVER
export GNOCCHI_INDEXER_URL=${OVERTEST_URL/#mysql:/mysql+pymysql:}
export GNOCCHI_COORDINATION_URL=${OVERTEST_URL}
# Activate overtest for storage
case $GNOCCHI_TEST_STORAGE_DRIVER in
influxdb)

View File

@ -39,15 +39,15 @@ swift =
python-swiftclient>=2.5.0
msgpack-python
lz4
tooz>=1.22
tooz>=1.30
ceph =
msgpack-python
lz4
tooz>=1.22
tooz>=1.30
file =
msgpack-python
lz4
tooz>=1.22
tooz>=1.30
doc =
oslosphinx>=2.2.0
sphinx
@ -68,8 +68,7 @@ test =
testtools>=0.9.38
WebTest>=2.0.16
doc8
sysv_ipc
tooz>=1.22
tooz>=1.30
keystonemiddleware>=4.0.0
[global]