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(middleware/proxy): Add DialDualStack option for upstream IPv6 support #2900

Merged
merged 3 commits into from Mar 13, 2024

Conversation

negrel
Copy link
Contributor

@negrel negrel commented Mar 5, 2024

Description

This PR adds a DialDualStack options to github.com/gofiber/fiber/v2/middleware/proxy.Config in order to enable proxy middleware to forward to IPv6 upstreams.

Fixes #2890

Changes introduced

List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.

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

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)
  • Performance improvement (non-breaking change which improves efficiency)
  • Code consistency (non-breaking change which improves code reliability and robustness)

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.

Commit formatting

Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md

Summary by CodeRabbit

  • New Features
    • Introduced a new configuration option DialDualStack for proxy settings, allowing clients to attempt connections to both IPv4 and IPv6 host addresses.
  • Documentation
    • Updated API documentation to include the DialDualStack configuration option.
  • Tests
    • Added new test functions for IPv4 and IPv6 network configurations in proxy settings.

@negrel negrel requested a review from a team as a code owner March 5, 2024 11:59
@negrel negrel requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team March 5, 2024 11:59
Copy link

welcome bot commented Mar 5, 2024

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Copy link
Contributor

coderabbitai bot commented Mar 5, 2024

Walkthrough

This update introduces a new DialDualStack configuration option across various components of the proxy middleware. This option allows clients to attempt connections using both IPv4 and IPv6, enhancing compatibility and resolving connection issues in environments where IPv4 might not be available or preferred. The changes span across documentation, configuration struct, proxy logic, and testing to ensure comprehensive support and functionality for dual-stack connectivity.

Changes

Files Change Summary
docs/api/middleware/proxy.md Added documentation for DialDualStack configuration option.
middleware/proxy/config.go Added DialDualStack field to Config struct.
middleware/proxy/proxy.go Integrated DialDualStack in client initialization within Balancer function.
middleware/proxy/proxy_test.go Added IPv4 and IPv6 specific test server creation functions.

Related issues

🎉🐰✨

A hop, a skip, in the digital field, we weave,

Through IPv4 and IPv6, we no longer grieve.

With DialDualStack, our connections are true,

From the burrows of code, to the internet's vast blue.

🌐🐾🌟

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 370cc8b and cbb4a09.
Files selected for processing (4)
  • docs/api/middleware/proxy.md (1 hunks)
  • middleware/proxy/config.go (1 hunks)
  • middleware/proxy/proxy.go (1 hunks)
  • middleware/proxy/proxy_test.go (18 hunks)
Additional comments: 7
middleware/proxy/config.go (1)
  • 54-64: The addition of the DialDualStack field to the Config struct is a significant enhancement for supporting dual-stack (IPv4 and IPv6) network environments. This change aligns with the PR's objective to improve IPv6 compatibility in proxy operations. However, it's crucial to ensure that the default value of false for DialDualStack is explicitly documented in the API documentation to inform users about the default behavior.

Additionally, the comment update on lines 54-55 is clear and informative, correctly indicating that the DialDualStack option, along with other specified fields, will not be utilized if a custom client is set. This is an important detail that helps prevent confusion about the precedence of configuration options.

middleware/proxy/proxy.go (1)
  • 48-49: The implementation of the DialDualStack option within the Balancer function is correctly applied to each fasthttp.HostClient instance. This ensures that when DialDualStack is enabled in the configuration, the proxy middleware will attempt connections to both IPv4 and IPv6 addresses, optimizing network path selection. This change is crucial for applications operating in dual-stack environments and aligns with the PR's objectives.

It's important to verify that this behavior is thoroughly tested, especially in environments where IPv6 connectivity might be inconsistent or unavailable, to ensure that the fallback to IPv4 does not introduce unexpected delays or issues.

docs/api/middleware/proxy.md (1)
  • 154-154: The documentation update to include the DialDualStack configuration option is clear and informative, providing users with guidance on enabling dual-stack connectivity for the proxy middleware. It's crucial that the documentation emphasizes the default value of false for DialDualStack and explains the potential impact of enabling this option on network path selection and application versatility in dual-stack environments.

One minor suggestion for improvement is to ensure consistency in the documentation's formatting and to check for any typographical errors or grammatical issues that might detract from the clarity of the information provided.

middleware/proxy/proxy_test.go (4)
  • 18-30: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [21-40]

The implementation of createProxyTestServer looks correct and aligns with the PR objectives. However, consider using a more reliable synchronization mechanism than time.Sleep for waiting for the server to start, if applicable. This is not a blocker but could improve test reliability in some scenarios.

  • 42-50: The introduction of createProxyTestServerIPv4 and createProxyTestServerIPv6 functions is a good approach to support both IPv4 and IPv6 in tests. These changes align well with the PR's objective to enhance IPv6 support in the proxy middleware.
  • 161-182: The test Test_Proxy_Balancer_IPv6_Upstream correctly sets up an IPv6 test server and tests proxy balancing to it. However, the assertion for fiber.StatusInternalServerError as the expected status code is unusual for a positive test case. Could you clarify if this is the intended behavior or if a different status code was expected?
  • 185-208: The introduction of Test_Proxy_Balancer_IPv6_Upstream_With_DialDualStack is a valuable addition, effectively validating the new DialDualStack feature with IPv6 upstreams. This test aligns well with the PR's objective to enhance IPv6 support and demonstrates the functionality of the DialDualStack option.

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.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 370cc8b and 9abeea9.
Files selected for processing (4)
  • docs/api/middleware/proxy.md (1 hunks)
  • middleware/proxy/config.go (1 hunks)
  • middleware/proxy/proxy.go (1 hunks)
  • middleware/proxy/proxy_test.go (18 hunks)
Files skipped from review as they are similar to previous changes (3)
  • middleware/proxy/config.go
  • middleware/proxy/proxy.go
  • middleware/proxy/proxy_test.go

docs/api/middleware/proxy.md Outdated Show resolved Hide resolved
@@ -151,6 +151,7 @@ app.Use(proxy.BalancerForward([]string{
| ReadBufferSize | `int` | Per-connection buffer size for requests' reading. This also limits the maximum header size. Increase this buffer if your clients send multi-KB RequestURIs and/or multi-KB headers (for example, BIG cookies). | (Not specified) |
| WriteBufferSize | `int` | Per-connection buffer size for responses' writing. | (Not specified) |
| TlsConfig | `*tls.Config` (or `*fasthttp.TLSConfig` in v3) | TLS config for the HTTP client. | `nil` |
| DialDualStack | `bool` | Client will attempt to connect to both ipv4 and ipv6 host addresses if set to true. | `false` |
Copy link
Contributor

@coderabbitai coderabbitai bot Mar 5, 2024

Choose a reason for hiding this comment

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

The addition of the DialDualStack configuration option is well-documented. However, it would be beneficial to include an example or more detailed explanation on how enabling this option affects proxy behavior, especially for users unfamiliar with dual-stack environments.

Consider adding a practical example or a more detailed explanation of the DialDualStack option's impact on proxy behavior to aid user understanding.

Copy link
Member

Choose a reason for hiding this comment

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

@negrel

Consider adding a practical example or a more detailed explanation of the DialDualStack option's impact on proxy behavior to aid user understanding.

is a good hint, could you do this

only a feature that is understandable and well documented will be found and used

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ReneWerner87 I've added an example. Let me know if that suits you!

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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 370cc8b and dc8bdcd.
Files selected for processing (4)
  • docs/api/middleware/proxy.md (5 hunks)
  • middleware/proxy/config.go (1 hunks)
  • middleware/proxy/proxy.go (1 hunks)
  • middleware/proxy/proxy_test.go (18 hunks)
Files skipped from review as they are similar to previous changes (3)
  • middleware/proxy/config.go
  • middleware/proxy/proxy.go
  • middleware/proxy/proxy_test.go
Additional comments: 1
docs/api/middleware/proxy.md (1)
  • 156-156: The introduction of the DialDualStack configuration option is a crucial enhancement for supporting dual-stack (IPv4 and IPv6) environments. This change aligns well with the PR objectives and modern network requirements. However, it's essential to ensure that the default value (false) is the intended behavior, as it requires explicit opt-in by the developer. This approach is sensible for backward compatibility but consider highlighting this in the documentation to ensure developers are aware they need to enable it for IPv6 support.

docs/api/middleware/proxy.md Outdated Show resolved Hide resolved
docs/api/middleware/proxy.md Show resolved Hide resolved
Comment on lines 129 to 134
c.Response().Header.Del(fiber.HeaderServer)
return nil
},
// Enable support for IPv6 upstreams.
DialDualStack: true,
}))

// Or this way if the balancer is using https and the destination server is only using http.
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [122-133]

Adding the IPv6 address in the Servers list and introducing the DialDualStack option are significant improvements for IPv6 support. However, ensure that the example provided is clear to users about when and why to use DialDualStack: true. It might be beneficial to add a brief explanation or comment in the code snippet about the specific scenarios where enabling DialDualStack is advantageous.

Consider adding a comment in the code snippet explaining the use case for DialDualStack: true to enhance clarity for developers.

@negrel negrel force-pushed the fix-proxy-ipv6-upstream branch 2 times, most recently from 472bd21 to 0700c40 Compare March 5, 2024 13:18
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 370cc8b and 472bd21.
Files selected for processing (4)
  • docs/api/middleware/proxy.md (4 hunks)
  • middleware/proxy/config.go (1 hunks)
  • middleware/proxy/proxy.go (1 hunks)
  • middleware/proxy/proxy_test.go (18 hunks)
Files skipped from review as they are similar to previous changes (3)
  • middleware/proxy/config.go
  • middleware/proxy/proxy.go
  • middleware/proxy/proxy_test.go
Additional comments: 2
docs/api/middleware/proxy.md (2)
  • 143-150: The example provided for using the DialDualStack option is clear and demonstrates how to enable IPv6 support in a round-robin balancer setup. This addition is crucial for applications that need to operate in dual-stack (IPv4 and IPv6) network environments. The example correctly shows the configuration of IPv6 and IPv4 addresses in the Servers list and the enabling of DialDualStack.
  • 165-165: The documentation for the DialDualStack configuration option is well-explained, indicating that setting this option to true enables the client to attempt connections to both IPv4 and IPv6 host addresses. This is a significant enhancement for the proxy middleware, ensuring better network path selection and application versatility in dual-stack environments.

Copy link

codecov bot commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.73%. Comparing base (fcb8537) to head (e49e928).
Report is 2 commits behind head on main.

❗ Current head e49e928 differs from pull request most recent head 3ed19af. Consider uploading reports for the commit 3ed19af to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2900      +/-   ##
==========================================
+ Coverage   82.66%   82.73%   +0.07%     
==========================================
  Files         116      116              
  Lines        8368     8369       +1     
==========================================
+ Hits         6917     6924       +7     
+ Misses       1107     1103       -4     
+ Partials      344      342       -2     
Flag Coverage Δ
unittests 82.73% <100.00%> (+0.07%) ⬆️

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.

@gaby
Copy link
Member

gaby commented Mar 10, 2024

@negrel Can you take a look at the merge conflict so we can move this forward? Thanks!

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fcb8537 and 6ad2db4.
Files selected for processing (4)
  • docs/api/middleware/proxy.md (4 hunks)
  • middleware/proxy/config.go (1 hunks)
  • middleware/proxy/proxy.go (1 hunks)
  • middleware/proxy/proxy_test.go (18 hunks)
Files skipped from review as they are similar to previous changes (3)
  • middleware/proxy/config.go
  • middleware/proxy/proxy.go
  • middleware/proxy/proxy_test.go
Additional comments: 2
docs/api/middleware/proxy.md (2)
  • 142-151: The example provided for making a round-robin balancer with IPv6 support using the DialDualStack option is clear and demonstrates the feature well. This addition should help users understand how to enable both IPv4 and IPv6 support in their proxy configurations.
  • 166-166: The addition of the DialDualStack option to the configuration section is well-documented, clearly explaining that setting this option to true enables the client to attempt connections to both IPv4 and IPv6 host addresses. The default value of false is also correctly noted.

@negrel
Copy link
Contributor Author

negrel commented Mar 10, 2024

@gaby I've fix all conflicts. Let me know if this is good for you!

@gaby
Copy link
Member

gaby commented Mar 10, 2024

@gaby I've fix all conflicts. Let me know if this is good for you!

Running CI now :-) thanks!

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6ad2db4 and e49e928.
Files selected for processing (1)
  • docs/api/middleware/proxy.md (4 hunks)
Additional comments: 3
docs/api/middleware/proxy.md (3)
  • 10-10: The documentation correctly updates the signature comment for BalancerForward to include "round-robin" hyphenated, as previously suggested. This change improves grammatical correctness and consistency in the documentation.
  • 143-152: This section introduces the DialDualStack option in a practical example, demonstrating how to enable dual-stack (IPv4 and IPv6) support for proxy connections. The example is clear and directly illustrates the use of the new feature. However, it's essential to ensure that the DialDualStack field is properly documented in the Config struct section to maintain consistency and provide complete information to the users.
  • 167-167: The documentation has been updated to include the DialDualStack option in the Config struct, specifying its purpose and default value. This addition is crucial for informing users about the new feature and how to utilize it. The description is concise and informative, aligning with the PR's objectives to enhance IPv6 support. It's recommended to ensure that all related documentation and examples are updated to reflect this new option for consistency and completeness.

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@sixcolors sixcolors left a comment

Choose a reason for hiding this comment

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

@negrel tested with vite dev server fixes: #2890. LGTM, thanks for adding this.

@sixcolors sixcolors changed the title Add DialDualStack option to proxy middleware for upstream IPv6 support feat(middleware/proxy): Add DialDualStack option for upstream IPv6 support Mar 11, 2024
@ReneWerner87 ReneWerner87 merged commit df1f877 into gofiber:main Mar 13, 2024
12 of 13 checks passed
Copy link

welcome bot commented Mar 13, 2024

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

grivera64 pushed a commit to grivera64/fiber that referenced this pull request Mar 16, 2024
…pport (gofiber#2900)

* 🔥 Add DialDualStack option to proxy middleware for upstream IPv6 support

* Update docs/api/middleware/proxy.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Jason McNeil <sixcolors@mac.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
4 participants