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: Add Startup Probe to Healthcheck Middleware #3069

Merged

Conversation

kirankumar-grootan
Copy link
Contributor

Description

Added default startup probe route for fiber v3

#3068

@kirankumar-grootan kirankumar-grootan requested a review from a team as a code owner July 11, 2024 05:39
@kirankumar-grootan kirankumar-grootan requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team July 11, 2024 05:39
Copy link

welcome bot commented Jul 11, 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 Jul 11, 2024

Warning

Rate limit exceeded

@kirankumar-grootan has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 59 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 88b8d89 and 81fa78f.

Walkthrough

The recent changes introduce a new "Startup Probe" alongside the existing "Liveness" and "Readiness Probes" in the Fiber middleware. This probe helps check the startup state of HTTP applications using the /startupz endpoint. The updates encompass new constants, documentation, and tests to support this feature, as well as updates to configuration and usage examples to reflect the addition of the startup probe.

Changes

Files Change Summaries
middleware/healthcheck/config.go Added a new constant DefaultStartupEndpoint to the Config struct.
docs/middleware/healthcheck.md, docs/whats_new.md Updated documentation to include startup probes, new endpoint /startupz, and corresponding usage examples.
middleware/healthcheck/healthcheck_test.go Added new tests for the /startupz endpoint, updating existing tests to include this new probe.

Poem

In the land where fibers weave,
A startup probe now takes its leave.
To check if apps have sprung to life,
/startupz cuts through startup strife.
With liveliness and readiness in tow,
Our middleware's checks now overflow.
Hop with joy, the code's aglow! 🐇


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 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 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 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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • 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

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c579a1a and 1c63a78.

Files selected for processing (1)
  • middleware/healthcheck/config.go (1 hunks)
Additional context used
golangci-lint
middleware/healthcheck/config.go

27-27: File is not gofumpt-ed with -extra

(gofumpt)

Additional comments not posted (1)
middleware/healthcheck/config.go (1)

27-27: Addition of DefaultStartupEndpoint is consistent and appropriate.

The new constant DefaultStartupEndpoint follows the pattern of the existing constants DefaultLivenessEndpoint and DefaultReadinessEndpoint. This addition is appropriate and maintains consistency.

Tools
golangci-lint

27-27: File is not gofumpt-ed with -extra

(gofumpt)

@ReneWerner87
Copy link
Member

why did you close it? @kirankumar-grootan

@ReneWerner87
Copy link
Member

@kirankumar-grootan
i see the healthcheck mw is better in v3 https://docs.gofiber.io/next/middleware/healthcheck

can you still add the default path for the startup probe and documentation so that people don't wonder why we didn't include them

@kirankumar-grootan
Copy link
Contributor Author

kirankumar-grootan commented Jul 11, 2024

@ReneWerner87 I have added the default startup endpoint and updated docs and test accordingly.

@kirankumar-grootan kirankumar-grootan changed the title added startup default probe endpoint add startup default probe endpoint Jul 11, 2024
@kirankumar-grootan kirankumar-grootan changed the title add startup default probe endpoint add default startup probe endpoint Jul 11, 2024
@ReneWerner87
Copy link
Member

Will check it tomorrow, thx

Copy link

codecov bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.12%. Comparing base (58d07f0) to head (81fa78f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3069      +/-   ##
==========================================
+ Coverage   83.10%   83.12%   +0.02%     
==========================================
  Files         115      115              
  Lines        8321     8321              
==========================================
+ Hits         6915     6917       +2     
+ Misses       1076     1075       -1     
+ Partials      330      329       -1     
Flag Coverage Δ
unittests 83.12% <ø> (+0.02%) ⬆️

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 gaby changed the title add default startup probe endpoint ✨ feat: add startup probe to Healthcheck middleware Jul 12, 2024
@gaby
Copy link
Member

gaby commented Jul 12, 2024

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Actions performed

Full review triggered.

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: 2

Outside diff range, codebase verification and nitpick comments (11)
docs/middleware/healthcheck.md (2)

51-52: Ensure consistency in usage examples.

Ensure that the usage example for the startup probe is consistent with the liveness and readiness probes.

- // Provide a minimal config for startup check
+ // Provide a minimal config for startup probe

68-73: Ensure consistency in customization examples.

Ensure that the customization example for the startup probe is consistent with the liveness and readiness probes.

- // And it works the same for startup, just change the route
+ // And it works the same for the startup probe, just change the route
middleware/healthcheck/healthcheck_test.go (9)

39-39: Ensure consistent naming in test functions.

Ensure that the naming of the startup probe endpoint in test functions is consistent with the liveness and readiness probes.

- app.Get(DefaultStartupEndpoint, NewHealthChecker())
+ app.Get(healthcheck.DefaultStartupEndpoint, NewHealthChecker())

43-46: Ensure consistent naming in test assertions.

Ensure that the naming of the startup probe endpoint in test assertions is consistent with the liveness and readiness probes.

- shouldGiveOK(t, app, "/startupz")
- shouldGiveNotFound(t, app, "/startupz/")
+ shouldGiveOK(t, app, healthcheck.DefaultStartupEndpoint)
+ shouldGiveNotFound(t, app, healthcheck.DefaultStartupEndpoint + "/")

58-58: Ensure consistent naming in test functions.

Ensure that the naming of the startup probe endpoint in test functions is consistent with the liveness and readiness probes.

- app.Get(DefaultStartupEndpoint, NewHealthChecker())
+ app.Get(healthcheck.DefaultStartupEndpoint, NewHealthChecker())

62-65: Ensure consistent naming in test assertions.

Ensure that the naming of the startup probe endpoint in test assertions is consistent with the liveness and readiness probes.

- shouldGiveOK(t, app, "/startupz")
- shouldGiveOK(t, app, "/startupz/")
+ shouldGiveOK(t, app, healthcheck.DefaultStartupEndpoint)
+ shouldGiveOK(t, app, healthcheck.DefaultStartupEndpoint + "/")

91-95: Ensure consistent naming in custom test functions.

Ensure that the naming of the startup probe endpoint in custom test functions is consistent with the liveness and readiness probes.

- app.Get(DefaultStartupEndpoint, NewHealthChecker(Config{
+ app.Get(healthcheck.DefaultStartupEndpoint, NewHealthChecker(Config{

113-114: Ensure consistent naming in custom test assertions.

Ensure that the naming of the startup probe endpoint in custom test assertions is consistent with the liveness and readiness probes.

- shouldGiveStatus(t, app, "/startupz", fiber.StatusServiceUnavailable)
+ shouldGiveStatus(t, app, healthcheck.DefaultStartupEndpoint, fiber.StatusServiceUnavailable)

175-181: Ensure consistent naming in next test functions.

Ensure that the naming of the startup probe endpoint in next test functions is consistent with the liveness and readiness probes.

- app.Get(DefaultStartupEndpoint, checker)
- shouldGiveNotFound(t, app, "/startupz")
+ app.Get(healthcheck.DefaultStartupEndpoint, checker)
+ shouldGiveNotFound(t, app, healthcheck.DefaultStartupEndpoint)

189-189: Ensure consistent naming in benchmark test functions.

Ensure that the naming of the startup probe endpoint in benchmark test functions is consistent with the liveness and readiness probes.

- app.Get(DefaultStartupEndpoint, NewHealthChecker())
+ app.Get(healthcheck.DefaultStartupEndpoint, NewHealthChecker())

211-211: Ensure consistent naming in parallel benchmark test functions.

Ensure that the naming of the startup probe endpoint in parallel benchmark test functions is consistent with the liveness and readiness probes.

- app.Get(DefaultStartupEndpoint, NewHealthChecker())
+ app.Get(healthcheck.DefaultStartupEndpoint, NewHealthChecker())
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1c63a78 and 4d7a252.

Files selected for processing (3)
  • docs/middleware/healthcheck.md (5 hunks)
  • middleware/healthcheck/config.go (1 hunks)
  • middleware/healthcheck/healthcheck_test.go (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • middleware/healthcheck/config.go

docs/middleware/healthcheck.md Outdated Show resolved Hide resolved
docs/middleware/healthcheck.md Outdated Show resolved Hide resolved
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, codebase verification and nitpick comments (7)
middleware/healthcheck/config.go (1)

27-27: Add a comment for the new constant.

To maintain consistency and clarity, consider adding a comment for the new DefaultStartupEndpoint constant.

+ // DefaultStartupEndpoint defines the default endpoint for the startup probe.
docs/middleware/healthcheck.md (3)

7-7: Ensure consistency in the description.

The description of the probes should consistently use Oxford commas for clarity.

- Liveness, readiness and startup probes middleware for [Fiber](https://github.com/gofiber/fiber) that provides three endpoints for checking the liveness, readiness and startup state of HTTP applications.
+ Liveness, readiness, and startup probes middleware for [Fiber](https://github.com/gofiber/fiber) that provides three endpoints for checking the liveness, readiness, and startup state of HTTP applications.

19-21: Clarify the behavior of the startup probe.

The behavior description for the startup probe should differentiate it from the readiness probe.

- **Startup Probe**: Assesses if the application is ready to handle requests.
+ **Startup Probe**: Checks if the application has completed its startup sequence.

105-108: Improve the explanation of the probes.

The explanation of the probes can be made clearer by separating the descriptions for each probe type.

- The readiness probe is typically used to indicate if the application is ready to start accepting traffic (e.g., all necessary components are initialized and dependent services are available) and the startup probe typically used to indicate if the application has completed its startup sequence and is ready to proceed with initialization and readiness checks
+ The readiness probe is typically used to indicate if the application is ready to start accepting traffic (e.g., all necessary components are initialized and dependent services are available).
+ The startup probe is typically used to indicate if the application has completed its startup sequence and is ready to proceed with initialization and readiness checks.
middleware/healthcheck/healthcheck_test.go (3)

39-39: Ensure consistency in endpoint definitions.

Consider using the DefaultLivenessEndpoint and DefaultReadinessEndpoint constants for consistency.

- app.Get("/livez", NewHealthChecker())
- app.Get("/readyz", NewHealthChecker())
+ app.Get(DefaultLivenessEndpoint, NewHealthChecker())
+ app.Get(DefaultReadinessEndpoint, NewHealthChecker())

58-58: Ensure consistency in endpoint definitions.

Consider using the DefaultLivenessEndpoint and DefaultReadinessEndpoint constants for consistency.

- app.Get("/livez", NewHealthChecker())
- app.Get("/readyz", NewHealthChecker())
+ app.Get(DefaultLivenessEndpoint, NewHealthChecker())
+ app.Get(DefaultReadinessEndpoint, NewHealthChecker())

175-175: Ensure consistency in endpoint definitions.

Consider using the DefaultLivenessEndpoint and DefaultReadinessEndpoint constants for consistency.

- app.Get("/readyz", checker)
- app.Get("/livez", checker)
+ app.Get(DefaultReadinessEndpoint, checker)
+ app.Get(DefaultLivenessEndpoint, checker)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1c63a78 and 4d7a252.

Files selected for processing (3)
  • docs/middleware/healthcheck.md (5 hunks)
  • middleware/healthcheck/config.go (1 hunks)
  • middleware/healthcheck/healthcheck_test.go (6 hunks)
Additional comments not posted (6)
docs/middleware/healthcheck.md (1)

51-52: Examples update looks good!

The updated examples for the startup probe endpoint are clear and consistent with the other probes.

Also applies to: 68-69, 70-73

middleware/healthcheck/healthcheck_test.go (5)

43-43: Tests update looks good!

The tests for the startup probe endpoint are well integrated and consistent with the other probes.

Also applies to: 46-46, 49-49


62-62: Tests update looks good!

The tests for the startup probe endpoint are well integrated and consistent with the other probes.

Also applies to: 65-65, 68-68


91-95: Tests update looks good!

The custom tests for the startup probe endpoint are well integrated and consistent with the other probes.

Also applies to: 113-114


181-181: Tests update looks good!

The tests for the startup probe endpoint are well integrated and consistent with the other probes.


189-189: Benchmark tests update looks good!

The benchmark tests for the startup probe endpoint are well integrated and consistent with the other probes.

Also applies to: 211-211

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, codebase verification and nitpick comments (1)
docs/middleware/healthcheck.md (1)

7-7: Improve readability by adding a comma.

To improve readability, consider adding a comma after "readiness":

- Liveness, readiness and startup probes middleware for [Fiber](https://github.com/gofiber/fiber) that provides three endpoints for checking the liveness, readiness, and startup state of HTTP applications.
+ Liveness, readiness, and startup probes middleware for [Fiber](https://github.com/gofiber/fiber) that provides three endpoints for checking the liveness, readiness, and startup state of HTTP applications.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4d7a252 and ed5d118.

Files selected for processing (1)
  • docs/middleware/healthcheck.md (5 hunks)
Additional comments not posted (4)
docs/middleware/healthcheck.md (4)

19-21: LGTM!

The description of the startup probe is clear and aligns with its intended purpose.


51-52: LGTM!

The code example for the startup check is consistent with the existing examples for liveness and readiness checks.


68-73: LGTM!

The extended config example for the startup check is clear and consistent with the other probe examples.


105-108: LGTM!

The updated comments for the Config struct are clear and provide the necessary information about the startup probe.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ed5d118 and dfc6297.

Files selected for processing (1)
  • middleware/healthcheck/healthcheck_test.go (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • middleware/healthcheck/healthcheck_test.go

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

@gaby gaby changed the title ✨ feat: add startup probe to Healthcheck middleware ✨ feat: Add Startup Probe to Healthcheck Middleware Jul 16, 2024
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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dfc6297 and 88b8d89.

Files selected for processing (1)
  • docs/whats_new.md (3 hunks)
Additional context used
Markdownlint
docs/whats_new.md

323-323: null
Link fragments should be valid

(MD051, link-fragments)

Additional comments not posted (1)
docs/whats_new.md (1)

475-520: Review of Healthcheck Middleware Code Examples

The updated documentation and code examples clearly delineate the changes from a combined setup to individual configurations for each probe type. This provides better modularity and allows users to easily customize each probe according to their specific requirements.

The code examples are correct and align well with the described functionality. It's beneficial for users to see both the before and after configurations to understand the improvements in flexibility and customization.

docs/whats_new.md Outdated Show resolved Hide resolved
@ReneWerner87 ReneWerner87 merged commit 4f1dc49 into gofiber:main Jul 18, 2024
17 checks passed
Copy link

welcome bot commented Jul 18, 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

@ReneWerner87 ReneWerner87 added this to the v3 milestone Jul 18, 2024
@ReneWerner87 ReneWerner87 linked an issue Jul 19, 2024 that may be closed by this pull request
3 tasks
gaby pushed a commit that referenced this pull request Jul 25, 2024
* added startup default probe endpoint

* added test case

* updated docs

* updated test order

* added test case

* fixed go fmt and md lint

* fixed go fmt and md lint

* updated doc as per coderabbitai suggestions

* changed healhtcheck route register to use default const instead of string for test cases

* updated whats new with healthcheck content

* updated whats new doc with coderabbitai sugg

* updated migration guide
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.

📝 [Proposal]: Add StartupProbe support to healthcheck Middleware
5 participants