grpchealth

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package grpchealth provides a health check aggregator for connectrpc.com/grpchealth.

It aggregates multiple health checkers and updates a gRPC health endpoint based on their combined status. All registered checkers are probed in parallel at configurable intervals, and the aggregate status is set to serving only if all checks pass.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

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

Aggregator probes registered health checkers and updates gRPC health status.

func NewAggregator

func NewAggregator(ctx context.Context, cfg Config) *Aggregator

NewAggregator creates and starts a new health aggregator. The aggregator starts in NotServing state until the first check cycle completes. The context controls the lifecycle of the background health check goroutine. A shutdown handler is automatically registered with the shutdown package.

func (*Aggregator) Handler

func (a *Aggregator) Handler(opts ...connect.HandlerOption) (string, http.Handler)

Handler returns the HTTP handler for the gRPC health endpoint. Mount on your HTTP mux: mux.Handle(aggregator.Handler())

func (*Aggregator) IsServing

func (a *Aggregator) IsServing() bool

IsServing returns the current aggregate health status (thread-safe).

func (*Aggregator) Register

func (a *Aggregator) Register(name string, checker HealthChecker) *Aggregator

Register adds a health checker with the given name. Returns the Aggregator for method chaining. Panics if name is empty or already registered.

type Config

type Config struct {
	// Interval between health check cycles.
	Interval time.Duration `koanf:"interval"`

	// Timeout for each individual health check.
	Timeout time.Duration `koanf:"timeout"`
}

Config holds configuration for the health aggregator.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible default values.

type HealthChecker

type HealthChecker interface {
	// Check returns true if the service is ready.
	// The context contains the configured timeout.
	Check(ctx context.Context) bool
}

HealthChecker checks the readiness of a service.

type HealthCheckerFunc

type HealthCheckerFunc func(ctx context.Context) bool

HealthCheckerFunc allows simple functions to be used as HealthChecker.

func (HealthCheckerFunc) Check

func (f HealthCheckerFunc) Check(ctx context.Context) bool

Check implements HealthChecker.

Jump to

Keyboard shortcuts

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