Skip to content

GO-3296: Gateway: retry serving images #1163

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

Merged
merged 2 commits into from
Apr 22, 2024
Merged

Conversation

deff7
Copy link
Member

@deff7 deff7 commented Apr 22, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced error handling in file and image retrieval functions to return specific errors instead of generic ones.
    • Introduced retry logic in image retrieval to improve reliability.
  • Refactor

    • Streamlined method signatures and functionality in file and image management modules.
    • Consolidated file statistics functionality to improve maintainability.
  • Bug Fixes

    • Corrected error handling in file and image retrieval functions to enhance accuracy and user feedback.
  • Documentation

    • Updated internal documentation to reflect changes in error handling and retry mechanisms.
  • Tests

    • Added new tests for improved image retrieval processes and retry mechanisms.
  • Chores

    • Removed outdated methods and imports to clean up the codebase and improve efficiency.

Copy link

coderabbitai bot commented Apr 22, 2024

Walkthrough

The recent updates involve refining error handling across various components, removing outdated interfaces, and enhancing functionality by integrating new libraries. Key changes include the removal of redundant error types and methods, streamlining interfaces, and implementing retry mechanisms in image retrieval processes. This revision aims to simplify codebases, improve error transparency, and ensure more robust operations.

Changes

Files Summary
.../core/domain/errors.go, .../core/files/fileobject/fileindex.go Removed ErrFileNotFound and associated error handling logic.
.../core/files/{files.go, images.go} Modified error handling to return original errors instead of generic ones in FileByHash and ImageByHash functions.
.../core/files/mock_files/mock_Image.go Streamlined method signatures, removed Exif methods, and adjusted mock setups.
.../filestorage/filesync/{filesync.go, mock_filesync/mock_FileSync.go, stats.go} Removed FileStat method, shifted focus to Init for mocking, and consolidated functionality in fileInfoToStat.
.../pkg/lib/gateway/{gateway.go, gateway_test.go} Enhanced gateway functionalities with retry logic using retry-go library, updated error handling, and added new test functions and imports.

Poem

🐇✨
In the land of code where the bits frolic,
A rabbit hopped, making changes symbolic.
No more errors generic, files now clear,
With retries in place, no failure to fear.
Hop, skip, a commit, then merge,
In the digital meadow, we surge! 🚀🌟
🐇✨


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between dc8748d and b8cf4d9.
Files selected for processing (1)
  • pkg/lib/gateway/gateway.go (7 hunks)
Additional comments not posted (6)
pkg/lib/gateway/gateway.go (6)

17-17: Added import of "github.com/avast/retry-go/v4".

This import is necessary for the newly introduced retry logic in image handling.


17-17: Removal of outdated dependencies is a good practice to keep the codebase clean and maintainable.


325-347: Introduced retry logic in getImage method using the retry-go library.

This enhancement is crucial for improving the robustness of image retrieval operations, especially in error-prone network environments.


349-352: Added new type getImageReaderResult.

This type helps in encapsulating the file and its reader, which simplifies the handling of these two related data together.


354-367: Added new type retryReadSeeker.

This custom type wraps the standard io.ReadSeeker to add retry capabilities, which is essential for reliable file operations over unstable networks.


384-411: Updated getImageReader method to support dynamic image resolution based on request parameters.

This update enhances the flexibility of the image serving functionality by allowing clients to request images of specific resolutions.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

func newRetryReadSeeker(reader io.ReadSeeker, options ...retry.Option) *retryReadSeeker {
// EOF has special meaning, do not retry on it
options = append(options, retry.RetryIf(func(err error) bool {
return err != io.EOF
Copy link

Choose a reason for hiding this comment

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

The comparison with != for io.EOF may fail on wrapped errors. Use errors.Is for a more robust error check.

- return err != io.EOF
+ return !errors.Is(err, io.EOF)

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.

Suggested change
return err != io.EOF
return !errors.Is(err, io.EOF)

Copy link

github-actions bot commented Apr 22, 2024

New Coverage 44.7% of statements
Patch Coverage 77.4% of changed statements (24/31)

Coverage provided by https://github.com/seriousben/go-patch-cover-action

@deff7 deff7 merged commit 33df40b into main Apr 22, 2024
@deff7 deff7 deleted the go-3296-shared-space-broken-image branch April 22, 2024 15:16
@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants