Skip to content

Add cloudwatch_logs.py utility file to monitor lambdas #6740

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

seemethere
Copy link
Member

@seemethere seemethere commented Jun 11, 2025

This adds a cloudwatch_logs.py utility file in order to make it easier to debug lambdas if / when things go awry.

Example usage:

python3 tools/self-hosted-runner-utils/cloudwatch_logs.py gh-ci-scale-up --tail
python3 tools/self-hosted-runner-utils/cloudwatch_logs.py gh-ci-scale-down --tail

- Reorganized import statements for better clarity.
- Standardized string formatting and spacing throughout the code.
- Enhanced function definitions and comments for better understanding.
- Improved error handling and logging for AWS interactions.
- Updated README.md to remove unnecessary newline.
Copy link

vercel bot commented Jun 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
torchci ⬜️ Ignored (Inspect) Visit Preview Jun 11, 2025 8:51pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 11, 2025
@seemethere seemethere requested a review from a team June 11, 2025 02:23
from typing import Any, Dict, List, Optional

import boto3 # type: ignore[import-untyped]
import dateparser # type: ignore[import-untyped]
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of custom dependency to be frank..

Comment on lines 299 to 312
if options.output_file:
# Write to output file
with open(options.output_file, "w", encoding="utf-8") as f:
f.writelines(header)
for log_content in all_logs:
f.write(log_content)
print(f"Downloaded logs to: {options.output_file}")
else:
# Write to stdout
import sys

sys.stdout.writelines(header)
for log_content in all_logs:
sys.stdout.write(log_content)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not combine this logic to something like

def write_logs(f):
  f.writelines(header)
  for log_content in all_logs:
    f.write(log_content)

if options.output_file:
   with open(options.output_file, "w", encoding="utf-8") as f:
      write_logs(f)
else:
   write_logs(sys.stdout)

except NoCredentialsError:
print(
"Error: AWS credentials not found. Please configure your AWS credentials."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

sys.exit(-1) seems to be in order here

Comment on lines 318 to 323
except ValueError as e:
print(f"Error: {e}")
except ClientError as e:
print(f"AWS Error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, what's the value of catching those errors? If script fails, it should fail and return non-zero status code, but right now it's not the case

Signed-off-by: Eli Uriegas <[email protected]>
@@ -0,0 +1,326 @@
import argparse

Check warning

Code scanning / lintrunner

PYFMT/format Warning

Run lintrunner -a to apply this patch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants