From 532e64352d03f017fc773026acb6bb63a03b8765 Mon Sep 17 00:00:00 2001 From: Eli Kogan-Wang Date: Mon, 11 Nov 2024 11:14:37 +0100 Subject: [PATCH] Improve showing why a line was shown in deployment log --- src/batou/component.py | 11 +++++++++-- src/batou/utils.py | 10 ++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/batou/component.py b/src/batou/component.py index 18358d42..7ece331b 100644 --- a/src/batou/component.py +++ b/src/batou/component.py @@ -372,7 +372,9 @@ def deploy(self, predict_only=False): if sub_component.changed: self.changed = True - output.buffer("annotate", self.host.name + " > " + self._breadcrumbs) + output.buffer( + "annotate", f"{self.host.name} > {self._breadcrumbs}: update" + ) if not os.path.exists(self.workdir): os.makedirs(self.workdir) @@ -399,9 +401,14 @@ def deploy(self, predict_only=False): output.clear_buffer() - if self.timer.above_threshold(verify=1, update=1, total=10): + took_too_long, steps_too_long = self.timer.above_threshold( + verify=1, update=1, total=10 + ) + if took_too_long: output.annotate( f"{self.host.name} > {self._breadcrumbs} [{self.timer.humanize('total', 'verify', 'update', 'sub')}]" + + ", ".join(steps_too_long) + + " took too long", ) def verify(self): diff --git a/src/batou/utils.py b/src/batou/utils.py index bf1e6299..5dff5d80 100644 --- a/src/batou/utils.py +++ b/src/batou/utils.py @@ -545,17 +545,19 @@ def step(self, note): def above_threshold(self, **thresholds): """ - Return true if any of the steps took longer than the given threshold. + Return tuple with true if any of the steps took longer than the given threshold. "total" is a special step that is the sum of all other steps. + Second element is a list of the steps that took longer than the threshold. """ total = sum(self.durations.values()) + took_longer = [] for note, duration in self.durations.items(): if note in thresholds and duration > thresholds[note]: - return True + took_longer.append(note) if "total" in thresholds and total > thresholds["total"]: - return True - return False + took_longer.append("total") + return bool(took_longer), took_longer def humanize(self, *steps): """