healthcheck

package
v2.2.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdNone  = "NONE"
	Cmd      = "CMD"
	CmdShell = "CMD-SHELL"
	TestNone = ""
)

Healthcheck cmd types

View Source
const (
	DefaultProbeInterval   = 30 * time.Second // Default interval between probe runs. Also applies before the first probe.
	DefaultProbeTimeout    = 30 * time.Second // Max duration a single probe run may take before it's considered failed.
	DefaultStartPeriod     = 0 * time.Second  // Grace period for container startup before health checks count as failures.
	DefaultProbeRetries    = 3                // Number of consecutive failures before marking container as unhealthy.
	MaxLogEntries          = 5                // Maximum number of health check log entries to keep.
	MaxOutputLenForInspect = 4096             // Max output length (in bytes) stored in health check logs during inspect. Longer outputs are truncated.
	MaxOutputLen           = 1 * 1024 * 1024  // Max output size for health check logs: 1MB limit (prevents excessive memory usage)
	HealthLogFilename      = "health.json"    // HealthLogFilename is the name of the file used to persist health check status for a container.
)

Variables

This section is empty.

Functions

func CreateTimer added in v2.1.5

func CreateTimer(ctx context.Context, container containerd.Container, cfg *config.Config) error

CreateTimer sets up the transient systemd timer and service for healthchecks.

func ExecuteHealthCheck

func ExecuteHealthCheck(ctx context.Context, task containerd.Task, container containerd.Container, hc *Healthcheck) error

ExecuteHealthCheck executes the health check command for a container

func ForceRemoveTransientHealthCheckFiles added in v2.1.5

func ForceRemoveTransientHealthCheckFiles(ctx context.Context, containerID string) error

ForceRemoveTransientHealthCheckFiles forcefully stops and cleans up the transient timer and service using just the container ID. This function is non-blocking and uses timeouts to prevent hanging on systemd operations. It logs errors as warnings but continues cleanup attempts.

func RemoveTransientHealthCheckFiles added in v2.1.5

func RemoveTransientHealthCheckFiles(ctx context.Context, container containerd.Container) error

RemoveTransientHealthCheckFiles stops and cleans up the transient timer and service.

func StartTimer added in v2.1.5

func StartTimer(ctx context.Context, container containerd.Container, cfg *config.Config) error

StartTimer starts the healthcheck timer unit.

Types

type Health

type Health struct {
	Status        HealthStatus         // Status is one of [Starting], [Healthy] or [Unhealthy].
	FailingStreak int                  // FailingStreak is the number of consecutive failures
	Log           []*HealthcheckResult // Log contains the last few results (oldest first)
}

NOTE: Health, HealthcheckResult and Healthcheck types are kept Docker-compatible. See: https://github.com/moby/moby/blob/9d1b069a4bfdcee368e67767978eff596b696d4c/api/types/container/health.go Health stores information about the container's healthcheck results

func ReadHealthStatusForInspect

func ReadHealthStatusForInspect(stateDir, healthState string) (*Health, error)

ReadHealthStatusForInspect reads the health state from labels and the last MaxLogEntries health check result logs.

type HealthState

type HealthState struct {
	Status        HealthStatus // Status is one of [Starting], [Healthy] or [Unhealthy]
	FailingStreak int          // FailingStreak is the number of consecutive failures
	InStartPeriod bool         // InStartPeriod indicates if we're in the start period workflow
}

HealthState stores the current health state of a container

func HealthStateFromJSON

func HealthStateFromJSON(s string) (*HealthState, error)

HealthStateFromJSON deserializes a JSON string into a HealthState

func (*HealthState) ToJSONString

func (hs *HealthState) ToJSONString() (string, error)

ToJSONString serializes HealthState to a JSON string for label storage

type HealthStatus

type HealthStatus = string
const (
	NoHealthcheck HealthStatus = "none" // Indicates there is no healthcheck
	Starting      HealthStatus = "starting"
	Healthy       HealthStatus = "healthy"
	Unhealthy     HealthStatus = "unhealthy"
)

Health states

type Healthcheck

type Healthcheck struct {
	Test        []string      `json:"Test,omitempty"`        // Test is the check to perform that the container is healthy
	Interval    time.Duration `json:"Interval,omitempty"`    // Interval is the time to wait between checks
	Timeout     time.Duration `json:"Timeout,omitempty"`     // Timeout is the time to wait before considering the check to have hung
	Retries     int           `json:"Retries,omitempty"`     // Retries is the number of consecutive failures needed to consider a container as unhealthy
	StartPeriod time.Duration `json:"StartPeriod,omitempty"` // StartPeriod is the period for the container to initialize before the health check starts
}

Healthcheck represents the health check configuration

func HealthCheckFromJSON

func HealthCheckFromJSON(s string) (*Healthcheck, error)

HealthCheckFromJSON deserializes a JSON string into a Healthcheck struct

func (*Healthcheck) ApplyDefaults

func (hc *Healthcheck) ApplyDefaults()

ApplyDefaults sets default values for unset healthcheck fields

func (*Healthcheck) ToJSONString

func (hc *Healthcheck) ToJSONString() (string, error)

ToJSONString serializes a Healthcheck struct to a JSON string

type HealthcheckResult

type HealthcheckResult struct {
	Start    time.Time // Start is the time this check started
	End      time.Time // End is the time this check ended
	ExitCode int       // ExitCode meanings: 0=healthy, 1=unhealthy, 2=reserved (considered unhealthy), else=error running probe
	Output   string    // Output from last check
}

HealthcheckResult stores information about a single run of a healthcheck probe

func HealthcheckResultFromJSON

func HealthcheckResultFromJSON(s string) (*HealthcheckResult, error)

HealthcheckResultFromJSON deserializes a JSON string into a HealthcheckResult struct

func (*HealthcheckResult) ToJSONString

func (r *HealthcheckResult) ToJSONString() (string, error)

ToJSONString serializes a HealthcheckResult struct to a JSON string

type ResizableBuffer

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

ResizableBuffer collects output with a configurable upper limit.

func NewResizableBuffer

func NewResizableBuffer(maxSize int) *ResizableBuffer

NewResizableBuffer returns a new buffer with the given size limit in bytes.

func (*ResizableBuffer) String

func (b *ResizableBuffer) String() string

func (*ResizableBuffer) Write

func (b *ResizableBuffer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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