healthprobe

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package healthprobe provides HTTP and gRPC health-check implementations that monitor the startup and liveness status of an application. It exposes endpoints to confirm whether an application has successfully initialized and is currently operational, ensuring readiness and health compliance for services relying on these checks.

The package defines both HTTP and gRPC servers, each offering startup and liveness endpoints. These endpoints enable external systems to perform health checks via HTTP requests or gRPC calls, facilitating integration with orchestration tools such as Kubernetes for robust health monitoring.

Users should note that while the HTTP server setup illustrates proper endpoint registration and resource cleanup, it has not been tested extensively. Thus, it should be utilized at your own risk. The core functionality revolves around the `Monitor` interface, which services use to report their respective health status based on custom business logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleLivenessRequest

func HandleLivenessRequest(monitor Monitor) func(http.ResponseWriter, *http.Request)

func HandleStartupRequest

func HandleStartupRequest(monitor Monitor) func(http.ResponseWriter, *http.Request)

func StartGRPC

func StartGRPC(l *component.L, lis net.Listener, monitor Monitor)

StartGRPC initializes and starts the gRPC health server. The server will listen for gRPC health check requests and can be gracefully shutdown by the Cleanup function.

Since component.L contains context, and we would like to use this context, it is redundant to pass context to this function, hence nolint:contextcheck

func StartHTTP

func StartHTTP(l *component.L, address string, monitor Monitor)

StartHTTP initializes and runs an HTTP server dedicated to handling health check requests. The server provides two endpoints: "/health/startup" and "/health/liveness", each corresponding to a specific health check type. The server uses the Monitor interface to evaluate the application's startup and liveness status.

  • The "/health/startup" endpoint checks if the application has successfully initialized and is ready to serve. It returns a 200 OK response with a status of "SERVING" if loaded, otherwise a 500 Internal Server Error with a status of "NOT_SERVING".

  • The "/health/liveness" endpoint verifies if the application is currently alive and operational. It ensures that the startup check has passed. If the application has not started yet, it responds with a 503 Service Unavailable and an error message. If alive, it returns a 200 OK with a "SERVING" status; otherwise, it sends a 500 Internal Server Error with "NOT_SERVING".

Note for the users of this function, the http server wasn't tested, so the use of this is on your own risk, have fun ;)

Types

type Monitor

type Monitor interface {
	// Alive returns a boolean indicating the application's current liveness status.
	// True signifies that the application is running and capable of performing its
	// intended operations without any critical failures. Conversely, a false value
	// indicates that the application is facing issues that impair its ability to
	// function properly.
	Alive() (liveness bool)
	// Loaded returns a boolean indicating if the application's startup phase is
	// complete. True value means that the application has successfully loaded all
	// required components and is fully operational. False return value indicates
	// that the application is still in the process of starting up or initializing,
	// suggesting that it might not yet be ready to handle full workloads or process
	// requests effectively.
	Loaded() (startup bool)
}

Monitor defines methods to assess the health state of an application. It provides the functionality needed to determine both the startup and liveness statuses, which are critical for health-checking mechanisms integrated with the application's services.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL