Skip to content

Conversation

@gaby
Copy link
Member

@gaby gaby commented Aug 3, 2025

Summary

  • document generic probe and explicit endpoint registration
  • clarify example usage and constant comments
  • note default endpoint helpers
  • fix healthcheck examples and update default config snippet
  • correct liveness spelling in what's new
  • rewrite the what's new Healthcheck entry for clarity

Fixes #3654

Copilot AI review requested due to automatic review settings August 3, 2025 01:30
@gaby gaby requested a review from a team as a code owner August 3, 2025 01:30
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 3, 2025

Walkthrough

Documentation for the Fiber healthcheck middleware was revised for clarity and simplicity, reflecting a new API signature that accepts variadic configuration parameters. The Config struct and default configuration handling were updated, and comments were improved. The documentation now emphasizes explicit endpoint registration and generic probe usage.

Changes

Cohort / File(s) Change Summary
Documentation Updates
docs/middleware/healthcheck.md, docs/whats_new.md
Updated to clarify usage, configuration, and API signature for the healthcheck middleware. Simplified examples, improved explanations, and corrected terminology.
Config Struct and Defaults
middleware/healthcheck/config.go
Generalized Config struct comments, added descriptive endpoint constant comments, introduced ConfigDefault, and renamed/updated default config function.
Middleware Initialization
middleware/healthcheck/healthcheck.go
Updated to use the renamed configDefault function for configuration initialization.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FiberApp
    participant HealthcheckMiddleware

    User->>FiberApp: Register healthcheck middleware on endpoint(s)
    FiberApp->>HealthcheckMiddleware: Initialize with config (variadic)
    HealthcheckMiddleware->>HealthcheckMiddleware: Use configDefault to set defaults
    User->>FiberApp: Send GET request to health endpoint
    FiberApp->>HealthcheckMiddleware: Route request
    HealthcheckMiddleware->>HealthcheckMiddleware: Run Probe function
    HealthcheckMiddleware-->>FiberApp: Respond with health status
    FiberApp-->>User: Return health check response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

🧹 Updates, v3

Suggested reviewers

  • sixcolors
  • efectn
  • ReneWerner87

Poem

A hop and a skip, docs polished anew,
Healthchecks made simple, clear for the crew.
Probes now generic, endpoints your own,
With configs that flex, defaults clearly shown.
🐇✨
Review with delight, for clarity’s grown!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2025-08-03-01-30-04

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes documentation discrepancies and improves clarity in the healthcheck middleware by standardizing function naming, updating documentation to reflect the simplified generic probe approach, and correcting spelling errors.

Key changes:

  • Standardizes configuration function naming from defaultConfig to configDefault and exposes ConfigDefault variable
  • Rewrites documentation to clarify the middleware's generic probe approach rather than describing automatic endpoint registration
  • Corrects "liveliness" to "liveness" spelling throughout documentation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
middleware/healthcheck/healthcheck.go Updates function call to use standardized configDefault naming
middleware/healthcheck/config.go Refactors configuration with exposed ConfigDefault variable and improved comments
docs/whats_new.md Simplifies and clarifies healthcheck middleware description, fixes spelling
docs/middleware/healthcheck.md Comprehensive rewrite to accurately document generic probe approach with practical examples

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on improving the documentation and internal consistency of the healthcheck middleware. The changes aim to provide a clearer understanding of how the middleware functions as a generic health probe, requiring explicit endpoint registration, and to ensure all related documentation and configuration snippets are accurate and up-to-date.

Highlights

  • Documentation Clarity: The documentation for the healthcheck middleware (docs/middleware/healthcheck.md) has been significantly rewritten to clarify its behavior. It now emphasizes that New() provides a generic probe handler, requiring explicit registration of endpoints (e.g., /livez, /readyz) using provided constants, rather than implying automatic default endpoints.
  • Simplified Examples: The examples in the healthcheck middleware documentation have been streamlined to better reflect the generic probe concept and explicit endpoint registration, making usage clearer and more concise.
  • Configuration Refinement: The Config struct's Probe field documentation has been made more concise and accurate. Additionally, the internal default configuration logic (middleware/healthcheck/config.go) has been updated to explicitly initialize the Next field and use a new ConfigDefault variable for consistency.
  • What's New Entry Update: The 'What's New' entry (docs/whats_new.md) for the healthcheck middleware has been completely rewritten to accurately describe the simplified, generic probe handler approach and the need for manual endpoint registration, correcting previous discrepancies and a spelling error ('liveliness' to 'liveness').
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gaby gaby changed the title Fix healthcheck documentation discrepancies 📒 docs: Fix Healthcheck middleware documentation Aug 3, 2025
@gaby gaby added this to v3 Aug 3, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the healthcheck middleware documentation to reflect its simplified API, improving clarity and examples. The migration guide in docs/whats_new.md could benefit from a more direct example to better assist users with the migration process.

@gaby gaby added this to the v3 milestone Aug 3, 2025
@gaby gaby moved this to In Progress in v3 Aug 3, 2025
@codecov
Copy link

codecov bot commented Aug 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.82%. Comparing base (b446888) to head (79b8129).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3657      +/-   ##
==========================================
- Coverage   91.82%   91.82%   -0.01%     
==========================================
  Files         113      113              
  Lines       11421    11419       -2     
==========================================
- Hits        10487    10485       -2     
  Misses        671      671              
  Partials      263      263              
Flag Coverage Δ
unittests 91.82% <100.00%> (-0.01%) ⬇️

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

🔭 Outside diff range comments (1)
middleware/healthcheck/healthcheck.go (1)

16-18: Treat HEAD like GET to match typical probe behaviour

Many load-balancers (e.g. AWS ALB) issue HEAD requests for health checks.
Right now a HEAD /livez will fall through and likely 404, which is unexpected.

- if c.Method() != fiber.MethodGet {
+ if c.Method() != fiber.MethodGet && c.Method() != fiber.MethodHead {
     return c.Next()
 }

The change is trivial and keeps semantics for all other verbs.

🧹 Nitpick comments (4)
middleware/healthcheck/config.go (2)

39-43: Exported ConfigDefault is mutable – consider keeping it unexported to avoid global races

ConfigDefault is a global variable that can be reassigned or mutated by any package importing healthcheck.
In concurrent programs this introduces subtle data-race possibilities (e.g. tests mutating it in parallel) and breaks the guarantee that a “default” really is immutable.

-// ConfigDefault is the default configuration.
-var ConfigDefault = Config{
+// configDefaultValue is the package-level immutable default.
+var configDefaultValue = Config{

Then inside configDefault() return a copy of configDefaultValue.

This keeps the public API intact while removing the shared-state foot-gun.


45-56: configDefault ignores Next == nil – was that intentional?

Probe gets auto-filled from the package default, but Next is left as-is even when nil.
That’s fine functionally (the zero value already means “skip nothing”), but it’s asymmetric and surprised me because the comment above Next calls out a “Default: nil”.

If you really want all fields normalised, add:

if cfg.Next == nil {
    cfg.Next = configDefaultValue.Next
}

Otherwise consider adding a note in the doc-comment explaining that Next is intentionally left untouched.

docs/middleware/healthcheck.md (1)

58-62: app.All example will still 404 on non-GET verbs

The middleware itself early-returns on any method ≠ GET, so registering it with
app.All does not magically make /healthz respond to POST/PUT… – those
requests will hit the handler, see the method check, call c.Next(), and with
no following handlers Fiber returns 404.

Readers may misinterpret this snippet; either drop it or add a clarifying note:

> ⚠️ Only `GET` (and `HEAD` if you accept the patch above) returns 200/503.
> Other verbs will pass to the next handler; if none exists Fiber responds 404.
docs/whats_new.md (1)

1110-1111: Spelling nit – “helpers” not “helpers like”

Small style tweak for readability:

-The healthcheck middleware has been simplified into a single generic probe handler. No endpoints are registered automatically. Register the middleware on each route you need—using helpers like `healthcheck.LivenessEndpoint`, `healthcheck.ReadinessEndpoint`, or `healthcheck.StartupEndpoint`—and optionally supply a `Probe` function to determine the service's health.
+The healthcheck middleware is now a single generic probe handler; it registers nothing automatically. Attach it to the routes you want—use the helper constants `healthcheck.LivenessEndpoint`, `healthcheck.ReadinessEndpoint`, and `healthcheck.StartupEndpoint`—and optionally provide a `Probe` function to decide the status.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b446888 and 79b8129.

📒 Files selected for processing (4)
  • docs/middleware/healthcheck.md (4 hunks)
  • docs/whats_new.md (2 hunks)
  • middleware/healthcheck/config.go (1 hunks)
  • middleware/healthcheck/healthcheck.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
docs/**

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

Review and update the contents of the docs folder if necessary when modifying code

Files:

  • docs/whats_new.md
  • docs/middleware/healthcheck.md
🧠 Learnings (11)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.
Learnt from: sixcolors
PR: gofiber/fiber#3446
File: docs/middleware/logger.md:44-44
Timestamp: 2025-05-13T00:19:16.407Z
Learning: In documentation files for the Fiber framework, code examples are often partial and don't repeat import statements that were shown in earlier examples, focusing instead on demonstrating specific usage patterns.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: app.go:623-636
Timestamp: 2025-05-08T08:14:37.302Z
Learning: In the gofiber/fiber framework, service startup failures should panic rather than allowing the application to continue running with degraded functionality, as this is the agreed-upon design decision.
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: docs/api/services.md:39-43
Timestamp: 2025-05-07T13:07:33.899Z
Learning: When documenting Go interface methods in the Fiber project, avoid showing method signatures with the interface type as the receiver (e.g., `func (d *Service) Method()`) since interfaces cannot be used as receivers in Go. Instead, show just the method signature without a receiver or use a placeholder implementation name.
📚 Learning: in the `test_csrf_withsession_middleware` function, calling `session.newwithstore()` without argumen...
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/csrf/csrf_test.go:164-165
Timestamp: 2024-09-25T17:08:07.693Z
Learning: In the `Test_CSRF_WithSession_Middleware` function, calling `session.NewWithStore()` without arguments is acceptable, as the default configuration is sufficient.

Applied to files:

  • middleware/healthcheck/healthcheck.go
📚 Learning: in `defaulterrorhandler(c *fiber.ctx, err error)`, since `c` is a pointer to an interface, we need t...
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/config.go:122-122
Timestamp: 2024-09-25T16:18:34.719Z
Learning: In `DefaultErrorHandler(c *fiber.Ctx, err error)`, since `c` is a pointer to an interface, we need to dereference `*c` when calling interface methods like `SendStatus`.

Applied to files:

  • middleware/healthcheck/healthcheck.go
📚 Learning: in the `middleware/adaptor/adaptor.go` file of the fiber framework, when updating context handling, ...
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.

Applied to files:

  • middleware/healthcheck/healthcheck.go
  • docs/middleware/healthcheck.md
📚 Learning: in the fiber framework, the `new` function automatically calls `startservices` when services are con...
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: services_test.go:450-464
Timestamp: 2025-05-15T12:56:45.397Z
Learning: In the Fiber framework, the `New` function automatically calls `startServices` when services are configured, so there's no need to explicitly call `startServices` after creating a new app with `New(Config{Services: ...})`.

Applied to files:

  • middleware/healthcheck/healthcheck.go
📚 Learning: the `new` function in the fiber framework automatically calls `startservices` at initialization time...
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: services_test.go:450-464
Timestamp: 2025-05-15T12:56:45.397Z
Learning: The `New` function in the Fiber framework automatically calls `startServices` at initialization time when services are configured, making explicit calls to `startServices` unnecessary in code that creates an App instance with `New()`.

Applied to files:

  • middleware/healthcheck/healthcheck.go
📚 Learning: detailed usage examples and explanations for new methods like `removeroute` and `removeroutebyname` ...
Learnt from: ckoch786
PR: gofiber/fiber#3230
File: docs/whats_new.md:944-951
Timestamp: 2024-12-15T19:56:45.935Z
Learning: Detailed usage examples and explanations for new methods like `RemoveRoute` and `RemoveRouteByName` are documented in `docs/api/app.md`, so it's unnecessary to duplicate them in `docs/whats_new.md`.

Applied to files:

  • docs/whats_new.md
📚 Learning: in the fiber framework, breaking changes are acceptable when moving from version 2 to version 3, inc...
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.

Applied to files:

  • docs/middleware/healthcheck.md
📚 Learning: in the fiber framework, `context()` is being renamed to `requestctx()`, and `usercontext()` to `cont...
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.

Applied to files:

  • docs/middleware/healthcheck.md
📚 Learning: in the gofiber/fiber framework, service startup failures should panic rather than allowing the appli...
Learnt from: mdelapenya
PR: gofiber/fiber#3434
File: app.go:623-636
Timestamp: 2025-05-08T08:14:37.302Z
Learning: In the gofiber/fiber framework, service startup failures should panic rather than allowing the application to continue running with degraded functionality, as this is the agreed-upon design decision.

Applied to files:

  • docs/middleware/healthcheck.md
📚 Learning: in the fiber framework, the `isproxytrusted()` function returns `true` when `trustproxy` is `false`,...
Learnt from: gaby
PR: gofiber/fiber#3170
File: ctx.go:1825-1826
Timestamp: 2024-10-16T14:00:50.724Z
Learning: In the Fiber framework, the `IsProxyTrusted()` function returns `true` when `TrustProxy` is `false`, maintaining compatibility with version 2 behavior.

Applied to files:

  • docs/middleware/healthcheck.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Compare
  • GitHub Check: repeated

@ReneWerner87 ReneWerner87 merged commit 67a2166 into main Aug 4, 2025
15 checks passed
@ReneWerner87 ReneWerner87 deleted the 2025-08-03-01-30-04 branch August 4, 2025 07:13
@github-project-automation github-project-automation bot moved this from In Progress to Done in v3 Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: After using Healthcheck middleware in fiber v3, all routes are unreachable

3 participants