health

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package health provides health check implementations for Docker services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Poll

func Poll(ctx context.Context, timeout, interval time.Duration, fn func() error) error

Poll retries fn until it returns nil or the timeout is exceeded. Between attempts it waits for interval, respecting context cancellation.

func ScanForPattern

func ScanForPattern(r io.Reader, pattern string) (bool, error)

ScanForPattern reads lines from r looking for a line containing pattern.

Types

type Checker

type Checker interface {
	Check(ctx context.Context) error
}

Checker polls a service until it is healthy or the timeout is exceeded.

type DockerChecker

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

DockerChecker polls the Docker API for a container's built-in HEALTHCHECK status.

func NewDockerChecker

func NewDockerChecker(cli *dockerclient.Client, containerID string, timeout, interval time.Duration) *DockerChecker

NewDockerChecker creates a health checker that inspects the container's health state.

func (*DockerChecker) Check

func (c *DockerChecker) Check(ctx context.Context) error

Check polls Docker until the container reports healthy or timeout.

type HTTPChecker

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

HTTPChecker polls an HTTP endpoint until it returns a 2xx status code.

func NewHTTPChecker

func NewHTTPChecker(url string, timeout, interval time.Duration) *HTTPChecker

NewHTTPChecker creates a health checker that GETs the given URL.

func (*HTTPChecker) Check

func (c *HTTPChecker) Check(ctx context.Context) error

Check polls the HTTP endpoint until healthy or timeout.

type LogChecker

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

LogChecker watches container logs for a specific pattern string.

func NewLogChecker

func NewLogChecker(cli *dockerclient.Client, service, pattern string, timeout, interval time.Duration) *LogChecker

NewLogChecker creates a health checker that scans container stdout/stderr for pattern.

func (*LogChecker) Check

func (c *LogChecker) Check(ctx context.Context) error

type Named

type Named struct {
	Checker Checker
	Label   string
}

Named pairs a Checker with a human-readable label for terminal output.

type TCPChecker

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

TCPChecker polls a TCP endpoint until a connection can be established.

func NewTCPChecker

func NewTCPChecker(host, port string, timeout, interval time.Duration) *TCPChecker

NewTCPChecker creates a health checker that dials the given host:port.

func (*TCPChecker) Check

func (c *TCPChecker) Check(ctx context.Context) error

Check polls the TCP endpoint until connectable or timeout.

Jump to

Keyboard shortcuts

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