Skip to content

Commit

Permalink
LogReader: print number of missing rlogs (#32830)
Browse files Browse the repository at this point in the history
* 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 <shane@smiskol.com>
  • Loading branch information
StefanLekanic-SYRMIA and sshane authored Jun 27, 2024
1 parent b7695c0 commit 504dd45
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tools/lib/logreader.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 504dd45

Please sign in to comment.