From 510d799d05c738038159e74bf4d13140b6f2edca Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Wed, 21 Sep 2016 10:26:02 +0200 Subject: [PATCH] Use Cotyledon oslo config glue Oslo.service was providing some oslo config configuration. mainly to print all cfg options on startup and a timeout option in case of service doesn't stop gracefully in an timely fashion. It also reload the configuration file on sighup. This change uses the optional cotyledon helper to do that stuffs. Change-Id: I6227fab55b2f4d33611ca3c4bcf01239ff585748 --- etc/gnocchi/gnocchi-config-generator.conf | 1 + gnocchi/cli.py | 19 +++++++++++++++++-- .../notes/reloading-734a639a667c93ee.yaml | 6 ++++++ requirements.txt | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/reloading-734a639a667c93ee.yaml diff --git a/etc/gnocchi/gnocchi-config-generator.conf b/etc/gnocchi/gnocchi-config-generator.conf index fa6ae57b7..a79180681 100644 --- a/etc/gnocchi/gnocchi-config-generator.conf +++ b/etc/gnocchi/gnocchi-config-generator.conf @@ -6,4 +6,5 @@ namespace = oslo.db namespace = oslo.log namespace = oslo.middleware namespace = oslo.policy +namespace = cotyledon namespace = keystonemiddleware.auth_token diff --git a/gnocchi/cli.py b/gnocchi/cli.py index 8ae29ca40..a4e7cdbc8 100644 --- a/gnocchi/cli.py +++ b/gnocchi/cli.py @@ -19,6 +19,7 @@ import time import uuid import cotyledon +from cotyledon import oslo_config_glue from futurist import periodics import msgpack from oslo_config import cfg @@ -286,15 +287,29 @@ class MetricProcessor(MetricProcessBase): class MetricdServiceManager(cotyledon.ServiceManager): def __init__(self, conf): super(MetricdServiceManager, self).__init__() + oslo_config_glue.setup(self, conf) + self.conf = conf self.queue = multiprocessing.Manager().Queue() self.add(MetricScheduler, args=(self.conf, self.queue)) - self.add(MetricProcessor, args=(self.conf, self.queue), - workers=conf.metricd.workers) + self.metric_processor_id = self.add( + MetricProcessor, args=(self.conf, self.queue), + workers=conf.metricd.workers) self.add(MetricReporting, args=(self.conf,)) self.add(MetricJanitor, args=(self.conf,)) + self.register_hooks(on_reload=self.on_reload) + + def on_reload(self): + # NOTE(sileht): We do not implement reload() in Workers so all workers + # will received SIGHUP and exit gracefully, then their will be + # restarted with the new number of workers. This is important because + # we use the number of worker to declare the capability in tooz and + # to select the block of metrics to proceed. + self.reconfigure(self.metric_processor_id, + workers=self.conf.metricd.workers) + def run(self): super(MetricdServiceManager, self).run() self.queue.close() diff --git a/releasenotes/notes/reloading-734a639a667c93ee.yaml b/releasenotes/notes/reloading-734a639a667c93ee.yaml new file mode 100644 index 000000000..0cf2eb730 --- /dev/null +++ b/releasenotes/notes/reloading-734a639a667c93ee.yaml @@ -0,0 +1,6 @@ +--- +features: + - gnocchi-metricd now uses the cotyledon/oslo.config helper to handle + configuration file reloading. You can dynamically change the number + of workers by changing the configuration file and sending SIGHUP to the + metricd master process. diff --git a/requirements.txt b/requirements.txt index 818e3b45b..5c83463ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ pecan>=0.9 pytimeparse>=1.1.5 futures jsonpatch -cotyledon>=1.2.2 +cotyledon>=1.5.0 requests six stevedore