Help us shape the future of Go! Take the 2026 Go Developer Survey

health

package
v1.149.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package health provides readiness state tracking and HTTP health check handlers.

Index

Constants

View Source
const (
	// DefaultPoolWait is how long one probe waits for a connection. It is
	// under the one second a readiness probe is given by default.
	DefaultPoolWait = 500 * time.Millisecond
	// DefaultPoolStarvedFor is how long the pool must go without handing one
	// out before the replica reports not ready, so a busy pool that frees a
	// connection now and then is not taken out of service.
	DefaultPoolStarvedFor = 30 * time.Second
)

Pool starvation (#2169). A replica whose database pool hands out no connection serves nothing that reads the database, yet the process state alone kept /readyz at 200 while one did. A pool every connection of which is in use, and stays so, takes the replica out of service. A database that is down is not this: its pool opens no connections, and /readyz leaves an upstream outage to the dependency probes so it never takes every replica out at once.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker tracks the readiness state of the platform. It is safe for concurrent use.

func NewChecker

func NewChecker() *Checker

NewChecker creates a Checker in the Starting state.

func (*Checker) IsReady

func (c *Checker) IsReady() bool

IsReady returns true when the state is Ready.

func (*Checker) LivenessHandler

func (*Checker) LivenessHandler() http.HandlerFunc

LivenessHandler returns an http.HandlerFunc that always responds 200 OK. Use this for K8s livenessProbe (/healthz).

func (*Checker) ReadinessHandler

func (c *Checker) ReadinessHandler() http.HandlerFunc

ReadinessHandler returns an http.HandlerFunc that responds 200 when ready and 503 when starting, draining, or its database pool is starved. Use this for K8s readinessProbe (/readyz).

func (*Checker) SetDraining

func (c *Checker) SetDraining()

SetDraining transitions to the Draining state.

func (*Checker) SetReady

func (c *Checker) SetReady()

SetReady transitions to the Ready state.

func (*Checker) State

func (c *Checker) State() string

State returns the current state as a human-readable string.

func (*Checker) WatchPool added in v1.149.0

func (c *Checker) WatchPool(p *PoolProbe)

WatchPool makes a starved database pool take the replica out of service while the process is otherwise ready (#2169).

type PoolProbe added in v1.149.0

type PoolProbe struct {
	// contains filtered or unexported fields
}

PoolProbe reports whether a database pool can hand out a connection.

func NewPoolProbe added in v1.149.0

func NewPoolProbe(db *sql.DB, wait, starvedFor time.Duration) *PoolProbe

NewPoolProbe probes db, waiting wait for a connection and reporting it starved once it has handed none out for starvedFor.

func (*PoolProbe) Starved added in v1.149.0

func (p *PoolProbe) Starved(ctx context.Context) bool

Starved reports whether every connection of the pool has been in use, with none handed out on request, for at least starvedFor.

Jump to

Keyboard shortcuts

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