Skip to content

Commit 78f0b01

Browse files
Add docs from gofiber/fiber@4f1dc49
1 parent 984e485 commit 78f0b01

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

docs/core/middleware/healthcheck.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ id: healthcheck
44

55
# Health Check
66

7-
Liveness and readiness probes middleware for [Fiber](https://github.com/gofiber/fiber) that provides two endpoints for checking the liveness and readiness state of HTTP applications.
7+
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.
88

99
## Overview
1010

@@ -16,6 +16,10 @@ Liveness and readiness probes middleware for [Fiber](https://github.com/gofiber/
1616
- **Default Endpoint**: `/readyz`
1717
- **Behavior**: By default returns `true` immediately when the server is operational.
1818

19+
- **Startup Probe**: Checks if the application has completed its startup sequence and is ready to proceed with initialization and readiness checks.
20+
- **Default Endpoint**: `/startupz`
21+
- **Behavior**: By default returns `true` immediately when the server is operational.
22+
1923
- **HTTP Status Codes**:
2024
- `200 OK`: Returned when the checker function evaluates to `true`.
2125
- `503 Service Unavailable`: Returned when the checker function evaluates to `false`.
@@ -44,6 +48,8 @@ After you initiate your [Fiber](https://github.com/gofiber/fiber) app, you can u
4448
app.Get(healthcheck.DefaultLivenessEndpoint, healthcheck.NewHealthChecker())
4549
// Provide a minimal config for readiness check
4650
app.Get(healthcheck.DefaultReadinessEndpoint, healthcheck.NewHealthChecker())
51+
// Provide a minimal config for startup check
52+
app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.NewHealthChecker())
4753
// Provide a minimal config for check with custom endpoint
4854
app.Get("/live", healthcheck.NewHealthChecker())
4955

@@ -59,6 +65,12 @@ app.Get(healthcheck.DefaultReadinessEndpoint, healthcheck.NewHealthChecker(healt
5965
return true
6066
},
6167
}))
68+
// And it works the same for startup, just change the route
69+
app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.NewHealthChecker(healthcheck.Config{
70+
Probe: func(c fiber.Ctx) bool {
71+
return true
72+
},
73+
}))
6274
// With a custom route and custom probe
6375
app.Get("/live", healthcheck.NewHealthChecker(healthcheck.Config{
6476
Probe: func(c fiber.Ctx) bool {
@@ -90,6 +102,10 @@ type Config struct {
90102
// Function used for checking the liveness of the application. Returns true if the application
91103
// is running and false if it is not. The liveness probe is typically used to indicate if
92104
// the application is in a state where it can handle requests (e.g., the server is up and running).
105+
// The readiness probe is typically used to indicate if the application is ready to start accepting traffic (e.g., all necessary components
106+
// are initialized and dependent services are available) and the startup probe typically used to
107+
// indicate if the application has completed its startup sequence and is ready to proceed with
108+
// initialization and readiness checks
93109
//
94110
// Optional. Default: func(c fiber.Ctx) bool { return true }
95111
Probe HealthChecker

docs/core/whats_new.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Here's a quick overview of the changes in Fiber `v3`:
3333
- [Session](#session)
3434
- [Filesystem](#filesystem)
3535
- [Monitor](#monitor)
36+
- [Healthcheck](#healthcheck)
3637
- [📋 Migration guide](#-migration-guide)
3738

3839
## Drop for old Go versions
@@ -330,6 +331,25 @@ DRAFT section
330331

331332
Monitor middleware is now in Contrib package.
332333

334+
### Healthcheck
335+
336+
The Healthcheck middleware has been enhanced to support more than two routes, with default endpoints for liveliness, readiness, and startup checks. Here's a detailed breakdown of the changes and how to use the new features.
337+
338+
1. **Support for More Than Two Routes**:
339+
- The updated middleware now supports multiple routes beyond the default liveliness and readiness endpoints. This allows for more granular health checks, such as startup probes.
340+
341+
2. **Default Endpoints**:
342+
- Three default endpoints are now available:
343+
- **Liveness**: `/livez`
344+
- **Readiness**: `/readyz`
345+
- **Startup**: `/startupz`
346+
- These endpoints can be customized or replaced with user-defined routes.
347+
348+
3. **Simplified Configuration**:
349+
- The configuration for each health check endpoint has been simplified. Each endpoint can be configured separately, allowing for more flexibility and readability.
350+
351+
Refer to the [healthcheck middleware migration guide](./middleware/healthcheck.md) or the [general migration guide](#-migration-guide) to review the changes.
352+
333353
## 📋 Migration guide
334354

335355
- [🚀 App](#-app-1)
@@ -480,3 +500,48 @@ app.Use(static.New("", static.Config{
480500
MaxAge: 3600,
481501
}))
482502
```
503+
504+
### Healthcheck
505+
506+
Previously, the Healthcheck middleware was configured with a combined setup for liveliness and readiness probes:
507+
508+
```go
509+
//before
510+
app.Use(healthcheck.New(healthcheck.Config{
511+
LivenessProbe: func(c *fiber.Ctx) bool {
512+
return true
513+
},
514+
LivenessEndpoint: "/live",
515+
ReadinessProbe: func(c *fiber.Ctx) bool {
516+
return serviceA.Ready() && serviceB.Ready() && ...
517+
},
518+
ReadinessEndpoint: "/ready",
519+
}))
520+
```
521+
522+
With the new version, each health check endpoint is configured separately, allowing for more flexibility:
523+
524+
```go
525+
// after
526+
527+
// Default liveness endpoint configuration
528+
app.Get(healthcheck.DefaultLivenessEndpoint, healthcheck.NewHealthChecker(healthcheck.Config{
529+
Probe: func(c *fiber.Ctx) bool {
530+
return true
531+
},
532+
}))
533+
534+
// Default readiness endpoint configuration
535+
app.Get(healthcheck.DefaultReadinessEndpoint, healthcheck.NewHealthChecker())
536+
537+
// New default startup endpoint configuration
538+
// Default endpoint is /startupz
539+
app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.NewHealthChecker(healthcheck.Config{
540+
Probe: func(c *fiber.Ctx) bool {
541+
return serviceA.Ready() && serviceB.Ready() && ...
542+
},
543+
}))
544+
545+
// Custom liveness endpoint configuration
546+
app.Get("/live", healthcheck.NewHealthChecker())
547+
```

0 commit comments

Comments
 (0)