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

fix: download_directory local path incorrectly stored #54

Merged
merged 5 commits into from
Oct 7, 2024

Conversation

jjjermiah
Copy link
Collaborator

@jjjermiah jjjermiah commented Oct 3, 2024

when specifying a directory for input, or using the output from a previous rule that is marked with directory() the directory downloads directory into the workdir instead of into .snakemake/storage/gcs

This fix should hopefully fix that.

Summary by CodeRabbit

  • New Features

    • Introduced a Google Cloud Storage (GCS) storage provider with enhanced configuration options.
    • Added functionality for file integrity checks during downloads.
    • Implemented methods for managing storage objects, including existence checks, metadata retrieval, and directory uploads.
    • Enhanced query handling and rate limiting for GCS interactions.
    • Improved efficiency in downloading multiple blobs with directory support.
  • Bug Fixes

    • Improved error handling with retry logic for transient issues.

Copy link

coderabbitai bot commented Oct 3, 2024

Warning

Rate limit exceeded

@jjjermiah has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 41 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

Files that changed from the base of the PR and between a1a3e53 and 07b747d.

Walkthrough

The pull request introduces significant enhancements to the Google Cloud Storage (GCS) storage provider within the Snakemake framework. Key additions include the StorageProviderSettings data class for configuration options, the Crc32cCalculator for checksum validation, and the StorageProvider class for managing storage interactions. New methods for listing objects, processing queries, and handling storage objects are implemented, alongside retry logic for transient errors. These changes collectively improve the functionality and robustness of GCS integration.

Changes

File Change Summary
snakemake_storage_plugin_gcs/init.py - Added StorageProviderSettings, Crc32cCalculator, StorageProvider, and StorageObject classes.
- Introduced methods for downloading blobs, listing objects, and managing storage object properties (exists, mtime, size, retrieve, remove).
- Implemented retry logic and query processing methods.
- Refactored _download_directory to use transfer_manager.download_many_to_path.

Possibly related PRs


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 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

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d6d1bae and 10aab6f.

📒 Files selected for processing (1)
  • snakemake_storage_plugin_gcs/init.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
snakemake_storage_plugin_gcs/__init__.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

snakemake_storage_plugin_gcs/__init__.py Outdated Show resolved Hide resolved
Copy link

@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

🧹 Outside diff range and nitpick comments (1)
snakemake_storage_plugin_gcs/__init__.py (1)

528-529: LGTM! Path construction fixed as intended.

The change correctly addresses the issue of downloading directories to the wrong location. By using self.provider.local_prefix, the files will now be stored in the .snakemake/storage/gcs directory as intended.

For improved clarity, consider adding a comment explaining the purpose of this path construction:

# Construct the local path ensuring files are stored in .snakemake/storage/gcs
local_name = self.provider.local_prefix / self.bucket.name / blob.name

This will help future maintainers understand the importance of this line.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 10aab6f and 9c9a577.

📒 Files selected for processing (1)
  • snakemake_storage_plugin_gcs/init.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
snakemake_storage_plugin_gcs/__init__.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

🔇 Additional comments (1)
snakemake_storage_plugin_gcs/__init__.py (1)

528-529: Summary: PR objective achieved, with room for further improvement

The changes successfully address the main issue of incorrect directory downloads. The implementation looks good and should resolve the problem described in the PR objectives.

To further improve the code:

  1. Consider adding a clarifying comment for the new path construction.
  2. Explore the possibility of unifying path construction logic across download and upload methods.

These suggestions aim to enhance code clarity and maintainability for future development.

snakemake_storage_plugin_gcs/__init__.py Outdated Show resolved Hide resolved
Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9c9a577 and efe8dbc.

📒 Files selected for processing (1)
  • snakemake_storage_plugin_gcs/init.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
snakemake_storage_plugin_gcs/__init__.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

🔇 Additional comments (1)
snakemake_storage_plugin_gcs/__init__.py (1)

33-33: Importing transfer_manager is appropriate

The import statement correctly includes transfer_manager from google.cloud.storage, enabling batch download functionality.

snakemake_storage_plugin_gcs/__init__.py Outdated Show resolved Hide resolved
Copy link

@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: 0

🧹 Outside diff range and nitpick comments (1)
snakemake_storage_plugin_gcs/__init__.py (1)

525-536: Approve changes with suggestions for improvement

The refactoring of _download_directory to use transfer_manager.download_many_to_path is a good improvement that should enhance performance through batch downloads. The error handling for failed downloads is also a positive addition.

However, there are two areas for potential improvement:

  1. Error Logging: As per a previous review comment, using self.logger.error is not recommended. Consider using a more appropriate logging method or raising an exception for failed downloads.

  2. Path Construction: The path construction (self.provider.local_prefix / self.bucket.name) might not be consistent with other parts of the code. Consider unifying the path construction logic across methods, as suggested in a previous review comment.

Consider implementing these improvements:

  1. Replace the error logging with a more appropriate method or exception handling.
  2. Create a helper function for path construction to ensure consistency across the codebase.

Would you like assistance in implementing these suggestions?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between efe8dbc and a1a3e53.

📒 Files selected for processing (1)
  • snakemake_storage_plugin_gcs/init.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
snakemake_storage_plugin_gcs/__init__.py (1)

Pattern **/*.py: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

🔇 Additional comments (1)
snakemake_storage_plugin_gcs/__init__.py (1)

33-33: LGTM: New import for transfer_manager

The addition of transfer_manager import from google.cloud.storage is appropriate and necessary for the changes in the _download_directory method.

@jjjermiah
Copy link
Collaborator Author

After some minor benchmarking, iterating over blobs to download in _download_directory turns out to be quite slow, especially in my case where I have a few thousand dicom files taking ~ 80 seconds just to download the directory.

When running on GKE for ~10k jobs a minute of downloading could add up against our costs.

the transfer_manager class in the google.cloud.storage module is recommended in the docs for concurrent downloads

in a sample case the time taken is now ~6 seconds (92% improvement)

if this change works and is approved I can also update the upload_directory method as well.

@jjjermiah jjjermiah requested a review from manbat October 4, 2024 18:33
@johanneskoester johanneskoester merged commit bc3d739 into snakemake:main Oct 7, 2024
5 checks passed
johanneskoester pushed a commit that referenced this pull request Oct 7, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.1.2](v1.1.1...v1.1.2)
(2024-10-07)


### Bug Fixes

* download_directory local path incorrectly stored
([#54](#54))
([bc3d739](bc3d739))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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