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

Revert "🔥 feat: Add Context Support to RequestID Middleware" #3365

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sixcolors
Copy link
Member

Reverts #3200

Reversion of Middleware Changes in Fiber v3

Following discussions in issue #3358, we have reverted changes that attempted to copy values into context.Context within various middlewares. These changes were removed to maintain Fiber’s lightweight design, improve performance, and avoid unnecessary complexity for users who do not require context.Context.

Why Were These Changes Reverted?

  • Fiber prioritizes performance, and modifying context.Context for every request introduces unnecessary overhead.
  • Values are already accessible via c.Locals(), making context modifications redundant.
  • Users who need context.Context values can implement a trivial custom middleware without affecting default behavior.

@sixcolors sixcolors requested a review from a team as a code owner March 19, 2025 15:07
@sixcolors sixcolors requested review from gaby, ReneWerner87 and efectn and removed request for a team March 19, 2025 15:07
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Walkthrough

The pull request simplifies the request ID retrieval in the Fiber middleware. The documentation now exclusively uses fiber.Ctx to obtain the request ID, and the example code in the docs has been updated accordingly. In the core implementation, the FromContext function signature has been revised to accept only fiber.Ctx, eliminating the handling of context.Context. The associated tests have been streamlined to reflect this focused approach.

Changes

Files Affected Change Summary
docs/middleware/requestid.md Removed the outdated section using c.Context() and updated the example to retrieve the request ID directly with fiber.Ctx.
middleware/requestid/requestid.go, middleware/requestid/requestid_test.go Removed the context package usage; updated FromContext to strictly accept fiber.Ctx and simplified the test case to a single direct scenario.

Sequence Diagram(s)

sequenceDiagram
    participant Handler
    participant RequestID
    Handler->>RequestID: Call FromContext(fiber.Ctx)
    RequestID-->>Handler: Return request ID (or empty string)
Loading

Possibly related PRs

Suggested labels

🧹 Updates, ☢️ Bug

Suggested reviewers

  • gaby
  • sixcolors
  • ReneWerner87
  • efectn

Poem

I'm a little rabbit, hopping through the code,
Where contexts now flow in a simplified mode.
No tangled webs of old types to unwind,
Just clear paths in Fiber, refreshed and refined.
Celebrate the change with a joyful, swift hop! 🐇🎉

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 Mar 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.67%. Comparing base (87f3f0c) to head (7fd1da8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3365      +/-   ##
==========================================
- Coverage   83.73%   83.67%   -0.07%     
==========================================
  Files         118      118              
  Lines       11728    11716      -12     
==========================================
- Hits         9821     9803      -18     
- Misses       1481     1485       +4     
- Partials      426      428       +2     
Flag Coverage Δ
unittests 83.67% <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.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 (1)
middleware/requestid/requestid_test.go (1)

54-76: Test updated to match the simplified API

The test has been appropriately updated to reflect the changes in the FromContext function. The test now directly passes a fiber.Ctx to the function instead of testing multiple input types.

Minor improvements to note:

  1. The comment on line 54 mentions Test_RequestID_Locals, but the function name at line 55 is still Test_RequestID_FromContext. Consider renaming the function to match the comment for consistency.
  2. The test is more straightforward now, focusing on the single use case which matches Fiber's intended pattern.
// go test -run Test_RequestID_Locals
-func Test_RequestID_FromContext(t *testing.T) {
+func Test_RequestID_Locals(t *testing.T) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 87f3f0c and 7fd1da8.

📒 Files selected for processing (3)
  • docs/middleware/requestid.md (0 hunks)
  • middleware/requestid/requestid.go (1 hunks)
  • middleware/requestid/requestid_test.go (1 hunks)
💤 Files with no reviewable changes (1)
  • docs/middleware/requestid.md
🧰 Additional context used
🧬 Code Definitions (1)
middleware/requestid/requestid_test.go (2)
middleware/requestid/requestid.go (2) (2)
  • New (17-42)
  • FromContext (46-51)
middleware/requestid/config.go (1) (1)
  • Config (9-24)
🔇 Additional comments (1)
middleware/requestid/requestid.go (1)

46-49: Simplified and focused implementation

The function signature has been updated to explicitly accept fiber.Ctx instead of the previous any type that handled both fiber.Ctx and context.Context. This change aligns with the PR objective of removing unnecessary context modifications and maintaining Fiber's lightweight design.

The simplified implementation improves:

  • Type safety by using a specific type rather than any
  • Performance by removing context conversion overhead
  • Maintainability by following Fiber's pattern of using c.Locals() for value storage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant