From 0fd52b5820d8f32892dd72f62adde96ab2946072 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 21 Jan 2016 17:35:13 +0100 Subject: [PATCH] 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 --- devstack/plugin.sh | 8 +++----- devstack/settings | 1 - doc/source/configuration.rst | 11 ++++++----- gnocchi/service.py | 17 ++++++++++++++++- gnocchi/storage/_carbonara.py | 3 +-- gnocchi/tests/base.py | 6 +----- gnocchi/tests/gabbi/fixtures.py | 4 ---- setup-test-env.sh | 1 - setup.cfg | 9 ++++----- 9 files changed, 31 insertions(+), 29 deletions(-) diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 8078473c..7353dafd 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -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 diff --git a/devstack/settings b/devstack/settings index e28c40e6..7a5e72ab 100644 --- a/devstack/settings +++ b/devstack/settings @@ -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}} diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 694d1a6f..b2d25497 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -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:: diff --git a/gnocchi/service.py b/gnocchi/service.py index bd9ea8b3..c33d2378 100644 --- a/gnocchi/service.py +++ b/gnocchi/service.py @@ -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) diff --git a/gnocchi/storage/_carbonara.py b/gnocchi/storage/_carbonara.py index b51c0c9e..6c74f40b 100644 --- a/gnocchi/storage/_carbonara.py +++ b/gnocchi/storage/_carbonara.py @@ -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'), ] diff --git a/gnocchi/tests/base.py b/gnocchi/tests/base.py index 4b258b9f..bdff2f80 100644 --- a/gnocchi/tests/base.py +++ b/gnocchi/tests/base.py @@ -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() diff --git a/gnocchi/tests/gabbi/fixtures.py b/gnocchi/tests/gabbi/fixtures.py index 2ec251f3..03e926ce 100644 --- a/gnocchi/tests/gabbi/fixtures.py +++ b/gnocchi/tests/gabbi/fixtures.py @@ -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") diff --git a/setup-test-env.sh b/setup-test-env.sh index d6c52624..d4fe1cd0 100755 --- a/setup-test-env.sh +++ b/setup-test-env.sh @@ -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) diff --git a/setup.cfg b/setup.cfg index 758df395..5bd6cc1c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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]