Documentation
¶
Index ¶
- Constants
- func CreateTimer(ctx context.Context, container containerd.Container, cfg *config.Config) error
- func ExecuteHealthCheck(ctx context.Context, task containerd.Task, container containerd.Container, ...) error
- func ForceRemoveTransientHealthCheckFiles(ctx context.Context, containerID string) error
- func RemoveTransientHealthCheckFiles(ctx context.Context, container containerd.Container) error
- func StartTimer(ctx context.Context, container containerd.Container, cfg *config.Config) error
- type Health
- type HealthState
- type HealthStatus
- type Healthcheck
- type HealthcheckResult
- type ResizableBuffer
Constants ¶
const ( CmdNone = "NONE" Cmd = "CMD" CmdShell = "CMD-SHELL" TestNone = "" )
Healthcheck cmd types
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
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
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
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 ¶
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