]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/prometheus: use threading.Event instead of sleep
authorBoris Ranto <branto@redhat.com>
Wed, 25 Nov 2020 19:49:48 +0000 (20:49 +0100)
committerBoris Ranto <branto@redhat.com>
Mon, 30 Nov 2020 10:37:46 +0000 (11:37 +0100)
This allows us to avoid waiting for the sleep to finish when waiting for
the thread to finish.

Signed-off-by: Boris Ranto <branto@redhat.com>
(cherry picked from commit dd5886c3c006e388283df50cc87addeffb3b2b52)

src/pybind/mgr/prometheus/module.py

index 02157f215e3bb798523e094af1d774f0ecff17f5..cdce0abb6b7a871d074c617b95ace6286f952a53 100644 (file)
@@ -182,6 +182,7 @@ class MetricCollectionThread(threading.Thread):
         # type: (Module) -> None
         self.mod = module
         self.active = True
+        self.event = threading.Event()
         super(MetricCollectionThread, self).__init__(target=self.collect)
 
     def collect(self):
@@ -196,7 +197,7 @@ class MetricCollectionThread(threading.Thread):
                 except Exception as e:
                     # Log any issues encountered during the data collection and continue
                     self.mod.log.exception("failed to collect metrics:")
-                    time.sleep(self.mod.scrape_interval)
+                    self.event.wait(self.mod.scrape_interval)
                     continue
 
                 duration = time.time() - start_time
@@ -219,13 +220,14 @@ class MetricCollectionThread(threading.Thread):
                     self.mod.collect_cache = data
                     self.mod.collect_time = duration
 
-                time.sleep(sleep_time)
+                self.event.wait(sleep_time)
             else:
                 self.mod.log.error('No MON connection')
-                time.sleep(self.mod.scrape_interval)
+                self.event.wait(self.mod.scrape_interval)
 
     def stop(self):
         self.active = False
+        self.event.set()
 
 class Module(MgrModule):
     COMMANDS = [