-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🚀 [Feature] Middleware to support Kubernetes probes #2457
Comments
Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
I understand this might not be part of the "core" middlewares, but what you are describing is a health-check endpoint, something like what Liveness and readiness fulfill two different scenarios — they shouldn't be mixed up, and their implementation is not as simple as one endpoint for both returning an While this ticket is oriented towards a particular technology, the concepts are general enough to be used in almost any containerized environment. |
Agreeing with @x80486. Let's reopen this. |
@x80486 what do you think of a new readyness middleware which can be configured as follows: type Config struct {
// IsLive returns true when the application is running, false otherwise.
IsLive func(c fiber.Ctx) bool
// IsReady returns true when the application is running and ready to serve requests, false otherwise.
IsReady func(c fiber.Ctx) bool
} Exemplary instance: // Init fiber and other services
app := fiber.New()
db := database.New(database.Config{ … })
fs := filesystem.New(filesystem.Config{ … })
app.Use(readiness.New(readiness.Config{
IsLive: func(c fiber.Ctx) bool { return true },
IsReady: func(c fiber.Ctx) bool {
return db.Ready() && fs.Ready() && …
},
})) |
how would this middleware look like ? don't see this middleware currently in the core, if so then maybe in the contribution packet, but i don't see a big added value there currently, because the checks inside will take up most of the code. all the middleware could do is to register this code which is injected from outside on a certain route
by the way, i am aware of the difference between readiness and liveness probe and the above example was just to show how you can easily accomplish such a thing with the board tools |
by the way this middleware only provides a health check code which i could provide with 3 lines in the example above |
Would adding a |
Moreover, I understand @ReneWerner87's concern and probably this wouldn't fit in the main set, but on the contributions one. At the same time, @leonklingele wrote something that's more or less what users will be looking for. Basically, the implementation for liveness could be provided out of the box — and it shouldn't need to be changed because it's straightforward. The difficult one would be readiness because it involves more "moving parts" that only the application in question should be able to implement correctly. Nevertheless, again, what @leonklingele wrote provides a guidance/framework everyone can look at and customize, while having a default implementation. |
Instead of making it a middleware, we could as well introduce those two new fields in the package fiber
type Config struct {
// …
// IsLive should return true when the application is running, false otherwise.
IsLive func(c fiber.Ctx) bool
IsLiveEndpoint string // Defaults to /livez
// IsReady should return true when the application is running and ready to serve requests, false otherwise.
IsReady func(c fiber.Ctx) bool
IsReadyEndpoint string // Defaults to /readyz
// …
} ( Not really required to have it in the fiber stdlib, but definitely a nice-to-have as quite commonly used when working with Kubernetes, Docker or Docker Compose. EDIT: Having this, we could also easily add support for systemd's |
Is someone working on this or was it already implemented? I would like to take a stab |
Feature Description
Applications deployed on
Kubernetes
should provide information about their internal state with Container Probes.Fiber
could make use of a middleware to automatically manage the application availability state, so when deploying inKubernetes
(or any other environment) there is a built-in option for gathering the "liveness" and "readiness" information.This could be as simple as implementing the aforementioned probes, but it can plug as well in the application's lifecycle; for instance, refusing traffic automatically when starting. etc. — but that could be phased out, if relevant, into another unit of work.
Additional Context (optional)
No response
Code Snippet (optional)
No response
Checklist:
The text was updated successfully, but these errors were encountered: