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

feat(clp-package): Add support for extracting JSON streams from archives stored on S3. #678

Merged
merged 6 commits into from
Jan 20, 2025

Conversation

gibber9809
Copy link
Contributor

@gibber9809 gibber9809 commented Jan 19, 2025

Description

This PR adds support for extracting archives that are stored on S3 in the package. This feature is supported by pulling credentials from WorkerConfig, much like in #674.

Validation performed

  • Validated that archives on S3 in the package can be extracted successfully
  • Validated that log viewing functions for archives on S3

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced storage type validation for extraction processes.
    • Improved command generation for stream extraction tasks.
  • Bug Fixes

    • Added more robust error handling for S3 storage configurations.
    • Refined logic for detecting unsupported extraction scenarios.
  • Refactor

    • Restructured command generation functions for better modularity.
    • Updated error message handling for extraction tasks.

These updates improve the system's reliability and flexibility when handling different storage types during extraction processes.

@gibber9809 gibber9809 requested a review from haiqi96 January 19, 2025 20:55
Copy link
Contributor

coderabbitai bot commented Jan 19, 2025

Warning

Rate limit exceeded

@gibber9809 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f73ac19 and 46fabe3.

📒 Files selected for processing (1)
  • components/clp-package-utils/clp_package_utils/scripts/decompress.py (3 hunks)

Walkthrough

This pull request focuses on enhancing the handling of storage types, particularly for S3 storage, across two key components: the decompression utility script and the stream extraction task. The changes introduce more granular validation for storage types, adding support for checking both StorageType and StorageEngine. A new import of StorageEngine is added, and the command generation logic is refactored to provide more robust error handling and support for different storage configurations.

Changes

File Change Summary
components/clp-package-utils/clp_package_utils/scripts/decompress.py - Added import for StorageEngine
- Enhanced storage type validation logic
- Updated error handling for extraction scenarios
components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py - Renamed make_command to _make_clp_command_and_env_vars
- Added _make_clp_s_command_and_env_vars for JSON extraction
- Introduced _make_command_and_env_vars for command selection
- Updated command generation and error handling for S3 storage
components/job-orchestration/job_orchestration/executor/query/fs_search_task.py - Updated AWS credential retrieval method
- Retained error handling for missing credentials

Possibly Related PRs

Suggested Reviewers

  • haiqi96
  • kirkrodrigues

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py (1)

109-112: Avoid including all environment variables when setting AWS credentials

Including the entire os.environ in env_vars may unintentionally expose unnecessary or sensitive environment variables to the subprocess. It's safer to include only the required AWS credentials.

Apply this diff to set only the necessary environment variables:

-env_vars = {
-    **os.environ,
-    "AWS_ACCESS_KEY_ID": s3_config.credentials.access_key_id,
-    "AWS_SECRET_ACCESS_KEY": s3_config.credentials.secret_access_key,
-}
+env_vars = {
+    "AWS_ACCESS_KEY_ID": aws_access_key_id,
+    "AWS_SECRET_ACCESS_KEY": aws_secret_access_key,
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d1bc59 and 9f89fe4.

📒 Files selected for processing (2)
  • components/clp-package-utils/clp_package_utils/scripts/decompress.py (3 hunks)
  • components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py (4 hunks)
🔇 Additional comments (3)
components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py (1)

142-172: Well-structured command generation logic

The introduction of _make_command_and_env_vars function and the separation of command generation based on storage_engine enhance code modularity and readability.

components/clp-package-utils/clp_package_utils/scripts/decompress.py (2)

85-90: Enhanced validation of storage type and engine

Adding the check for both StorageType.S3 and StorageEngine.CLP improves error handling by providing clearer context when file extraction is unsupported.


169-173: Improved error handling for unsupported stream extraction

Validating both storage_type and storage_engine before proceeding ensures that unsupported extraction scenarios are correctly identified and handled.

if StorageType.FS != storage_type:
logger.error(f"File extraction is not supported for archive storage type: {storage_type}.")
storage_engine = clp_config.package.storage_engine
if StorageType.S3 == storage_type and StorageEngine.CLP == storage_engine:
Copy link
Contributor

@haiqi96 haiqi96 Jan 19, 2025

Choose a reason for hiding this comment

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

Just to confirm, do we have support for decompressing clp-s archive from S3 now in our decompression script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, added by this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure? File decompression is not through _task.py but directly handled by native/decompress.py though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see what you mean. The extract file command doesn't seem to be supported for clp-s at all (the script is hardcoded for clp). We didn't previously have a check to prevent using it for clp-s, but I'll add one.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we will need a check to ensure it's only supported on CLP & FS combination.

Copy link
Contributor

@haiqi96 haiqi96 left a comment

Choose a reason for hiding this comment

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

majorly nit

@gibber9809 gibber9809 requested a review from haiqi96 January 20, 2025 15:27
@@ -162,9 +166,11 @@ def handle_extract_stream_cmd(
return -1

storage_type = clp_config.archive_output.storage.type
if StorageType.FS != storage_type:
storage_engine = clp_config.package.storage_engine
if StorageType.S3 == storage_type and StorageEngine.CLP == storage_engine:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I might write

if StorageType.S3 == storage_type and StorageEngine.CLP_S != storage_engine since we only expect CLP-s to support S3. but not a big deal

Copy link
Contributor

@haiqi96 haiqi96 left a comment

Choose a reason for hiding this comment

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

For title, how about:

feat(clp-package): Add support for extracting IR/JSON streams from S3.

or

feat(clp-package): Add support for extracting IR/JSON streams from archives stored on S3.

@gibber9809
Copy link
Contributor Author

For title, how about:

feat(clp-package): Add support for extracting IR/JSON streams from S3.

or

feat(clp-package): Add support for extracting IR/JSON streams from archives stored on S3.

Since we don't actually add support for extracting to IR how about
feat(clp-package): Add support for extracting JSON streams from archives stored on S3.

@gibber9809 gibber9809 changed the title feat(clp-json): Add support for extracting archives that are stored on S3. feat(clp-package): Add support for extracting JSON streams from archives stored on S3. Jan 20, 2025
@haiqi96
Copy link
Contributor

haiqi96 commented Jan 20, 2025

For title, how about:
feat(clp-package): Add support for extracting IR/JSON streams from S3.
or
feat(clp-package): Add support for extracting IR/JSON streams from archives stored on S3.

Since we don't actually add support for extracting to IR how about feat(clp-package): Add support for extracting JSON streams from archives stored on S3.

Right, right. The title you suggested makes more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants