🧹 chore: Simplify HealthCheck middleware#3380
Conversation
WalkthroughThis pull request refactors the health check middleware in the Fiber framework. It renames the constructor function from Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (3)
🔇 Additional comments (13)
✨ Finishing Touches
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:
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.
Pull Request Overview
This PR simplifies the HealthCheck middleware by replacing the existing NewHealthChecker function with a more concise New function and updates the corresponding configuration and documentation accordingly.
- The middleware function has been renamed from NewHealthChecker to New.
- The configuration type for the probe has been updated from a custom HealthChecker type to a plain function.
- Documentation examples and references have been updated to reflect these changes.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| middleware/healthcheck/healthcheck_test.go | Updated tests to use New function in place of NewHealthChecker. |
| middleware/healthcheck/healthcheck.go | Replaced NewHealthChecker with New and updated the associated default config. |
| middleware/healthcheck/config.go | Modified the Probe type from HealthChecker to a function signature and updated default configurations. |
| docs/whats_new.md | Revised documentation examples to reference the new API function New. |
| docs/middleware/healthcheck.md | Updated signature and examples to use New instead of NewHealthChecker. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3380 +/- ##
==========================================
+ Coverage 83.66% 83.73% +0.06%
==========================================
Files 118 118
Lines 11716 11716
==========================================
+ Hits 9802 9810 +8
+ Misses 1486 1480 -6
+ Partials 428 426 -2
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:
|
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
docs/middleware/healthcheck.md(5 hunks)docs/whats_new.md(1 hunks)middleware/healthcheck/config.go(2 hunks)middleware/healthcheck/healthcheck.go(1 hunks)middleware/healthcheck/healthcheck_test.go(8 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
middleware/healthcheck/config.go (3)
middleware/logger/config.go (1)
Config(12-94)app.go (1)
Config(135-411)middleware/encryptcookie/config.go (1)
Config(8-35)
🪛 GitHub Check: lint
middleware/healthcheck/config.go
[failure] 30-30:
unused-parameter: parameter 'c' seems to be unused, consider removing or renaming it as _ (revive)
🪛 GitHub Actions: golangci-lint
middleware/healthcheck/config.go
[warning] 30-30: unused-parameter: parameter 'c' seems to be unused, consider removing or renaming it as _ (revive)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: repeated
- GitHub Check: Compare
🔇 Additional comments (20)
middleware/healthcheck/healthcheck.go (1)
7-8: Function signature updated to match established conventionsThe middleware now follows common Go and Fiber naming patterns by using
Newinstead ofNewHealthChecker. This simplifies the API while maintaining identical functionality.docs/whats_new.md (4)
1567-1568: Documentation correctly reflects the new APIThe examples have been properly updated to use the new
healthcheck.New()function for the liveness endpoint.
1574-1574: Simplified readiness endpoint configurationThe readiness endpoint configuration is now more straightforward, using
healthcheck.New()without additional parameters.
1578-1582: New startup endpoint with descriptive configurationThe documentation properly introduces the new default startup endpoint with a clear example of how to configure it with a custom probe function.
1585-1585: Simplified custom liveness endpoint exampleThe custom liveness endpoint example has been updated to match the new API pattern, making it consistent with other examples.
middleware/healthcheck/healthcheck_test.go (7)
37-39: Test cases updated to use new APITest cases for default endpoints have been properly updated to use the simplified
New()function.
56-58: Default test cases consistently updatedAll default endpoint test cases have been properly updated to use the simplified
New()function.
76-95: Custom test cases adapted to new APIThe test cases for custom configurations have been properly updated to use the new API while maintaining the same test coverage and behavior verification.
126-140: Nested path test cases updated correctlyTest cases for nested path configurations have been properly migrated to the new API.
167-171: Next function test case updatedThe test case for the Next configuration option has been properly updated to use the new API.
187-189: Benchmark tests updatedBenchmark tests have been properly updated to use the new API while maintaining the same performance testing criteria.
209-211: Parallel benchmark tests updatedParallel benchmark tests have been properly updated to use the new API while maintaining the same performance testing criteria.
docs/middleware/healthcheck.md (6)
30-30: API signature updated in documentationThe function signature documentation has been updated to use the new
Newfunction name, maintaining consistency with the implementation.
48-54: Examples updated to reflect new APIAll examples for different endpoint configurations have been updated to use the new
healthcheck.New()function, providing clear guidance for users.
57-79: Custom configuration examples updatedExamples with custom configurations have been updated to use the new API, maintaining the same options and behavior explanations.
84-88: Application router examples updatedThe example showing usage with
app.Allhas been properly updated to use the new API.
111-111: Config type definition updatedThe
Probefield type has been updated from the removedHealthCheckertype to its underlying function signaturefunc(fiber.Ctx) bool, simplifying the API while maintaining the same functionality.
120-120: Default function signature improvedThe default probe function signature now explicitly names the context parameter as
c, improving code readability and consistency.middleware/healthcheck/config.go (2)
21-21: LGTM: More direct function type improves API usabilityChanging from a custom
HealthCheckertype to a function type directly is a good simplification. This makes the API more straightforward to use and aligns with Go's idiomatic approach of using function types when appropriate.
32-32: LGTM: Improved naming conventionRemoving the version suffix from the function name (
defaultConfigV3→defaultConfig) makes the code more maintainable and less confusing for new developers. This change aligns with the PR's objective of simplifying the middleware.
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 8f5b5f4 | Previous: e90fe8a | Ratio |
|---|---|---|---|
Benchmark_CORS_SubdomainMatch |
11.62 ns/op 0 B/op 0 allocs/op |
7.699 ns/op 0 B/op 0 allocs/op |
1.51 |
Benchmark_CORS_SubdomainMatch - ns/op |
11.62 ns/op |
7.699 ns/op |
1.51 |
This comment was automatically generated by workflow using github-action-benchmark.
* Simplify middleware * Rename default endpoints
Description
Changes introduced