From fa5cc0ca081ca3cce552e0cb21a1e17273cf3482 Mon Sep 17 00:00:00 2001 From: Yaarit Hatuka Date: Tue, 9 Nov 2021 18:31:11 +0000 Subject: [PATCH] mgr/telemetry: fix waiting for mgr to warm up 1. The implementation of config_notify() in telemetry module sets the flag for event, which is supposed to wake up the 'serve' thread whenever a config option is changed. The problem is that we call config_notify() at the beginning of serve(), before we enter its 'run' loop. This call sets the event which cancels the 10 seconds wait for the mgr to warm up. To fix this, we extract the logic of updating the config options to a separate function (config_update_module_option()), and call it on __init__, instead of calling config_notify() in serve(). 2. We should always wait for the mgr to warm up here (10 seconds). In case of a sporadic event (e.g. a config option change via CLI) the event will be set, and wait will return immediately. We enforce this wait by using time.sleep(10) instead of event.wait(10). Fixes: https://tracker.ceph.com/issues/53204 Signed-off-by: Yaarit Hatuka --- src/pybind/mgr/telemetry/module.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index e54a4621891..665f7ac2341 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -141,6 +141,7 @@ class Module(MgrModule): self.last_report: Dict[str, Any] = dict() self.report_id: Optional[str] = None self.salt: Optional[str] = None + self.config_update_module_option() # for mypy which does not run the code if TYPE_CHECKING: self.url = '' @@ -156,12 +157,15 @@ class Module(MgrModule): self.channel_device = True self.channel_perf = False - def config_notify(self) -> None: + def config_update_module_option(self) -> None: for opt in self.MODULE_OPTIONS: setattr(self, opt['name'], self.get_module_option(opt['name'])) self.log.debug(' %s = %s', opt['name'], getattr(self, opt['name'])) + + def config_notify(self) -> None: + self.config_update_module_option() # wake up serve() thread self.event.set() @@ -1162,11 +1166,10 @@ Device report is generated separately. To see it run 'ceph telemetry show-device def serve(self) -> None: self.load() - self.config_notify() self.run = True self.log.debug('Waiting for mgr to warm up') - self.event.wait(10) + time.sleep(10) while self.run: self.event.clear()