Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogReader: print number of missing rlogs #32830

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions tools/lib/logreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,23 @@ class ReadMode(enum.StrEnum):
def default_valid_file(fn: LogPath) -> bool:
return fn is not None and file_exists(fn)

def count_missing_rlogs(rlog_paths: LogPaths, valid_file: ValidFileCallable) -> int:
missing_count = 0
for rlog in rlog_paths:
if rlog is None or not valid_file(rlog):
missing_count += 1
return missing_count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cached the result so we don't take 2x longer


def auto_strategy(rlog_paths: LogPaths, qlog_paths: LogPaths, interactive: bool, valid_file: ValidFileCallable) -> LogPaths:
# Count missing rlogs
missing_rlogs = count_missing_rlogs(rlog_paths, valid_file)
# 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):
if missing_rlogs != 0 and all(qlog is not None and valid_file(qlog) for qlog in qlog_paths):
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"Error: {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
Loading