From: Kamoltat (Junior) Sirivadhna Date: Mon, 8 Jul 2019 20:48:43 +0000 (-0400) Subject: mgr/progress: added the time an event has been in progress X-Git-Tag: v15.1.0~2193^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9d210d744a01d03e99bc664573e6bdae2b149647;p=ceph.git mgr/progress: added the time an event has been in progress moved the calculations to _refresh() in Event class so that other future Events can use this functionality. Signed-off-by: Kamoltat (Junior) Sirivadhna --- diff --git a/src/pybind/mgr/progress/module.py b/src/pybind/mgr/progress/module.py index 07bffec2d321..5c3a4648dc28 100644 --- a/src/pybind/mgr/progress/module.py +++ b/src/pybind/mgr/progress/module.py @@ -20,9 +20,9 @@ class Event(object): """ def __init__(self, message, refs): - self._message = message self._refs = refs - + self._duration_str = "(since 0h 0m 0s)" + self._message = message self.started_at = datetime.datetime.utcnow() self.id = None @@ -31,6 +31,7 @@ class Event(object): global _module _module.log.debug('refreshing mgr for %s (%s) at %f' % (self.id, self._message, self.progress)) + self.update_duration_event() _module.update_progress_event(self.id, self._message, self.progress) @property @@ -44,9 +45,13 @@ class Event(object): @property def progress(self): raise NotImplementedError() + + @property + def duration_str(self): + return self._duration_str def summary(self): - return "{0} {1}".format(self.progress, self.message) + return "{0} {1} {2}".format(self.progress, self.message, self.duration_str) def _progress_str(self, width): inner_width = width - 2 @@ -66,16 +71,26 @@ class Event(object): [===============..............] """ - return "{0}\n {1}".format( - self._message, self._progress_str(30)) + return "{0} {1}\n {2}".format( + self._message, self._duration_str, self._progress_str(30)) def to_json(self): return { "id": self.id, "message": self.message, + "duration": self.duration_str, "refs": self._refs } + def update_duration_event(self): + # Update duration of event in seconds/minutes/hours + + duration = (datetime.datetime.utcnow() - self.started_at) + duration_sec = duration.seconds + duration_min = duration_sec //60 + duration_hr = duration_min // 60 + + self._duration_str = "(since {0}h {1}m {2}s)".format(duration_hr, duration_min, duration_sec) class GhostEvent(Event): """ @@ -216,26 +231,14 @@ class PgRecoveryEvent(Event): ratio = 0.5 complete_accumulate += ratio - # Update duration of event in seconds/minutes/hours - duration = (datetime.datetime.utcnow() - self.started_at) - duration_sec = duration.seconds - duration_min = duration_sec //60 - duration_hr = duration_min // 60 - self._pgs = list(set(self._pgs) ^ complete) completed_pgs = self._original_pg_count - len(self._pgs) self._progress = (completed_pgs + complete_accumulate)\ / self._original_pg_count - # Because the spacing of 'in' and 'out' characters are different - if self._message[31] == "i": - self._message = self._message[:34] + "(since {0}h {1}m {2}s)".format(duration_hr, duration_min, duration_sec) - else: - self._message = self._message[:34] + " (since {0}h {1}m {2}s)".format(duration_hr, duration_min, duration_sec) - self._refresh() - - log.info("Updated progress to {0} ({1})".format( - self._progress, self._message + self._refresh() + log.info("Updated progress to {0} ({1} {2})".format( + self._progress, self._message, self._duration_str )) @property