Skip to content

Commit

Permalink
Improve showing why a line was shown in deployment log
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed Nov 11, 2024
1 parent 1109021 commit 532e643
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/batou/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions src/batou/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 532e643

Please sign in to comment.