-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
📒 docs: Fix Healthcheck middleware documentation #3657
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
Conversation
WalkthroughDocumentation for the Fiber healthcheck middleware was revised for clarity and simplicity, reflecting a new API signature that accepts variadic configuration parameters. The Changes
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
defaultConfigtoconfigDefaultand exposesConfigDefaultvariable - 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 |
There was a problem hiding this 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
healthcheckmiddleware (docs/middleware/healthcheck.md) has been significantly rewritten to clarify its behavior. It now emphasizes thatNew()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
healthcheckmiddleware documentation have been streamlined to better reflect the generic probe concept and explicit endpoint registration, making usage clearer and more concise. - Configuration Refinement: The
Configstruct'sProbefield documentation has been made more concise and accurate. Additionally, the internal default configuration logic (middleware/healthcheck/config.go) has been updated to explicitly initialize theNextfield and use a newConfigDefaultvariable 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
-
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. ↩
There was a problem hiding this 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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this 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: TreatHEADlikeGETto match typical probe behaviourMany load-balancers (e.g. AWS ALB) issue
HEADrequests for health checks.
Right now aHEAD /livezwill 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: ExportedConfigDefaultis mutable – consider keeping it unexported to avoid global races
ConfigDefaultis a global variable that can be reassigned or mutated by any package importinghealthcheck.
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 ofconfigDefaultValue.This keeps the public API intact while removing the shared-state foot-gun.
45-56:configDefaultignoresNext == nil– was that intentional?
Probegets auto-filled from the package default, butNextis left as-is even whennil.
That’s fine functionally (the zero value already means “skip nothing”), but it’s asymmetric and surprised me because the comment aboveNextcalls 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
Nextis intentionally left untouched.docs/middleware/healthcheck.md (1)
58-62:app.Allexample will still 404 on non-GET verbsThe middleware itself early-returns on any method ≠
GET, so registering it with
app.Alldoes not magically make/healthzrespond to POST/PUT… – those
requests will hit the handler, see the method check, callc.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
📒 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
docsfolder if necessary when modifying code
Files:
docs/whats_new.mddocs/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.godocs/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
Summary
Fixes #3654