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

Add MaxRetry for MinIO operations #1530

Merged
merged 3 commits into from
Nov 14, 2024
Merged

Add MaxRetry for MinIO operations #1530

merged 3 commits into from
Nov 14, 2024

Conversation

itpey
Copy link
Contributor

@itpey itpey commented Nov 13, 2024

This PR introduces a new MaxRetry configuration option to the Config struct, allowing users to specify the maximum number of retry attempts for MinIO operations.

Summary by CodeRabbit

  • New Features

    • Introduced a MaxRetry configuration option to specify the maximum retry attempts for requests, enhancing reliability during failures.
    • Updated default configuration to include the MaxRetry field.
  • Improvements

    • Enhanced dynamic configuration of the MaxRetry parameter when creating new storage instances, allowing for better customization.

@itpey itpey requested a review from a team as a code owner November 13, 2024 20:34
@itpey itpey requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team November 13, 2024 20:34
Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes introduced in this pull request add a new field, MaxRetry, to the Config struct in both the minio/README.md and minio/config.go files. This field specifies the maximum number of retry attempts for requests that encounter retryable failures, with a default value set to 10. The ConfigDefault variable is also updated to include this new field. Additionally, the New function in minio/minio.go is modified to set the MaxRetry parameter based on the provided configuration, allowing for dynamic configuration during the instantiation of the Storage struct.

Changes

File Change Summary
minio/README.md - Added field MaxRetry int to struct Config.
- Updated ConfigDefault to include MaxRetry: 10.
minio/config.go - Added field MaxRetry int to struct Config.
- Updated ConfigDefault to initialize MaxRetry with minio.MaxRetry.
minio/minio.go - Modified New function to set MaxRetry based on configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Config
    participant Storage

    User->>Config: Set MaxRetry
    Config->>Storage: Create new instance with MaxRetry
    Storage->>Storage: Perform operations (Get, Set, etc.)
    Storage-->>User: Return results
Loading

🐇 "In the meadow, where bunnies play,
A new field joins the fray.
MaxRetry hops in, oh what a sight,
Ten tries to make everything right!
With each request, we bounce and cheer,
For smoother storage, we hold dear!" 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f9f9ee6 and 603305c.

📒 Files selected for processing (1)
  • minio/README.md (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • minio/README.md

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 or @coderabbitai title 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: 2

🧹 Outside diff range and nitpick comments (3)
minio/config.go (1)

Line range hint 77-93: Add MaxRetry handling to configDefault function.

The configDefault helper function should handle the MaxRetry field to ensure it gets the default value when not explicitly set.

Apply this diff:

 func configDefault(config ...Config) Config {
     // Return default config if nothing provided
     if len(config) < 1 {
         return ConfigDefault
     }

     // Override default config
     cfg := config[0]

     // Set default values
     if cfg.Bucket == "" {
         cfg.Bucket = ConfigDefault.Bucket
     }
+    if cfg.MaxRetry == 0 {
+        cfg.MaxRetry = ConfigDefault.MaxRetry
+    }

     return cfg
 }
minio/minio.go (1)

Line range hint 31-47: Consider returning errors instead of panicking

While not directly related to the retry changes, the New function currently panics on initialization errors. As a library function, it would be better to return errors and let the caller decide how to handle them.

Consider refactoring the function signature to:

func New(config ...Config) (*Storage, error) {
	// Set default config
	cfg := configDefault(config...)

	// Minio instance
	minioClient, err := minio.New(cfg.Endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(cfg.Credentials.AccessKeyID, cfg.Credentials.SecretAccessKey, cfg.Token),
		Secure: cfg.Secure,
		Region: cfg.Region,
		Transport: &minio.Transport{
			MaxRetryAttempts: cfg.MaxRetry,
		},
	})
	if err != nil {
		return nil, fmt.Errorf("failed to create MinIO client: %w", err)
	}

	storage := &Storage{minio: minioClient, cfg: cfg, ctx: context.Background()}

	// Reset all entries if set to true
	if cfg.Reset {
		if err = storage.Reset(); err != nil {
			return nil, fmt.Errorf("failed to reset storage: %w", err)
		}
	}

	// check bucket
	if err = storage.CheckBucket(); err != nil {
		// create bucket
		if err = storage.CreateBucket(); err != nil {
			return nil, fmt.Errorf("failed to create bucket: %w", err)
		}
	}

	return storage, nil
}
minio/README.md (1)

97-100: Fix indentation: Replace hard tabs with spaces

The indentation uses hard tabs instead of spaces. To maintain consistency with the rest of the documentation, please replace the hard tabs with spaces.

Apply this diff:

    // The maximum number of times requests that encounter retryable failures should be attempted.
-	// Optional. Default is 10, same as the MinIO client.
-	MaxRetry int
+    // Optional. Default is 10, same as the MinIO client.
+    MaxRetry int
🧰 Tools
🪛 Markdownlint

98-98: Column: 1
Hard tabs

(MD010, no-hard-tabs)


99-99: Column: 1
Hard tabs

(MD010, no-hard-tabs)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a5f954c and cb10688.

📒 Files selected for processing (3)
  • minio/README.md (2 hunks)
  • minio/config.go (2 hunks)
  • minio/minio.go (1 hunks)
🧰 Additional context used
🪛 Markdownlint
minio/README.md

98-98: Column: 1
Hard tabs

(MD010, no-hard-tabs)


99-99: Column: 1
Hard tabs

(MD010, no-hard-tabs)

🔇 Additional comments (2)
minio/config.go (1)

32-34: LGTM! Well-documented MaxRetry field.

The new MaxRetry field is well-documented with clear comments indicating its purpose, optional nature, and default value.

minio/README.md (1)

131-131: ⚠️ Potential issue

Add MaxRetry field to ConfigDefault

The MaxRetry field is documented as having a default value of 10, but it's missing from the ConfigDefault struct. Please add it to maintain consistency with the documentation.

Add the following line to the ConfigDefault struct:

var ConfigDefault = Config{
    Bucket:              "fiber-bucket",
    Endpoint:            "",
    Region:              "",
    Token:               "",
    Secure:              false,
    Reset:               false,
+    MaxRetry:            10,
    Credentials:         Credentials{},

Likely invalid or redundant comment.

minio/minio.go Show resolved Hide resolved
@ReneWerner87
Copy link
Member

ReneWerner87 commented Nov 13, 2024

Thx for the pr

Pls add a test case

@itpey
Copy link
Contributor Author

itpey commented Nov 14, 2024

Thx for the pr

Pls add a test case

I don't think a new test case is necessary since this feature is already covered and well-tested within the MINIO client itself. I have not implemented a new retry mechanism.

https://github.com/minio/minio-go/blob/ab1c2fe050a4dd502c863178696a54c44610ca82/retry.go

minio/README.md Outdated Show resolved Hide resolved
@ReneWerner87
Copy link
Member

Thx for the pr
Pls add a test case

I don't think a new test case is necessary since this feature is already covered and well-tested within the MINIO client itself. I have not implemented a new retry mechanism.

minio/minio-go@ab1c2fe/retry.go

this should not be used to check the underlying functionality, but only to check that the configuration has been set correctly

this prevents an error from occurring later if the configurations become much larger

@ReneWerner87
Copy link
Member

but it looks like I'm a bit too strict there
at least we don't have that with the other adapters
only with the middleware
maybe we can add that later
would definitely help to find configuration errors early on when this process becomes more complex

@ReneWerner87 ReneWerner87 merged commit a0d6e6d into gofiber:main Nov 14, 2024
13 of 14 checks passed
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