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

📚 docs: Add Retry Addon documentation #3330

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

grivera64
Copy link
Member

Description

Fiber added its first add-on in PR #1972, called retry. The documentation for this add-on is not currently included in v3's documentation on docs.gofiber.io.

This PR adds this missing documentation under a new collapsible tab under the middleware tab.

Fixes #3326

Changes introduced

  • Benchmarks: Describe any performance benchmarks and improvements related to the changes.
  • Documentation Update: Detail the updates made to the documentation and links to the changed files.
    • Add a new tab to docs.gofiber.io for addons
  • Changelog/What's New: Include a summary of the additions for the upcoming release notes.
  • Migration Guide: If necessary, provide a guide or steps for users to migrate their existing code to accommodate these changes.
  • API Alignment with Express: Explain how the changes align with the Express API.
  • API Longevity: Discuss the steps taken to ensure that the new or updated APIs are consistent and not prone to breaking changes.
  • Examples: Provide examples demonstrating the new features or changes in action.
    • Add a more detailed usage example of retry

Type of change

  • Documentation update (changes to documentation)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

@grivera64 grivera64 self-assigned this Feb 26, 2025
@grivera64 grivera64 requested a review from a team as a code owner February 26, 2025 07:11
@grivera64 grivera64 requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team February 26, 2025 07:11
Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

This pull request enhances the retry addon documentation for Fiber by introducing a new example in the README and adding a separate documentation file. The README now includes a complete main function example that demonstrates the exponential backoff retry logic along with an updated default configuration section. The new documentation file further explains the retry mechanism with jitter, details the configuration options, and provides the function signature and type declarations for the addon.

Changes

File(s) Summary of changes
addon/retry/README.md Added a new example demonstrating NewExponentialBackoff usage with a complete main function, updated the section header from "Default Config Example" to "Default Config", introduced a DefaultConfig variable, and refined spacing in the Config struct.
docs/addon/retry.md Introduced a new documentation file for the retry addon, outlining the retry mechanism with exponential backoff and jitter, providing a function signature for NewExponentialBackoff, defining the Config struct, and detailing default and customizable configuration options.

Sequence Diagram(s)

sequenceDiagram
    participant M as Main Function
    participant EB as ExponentialBackoff
    participant NR as Network Request

    M->>EB: Initialize ExponentialBackoff
    loop Retry Attempts
        M->>NR: Execute Network Request
        NR-->>M: Return response or error
        alt Failure (error or non-200)
            M->>EB: Wait using exponential backoff
        else Success (status 200)
            M-->>EB: Proceed with successful response
        end
    end
    M->>M: Panic if all retries fail
Loading

Suggested labels

✏️ Feature, v3

Suggested reviewers

  • gaby
  • sixcolors
  • efectn
  • ReneWerner87

Poem

Hop along, dear coder, in joyful delight,
For retries now dance in the code so bright.
Exponential leaps with each network quest,
Configs refined, putting errors to rest.
A rabbit sings of progress in every byte,
Celebrating changes from morning to night! 🐰


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.
  • @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

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.27%. Comparing base (bc4c920) to head (904549c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3330      +/-   ##
==========================================
+ Coverage   84.21%   84.27%   +0.06%     
==========================================
  Files         116      116              
  Lines       11577    11577              
==========================================
+ Hits         9749     9757       +8     
+ Misses       1397     1391       -6     
+ Partials      431      429       -2     
Flag Coverage Δ
unittests 84.27% <ø> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 comments (2)
addon/retry/README.md (2)

10-17: 🛠️ Refactor suggestion

Update TOC Link Fragment Consistency.
The Table of Contents includes the link Default Config Example, but no section exists with that exact anchor. To resolve the markdownlint error (MD051) and avoid confusing readers, please either update the link to match an existing heading (for example, Default Config) or rename the corresponding section heading to "Default Config Example."

🧰 Tools
🪛 LanguageTool

[duplication] ~15-~15: Possible typo: you repeated a word.
Context: ...ault Config](#default-config) - Custom Config - Config - [Default Config Example](#d...

(ENGLISH_WORD_REPEAT_RULE)

🪛 GitHub Check: markdownlint

[failure] 17-17: Link fragments should be valid
addon/retry/README.md:17:3 MD051/link-fragments Link fragments should be valid [Context: "Default Config Example"] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md051.md

🪛 GitHub Actions: markdownlint

[error] 17-17: MD051/link-fragments Link fragments should be valid [Context: 'Default Config Example']


116-127: 🛠️ Refactor suggestion

Align Section Heading with TOC.
The section that declares the default configuration variable is titled "## Default Config," yet the Table of Contents lists a link for Default Config Example. For consistency and to fix the markdownlint error, please rename the section header (e.g., to "## Default Config Example") or adjust the TOC accordingly.

🧹 Nitpick comments (2)
addon/retry/README.md (1)

27-63: Clarify Example Code Variable Naming.
The example in the main function neatly illustrates how to use retry.NewExponentialBackoff. However, note that the local variable named client (declared inside the retry callback) shares its name with the imported package. To avoid any potential shadowing or confusion, consider renaming the local variable (for instance, to c or httpClient).

docs/addon/retry.md (1)

29-67: Refine Example Code for Consistency.
The provided example effectively demonstrates the usage of the retry addon. Similar to the README, the callback declares a local variable named client that might conflict with the imported package identifier. Consider renaming this local variable to improve clarity.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc4c920 and 5fd4980.

⛔ Files ignored due to path filters (4)
  • docs/addon/_category_.json is excluded by !**/*.json
  • docs/client/_category_.json is excluded by !**/*.json
  • docs/extra/_category_.json is excluded by !**/*.json
  • docs/guide/_category_.json is excluded by !**/*.json
📒 Files selected for processing (2)
  • addon/retry/README.md (2 hunks)
  • docs/addon/retry.md (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: markdownlint
addon/retry/README.md

[error] 17-17: MD051/link-fragments Link fragments should be valid [Context: 'Default Config Example']

🪛 LanguageTool
docs/addon/retry.md

[duplication] ~19-~19: Possible typo: you repeated a word.
Context: ...ault Config](#default-config) - Custom Config - Config - [Default Config Example](#d...

(ENGLISH_WORD_REPEAT_RULE)

🪛 GitHub Check: markdownlint
docs/addon/retry.md

[failure] 21-21: Link fragments should be valid
docs/addon/retry.md:21:3 MD051/link-fragments Link fragments should be valid [Context: "Default Config Example"] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md051.md

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: unit (1.24.x, macos-13)
  • GitHub Check: unit (1.24.x, macos-latest)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, macos-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: Compare
  • GitHub Check: Analyse
  • GitHub Check: repeated

Comment on lines +12 to +21
## Table of Contents

- [Retry Addon](#retry-addon)
- [Table of Contents](#table-of-contents)
- [Signatures](#signatures)
- [Examples](#examples)
- [Default Config](#default-config)
- [Custom Config](#custom-config)
- [Config](#config)
- [Default Config Example](#default-config-example)
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

Ensure Valid TOC Links.
Within the Table of Contents, the link Default Config Example does not match any section heading in the document. To improve navigation and address markdownlint MD051, please update the link so that it corresponds to an existing anchor (for example, matching a header renamed to "## Default Config Example") or modify the TOC entry accordingly.

🧰 Tools
🪛 LanguageTool

[duplication] ~19-~19: Possible typo: you repeated a word.
Context: ...ault Config](#default-config) - Custom Config - Config - [Default Config Example](#d...

(ENGLISH_WORD_REPEAT_RULE)

🪛 GitHub Check: markdownlint

[failure] 21-21: Link fragments should be valid
docs/addon/retry.md:21:3 MD051/link-fragments Link fragments should be valid [Context: "Default Config Example"] https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md051.md

Comment on lines 120 to 131
## Default Config

```go
// DefaultConfig is the default config for retry.
var DefaultConfig = Config{
InitialInterval: 1 * time.Second,
MaxBackoffTime: 32 * time.Second,
Multiplier: 2.0,
MaxRetryCount: 10,
currentInterval: 1 * time.Second,
}
```
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

Consistent Section Naming Recommended.
The section header for the default configuration variable is labeled "## Default Config" but is referenced in the TOC as Default Config Example. Renaming this header to "## Default Config Example" would ensure uniformity across the document and resolve the link fragment issue.

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

🧹 Nitpick comments (2)
addon/retry/README.md (1)

1-7: Improve Description Clarity in the Introduction
The introductory paragraph explains the addon’s purpose well, but the sentence “If all calls are failed, then, it returns an error.” can be rephrased for clarity. Consider updating it to:

-If all calls are failed, then, it returns an error.
+If all calls fail, an error is returned.

This change improves readability and grammatical accuracy.

docs/addon/retry.md (1)

1-11: Enhance Introduction Wording in YAML Documentation
The YAML front matter and introductory section effectively introduce the Retry Addon. However, similar to the README, consider rephrasing the sentence in the introduction to avoid repetition and improve clarity. For example:

-If all calls are failed, then, it returns an error. It adds a jitter at each retry step because adding
- a jitter is a way to break synchronization across the client and avoid collision.
+If all calls fail, an error is returned. A jitter is added at each retry step to break client synchronization and avoid collisions.

This revision removes redundant wording and makes the description more concise.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5fd4980 and 904549c.

📒 Files selected for processing (2)
  • addon/retry/README.md (2 hunks)
  • docs/addon/retry.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/addon/retry.md

[duplication] ~19-~19: Possible typo: you repeated a word.
Context: ...ault Config](#default-config) - Custom Config - Config - [Default Config Example](#d...

(ENGLISH_WORD_REPEAT_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: unit (1.24.x, macos-13)
  • GitHub Check: unit (1.24.x, macos-latest)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, macos-13)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: Compare
  • GitHub Check: repeated
🔇 Additional comments (5)
addon/retry/README.md (2)

8-18: Table of Contents Validation
The Table of Contents accurately lists all key sections, including “Default Config Example.” Ensure that the corresponding section header exactly matches the TOC entry so that in-page navigation works correctly. Currently, the TOC entry “Default Config Example” aligns with the later header, so no changes are necessary here.

🧰 Tools
🪛 LanguageTool

[duplication] ~15-~15: Possible typo: you repeated a word.
Context: ...ault Config](#default-config) - Custom Config - Config - [Default Config Example](#d...

(ENGLISH_WORD_REPEAT_RULE)


25-63: Examples Code Block – Clear and Comprehensive
The complete example in the “Examples” section demonstrates how to initialize the exponential backoff and perform a network request with retry logic. The inline comments make the code easy to follow. One consideration: while using panic(err) is acceptable in a demonstrative context, you might want to note (in comments) that in production code more graceful error handling could be preferable.

docs/addon/retry.md (3)

12-22: Table of Contents Consistency
The TOC accurately reflects the document’s sections, and the link “Default Config Example” now matches the header “## Default Config Example.” This resolves previous navigation issues and aligns with best practices for markdown links.

🧰 Tools
🪛 LanguageTool

[duplication] ~19-~19: Possible typo: you repeated a word.
Context: ...ault Config](#default-config) - Custom Config - Config - [Default Config Example](#d...

(ENGLISH_WORD_REPEAT_RULE)


29-67: Examples Code Block – Clear Demonstration
The “Examples” section provides a full, illustrative usage example of the retry functionality. The sample code is clear, well-commented, and effectively demonstrates how to handle errors during retries using the exponential backoff mechanism.


69-128: Configuration and Default Config Example Sections are Well Structured
The “Default Config,” “Custom Config,” “Config,” and “Default Config Example” sections comprehensively document the addon's configuration options. The code examples are consistent and maintain a clear style throughout the document. These sections offer valuable, easily digestible information for users looking to customize their retry behavior.

## Signatures

```go
func NewExponentialBackoff(config ...Config) *ExponentialBackoff
Copy link
Member

Choose a reason for hiding this comment

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

pls use rety.Config

Copy link
Member

@ReneWerner87 ReneWerner87 left a comment

Choose a reason for hiding this comment

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

@ReneWerner87 ReneWerner87 added this to the v3 milestone Feb 26, 2025
@gaby gaby changed the title 📚 Docs: Add Addon docs 📚 docs: Add Retry Addon documentation Feb 26, 2025
"collapsed": true,
"link": {
"type": "generated-index",
"description": "Addons are additional useful packages that can be used in Fiber."
Copy link
Member

Choose a reason for hiding this comment

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

This should say:

Addon is an additional useful package that can be used in Fiber.

// currentInterval tracks the current waiting time.
//
// Optional. Default: 1 * time.Second
currentInterval time.Duration
Copy link
Member

Choose a reason for hiding this comment

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

This is a private config option, I dont think it needs to be here in the docs.

@ReneWerner87
Copy link
Member

@grivera64 can you check our hints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

🧹 [Maintenance]: Add missing retry add-on documentation to docs.gofiber.io
3 participants