From 504dd4543dd7fd6c466817faa82cda42b6b55542 Mon Sep 17 00:00:00 2001 From: StefanLekanic-SYRMIA <156184842+StefanLekanic-SYRMIA@users.noreply.github.com> Date: Thu, 27 Jun 2024 06:15:13 +0100 Subject: [PATCH] LogReader: print number of missing rlogs (#32830) * count rlogs * minimization changes * cache to avoid duplicate checks * no real point in checking qlogs to just show the warning --------- Co-authored-by: Shane Smiskol --- tools/lib/logreader.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/lib/logreader.py b/tools/lib/logreader.py index 98c10941bb96a1..f6932c029aeb43 100755 --- a/tools/lib/logreader.py +++ b/tools/lib/logreader.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 import bz2 -from functools import partial +from functools import cache, partial import multiprocessing import capnp import enum @@ -87,18 +87,21 @@ class ReadMode(enum.StrEnum): InternalUnavailableException = Exception("Internal source not available") + +@cache def default_valid_file(fn: LogPath) -> bool: return fn is not None and file_exists(fn) def auto_strategy(rlog_paths: LogPaths, qlog_paths: LogPaths, interactive: bool, valid_file: ValidFileCallable) -> LogPaths: # auto select logs based on availability - if any(rlog is None or not valid_file(rlog) for rlog in rlog_paths) and all(qlog is not None and valid_file(qlog) for qlog in qlog_paths): + missing_rlogs = [rlog is None or not valid_file(rlog) for rlog in rlog_paths].count(True) + if missing_rlogs != 0: if interactive: - if input("Some rlogs were not found, would you like to fallback to qlogs for those segments? (y/n) ").lower() != "y": + if input(f"{missing_rlogs} rlogs were not found, would you like to fallback to qlogs for those segments? (y/n) ").lower() != "y": return rlog_paths else: - cloudlog.warning("Some rlogs were not found, falling back to qlogs for those segments...") + cloudlog.warning(f"{missing_rlogs} rlogs were not found, falling back to qlogs for those segments...") return [rlog if valid_file(rlog) else (qlog if valid_file(qlog) else None) for (rlog, qlog) in zip(rlog_paths, qlog_paths, strict=True)]