httpprobe

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package httpprobe exposes probes over HTTP with sensible defaults for Kubernetes liveness/readiness/startup checks, but generic enough for any service. It supports two modes:

  • Pull: Handler runs the probe synchronously per request (default).
  • Cached: CachedHandler reads a state.State updated by a runner.Runner out-of-band — required for expensive checks, gRPC parity, or when many concurrent requests would otherwise stampede the probe.

Index

Constants

View Source
const (
	DefaultLivenessPath  = "/healthz/liveness"
	DefaultReadinessPath = "/healthz/readiness"
	DefaultStartupPath   = "/healthz/startup"
)

Conventional Kubernetes paths.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout caps each probe check served via Handler.

Variables

This section is empty.

Functions

func CachedHandler

func CachedHandler(s *state.State, opts ...Option) http.HandlerFunc

CachedHandler returns an http.HandlerFunc that reads from a state.State without invoking any probe. Pair with a runner.Runner that periodically updates the state. Response codes match the pull-mode Handler.

Status is read instantly — no timeout applies. If the state has never been updated (StatusUnknown), the response is 503.

func Handler

func Handler(p probe.Probe, opts ...Option) http.HandlerFunc

Handler returns an http.HandlerFunc that runs the probe and renders the result. Status -> HTTP code: Up=200, Timeout=504, others=503.

func Mux

func Mux(probes ...*HTTPProbe) *http.ServeMux

Mux mounts each HTTPProbe on a fresh http.ServeMux.

func WaitProbe

func WaitProbe(ctx context.Context, p probe.Probe, timeout time.Duration) probe.Status

WaitProbe runs probe.Check under a derived context with the given timeout. On deadline expiry, StatusTimeout is returned; the probe goroutine may outlive the call but will not block the caller.

Types

type HTTPProbe

type HTTPProbe struct {
	http.Handler
	// contains filtered or unexported fields
}

HTTPProbe binds a Handler to a path and method.

func Liveness

func Liveness(p probe.Probe, opts ...Option) *HTTPProbe

Liveness builds an HTTPProbe at DefaultLivenessPath named "liveness".

func NewHTTPProbe

func NewHTTPProbe(path string, h http.Handler) *HTTPProbe

NewHTTPProbe constructs an HTTPProbe served under method GET at path.

func Readiness

func Readiness(p probe.Probe, opts ...Option) *HTTPProbe

Readiness builds an HTTPProbe at DefaultReadinessPath named "readiness".

func Startup

func Startup(p probe.Probe, opts ...Option) *HTTPProbe

Startup builds an HTTPProbe at DefaultStartupPath named "startup".

func (*HTTPProbe) Method

func (p *HTTPProbe) Method() string

func (*HTTPProbe) Path

func (p *HTTPProbe) Path() string

type Option

type Option func(*handlerOpts)

Option configures Handler behavior.

func AsJSON

func AsJSON() Option

AsJSON switches the response body to JSON {name,status}.

func WithName

func WithName(name string) Option

WithName tags the handler with a name surfaced in responses.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout overrides the per-request probe deadline. Non-positive values are ignored.

Jump to

Keyboard shortcuts

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