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-json): Add support for searching archives that are stored on S3. #674

Merged
merged 8 commits into from
Jan 19, 2025

Conversation

gibber9809
Copy link
Contributor

@gibber9809 gibber9809 commented Jan 17, 2025

Description

This PR adds support for searching clp-json archives from s3 in the package. This is achieved by simply pulling the storage configuration from WorkerConfig and adding appropriate arguments to the clp-s invocation.

Validation performed

  • Validated that search completes succesfully when archive storage is configured to point to s3 and storage engine is clp-s

Summary by CodeRabbit

  • New Features

    • Enhanced search functionality with more robust storage type and engine validation.
    • Added support for environment variable configuration in task execution.
  • Bug Fixes

    • Improved error handling for unsupported storage configurations.
    • Updated command generation for different storage types.
  • Refactor

    • Modularized command construction logic.
    • Updated function signatures to support more flexible task execution.

@gibber9809 gibber9809 requested a review from haiqi96 January 17, 2025 18:02
Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Walkthrough

The pull request introduces modifications across multiple components of the job orchestration and package utility systems. The changes primarily focus on enhancing command generation, error handling, and support for different storage types and engines. Key modifications include adding new functions for command generation, updating function signatures to support environment variables, and improving storage type validation logic. The changes enhance the error handling for specific combinations of storage types and engines, providing more flexible and robust handling of search and extraction tasks across various storage configurations.

Changes

File Change Summary
components/clp-package-utils/clp_package_utils/scripts/search.py - Added StorageEngine import
- Modified storage type validation logic in main function
components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py - Added optional env_vars parameter to extract_stream method
components/job-orchestration/job_orchestration/executor/query/fs_search_task.py - Added two new command generation functions
- Updated make_command_and_env_vars to return command and environment variables
- Enhanced error handling for storage types
components/job-orchestration/job_orchestration/executor/query/utils.py - Added optional env_vars parameter to run_query_task
- Updated subprocess.Popen to support environment variables

Possibly related PRs


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d48687f and e6a200f.

📒 Files selected for processing (4)
  • components/clp-package-utils/clp_package_utils/scripts/search.py (2 hunks)
  • components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py (1 hunks)
  • components/job-orchestration/job_orchestration/executor/query/fs_search_task.py (5 hunks)
  • components/job-orchestration/job_orchestration/executor/query/utils.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py
  • components/clp-package-utils/clp_package_utils/scripts/search.py
  • components/job-orchestration/job_orchestration/executor/query/utils.py
  • components/job-orchestration/job_orchestration/executor/query/fs_search_task.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)

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/clp-package-utils/clp_package_utils/scripts/search.py (1)

Line range hint 87-142: Consider enhancing error handling with specific error codes.

The command generation and execution logic looks good, but consider improving error handling by:

  1. Using specific error codes instead of just -1 for different failure scenarios
  2. Adding error handling for the subprocess.run() call
  3. Cleaning up the generated config file in case of failures

Here's a suggested improvement:

     if StorageType.S3 == storage_type and StorageEngine.CLP == storage_engine:
         logger.error(
             f"Search is not supported for archive storage type: {storage_type} while using the {storage_engine} storage engine."
         )
-        return -1
+        return 2  # Specific error code for unsupported storage configuration

     # ... existing code ...

-    subprocess.run(cmd, check=True)
+    try:
+        subprocess.run(cmd, check=True)
+    except subprocess.CalledProcessError as e:
+        logger.error(f"Search command failed with exit code {e.returncode}")
+        return 3  # Specific error code for search execution failure
+    finally:
+        # Clean up generated files even if an error occurs
+        if generated_config_path_on_host.exists():
+            generated_config_path_on_host.unlink()

-    # Remove generated files
-    generated_config_path_on_host.unlink()
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ac9055 and a53d6c3.

📒 Files selected for processing (4)
  • components/clp-package-utils/clp_package_utils/scripts/search.py (2 hunks)
  • components/job-orchestration/job_orchestration/executor/query/extract_stream_task.py (1 hunks)
  • components/job-orchestration/job_orchestration/executor/query/fs_search_task.py (5 hunks)
  • components/job-orchestration/job_orchestration/executor/query/utils.py (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (8)
components/job-orchestration/job_orchestration/executor/query/fs_search_task.py (4)

4-4: LGTM! The new imports support S3 functionality.

The addition of Tuple for type hints and generate_s3_virtual_hosted_style_url for S3 URL generation are appropriate for the new S3 search feature.

Also applies to: 10-10


24-41: LGTM! Well-structured command generation for CLP storage engine.

The function properly handles:

  • Early validation of S3 storage type compatibility
  • Clear error messaging
  • Consistent command construction with optional path filtering

Line range hint 88-158: LGTM! Well-structured refactoring of command generation.

The separation of concerns into specialized functions improves maintainability while preserving the existing functionality.


Line range hint 197-218: LGTM! Proper handling of environment variables in search task.

The changes correctly integrate the new environment variables support while maintaining the existing functionality.

components/job-orchestration/job_orchestration/executor/query/utils.py (1)

46-46: LGTM! Proper environment variables support in task execution.

The addition of the env_vars parameter and its integration with subprocess.Popen is well-implemented.

Also applies to: 67-67

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

144-144: LGTM! Maintains backward compatibility.

The addition of env_vars=None properly supports the new parameter while maintaining existing behaviour.

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

10-10: LGTM! Import change aligns with the new storage engine validation.

The addition of StorageEngine import is necessary and follows Python's import style guidelines.


82-86: ⚠️ Potential issue

Review storage validation logic - possible contradiction with PR objectives.

The current implementation blocks S3 storage with CLP engine, but according to the PR objectives, we should be adding S3 search capability. This appears to contradict the PR's goal of "incorporating the capability to search clp-json archives stored in Amazon S3."

Consider the following:

  1. If S3 search should be supported, this validation block might need to be removed or modified.
  2. If certain S3 configurations aren't supported, the error message should clarify which configurations are supported.
  3. Based on the AI summary, there are new functions in fs_search_task.py for handling S3 storage - this code might need to leverage those instead of returning an error.

Let's verify the intended behaviour:

Comment on lines 72 to 76
env_vars = {
**os.environ,
"AWS_ACCESS_KEY_ID": s3_config.access_key_id,
"AWS_SECRET_ACCESS_KEY": s3_config.secret_access_key,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider security implications of environment inheritance.

The current implementation inherits all existing environment variables (os.environ) before adding AWS credentials. This could potentially expose unnecessary environment variables to the subprocess.

Consider passing only the required environment variables:

-        env_vars = {
-            **os.environ,
-            "AWS_ACCESS_KEY_ID": s3_config.access_key_id,
-            "AWS_SECRET_ACCESS_KEY": s3_config.secret_access_key,
-        }
+        env_vars = {
+            "AWS_ACCESS_KEY_ID": s3_config.access_key_id,
+            "AWS_SECRET_ACCESS_KEY": s3_config.secret_access_key,
+            "PATH": os.environ.get("PATH", ""),  # Required for executing binaries
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
env_vars = {
**os.environ,
"AWS_ACCESS_KEY_ID": s3_config.access_key_id,
"AWS_SECRET_ACCESS_KEY": s3_config.secret_access_key,
}
env_vars = {
"AWS_ACCESS_KEY_ID": s3_config.access_key_id,
"AWS_SECRET_ACCESS_KEY": s3_config.secret_access_key,
"PATH": os.environ.get("PATH", ""), # Required for executing binaries
}

Co-authored-by: haiqi96 <14502009+haiqi96@users.noreply.github.com>
@gibber9809 gibber9809 requested a review from haiqi96 January 17, 2025 20:58

from clp_py_utils.clp_config import CLPConfig, StorageEngine
from clp_py_utils.s3_utils import parse_aws_credentials_file

# from clp_py_utils.s3_utils import parse_aws_credentials_file
Copy link
Contributor

Choose a reason for hiding this comment

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

by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes sorry didn't mean to include this diff

@gibber9809 gibber9809 force-pushed the package-archive-from-s3 branch from 2342742 to 3e50655 Compare January 17, 2025 21:04
}
else:
# fmt: off
command.extend((
Copy link
Contributor

Choose a reason for hiding this comment

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

correct me if wrong, shouldn't the argument of extend be []?

Copy link
Contributor

Choose a reason for hiding this comment

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

double checked, extend with a set also works.
I just get used to list more, but I guess set is also fine, unless our code guideline has a strict rule on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's consistent with how its used elsewhere in fs_search_task.py. Also its a tuple, not a set right?

logger.error(f"Encountered error while generating s3 url: {ex}")
return None, None
# fmt: off
command.extend((
Copy link
Contributor

Choose a reason for hiding this comment

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

same question here

@haiqi96
Copy link
Contributor

haiqi96 commented Jan 17, 2025

Nit: the private method (those make_blabla_commands) should start with "_".

However I realized I forgot to add "" to the ones to compress_task.py in my previous PR and I guess you just copied them. So I will leave it to you to decide if you want to add "" in this PR.

If not, we can open another PR to fix the method naming in both scripts

@gibber9809
Copy link
Contributor Author

Nit: the private method (those make_blabla_commands) should start with "_".

However I realized I forgot to add "" to the ones to compress_task.py in my previous PR and I guess you just copied them. So I will leave it to you to decide if you want to add "" in this PR.

If not, we can open another PR to fix the method naming in both scripts

I'll rename all the make commands used in this PR but won't touch the ones from compress_task.py

@gibber9809 gibber9809 requested a review from haiqi96 January 17, 2025 21:44
haiqi96
haiqi96 previously approved these changes Jan 17, 2025
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.

Tested manually and confirmed both S3 and FS search works for CLP-S.
Also confirmed FS search works for CLP.

will see if @kirkrodrigues wants to go through a final pass

@haiqi96
Copy link
Contributor

haiqi96 commented Jan 18, 2025

Since #662 is merged, please also update the code that gets credential from the config

@gibber9809
Copy link
Contributor Author

gibber9809 commented Jan 18, 2025

Since #662 is merged, please also update the code that gets credential from the config

Merged and pushed up the credentials changes. Github seems to be stuck processing that most recent push, though I can see when I check the branch that the CI passes without issue. If github is still stuck when I check tomorrow I might close this PR and open a new identical one.

"s3"
))
# fmt: on
env_vars = {
Copy link
Member

Choose a reason for hiding this comment

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

When you create the new PR, can you move the error check for the credentials above this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this change. Seems to have gotten un-stuck once I pushed up new changes, so looks like I won't have to put up a new PR.

Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

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

For the PR title, how about:

feat(clp-json): Add support for searching archives that are stored on S3.

@gibber9809 gibber9809 changed the title feat(clp-package): Add s3 search for clp-json to package. feat(clp-json): Add support for searching archives that are stored on S3. Jan 19, 2025
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.

3 participants