healthcheck

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 7 Imported by: 0

README

Health Checks

Health checks track whether a running workload is healthy without changing the instance lifecycle state.

An instance can be Running and unhealthy at the same time. Initializing still means Hypeman is bringing up the guest and waiting for the existing boot readiness signals. Health checks can run during Initializing, but the public status remains starting until the instance reaches Running.

Check Types

none disables health checks. This is the default.

http sends a GET request to the instance network address on the configured port and path. The check succeeds when the response status equals expected_status, which defaults to 200.

tcp opens a TCP connection to the instance network address and configured port. The check succeeds when the connection opens.

exec runs a command inside the guest after the guest agent is ready. Exit code 0 is healthy. A nonzero exit code, timeout, missing command, or launch error is unhealthy.

Timing

Each enabled health check has:

  • interval: how often to run the check after the previous attempt
  • timeout: the maximum time one check may run
  • start_period: startup grace period before failures can mark the workload unhealthy
  • failure_threshold: consecutive failures required to mark unhealthy
  • success_threshold: consecutive successes required to mark healthy

The defaults are:

interval: 10s
timeout: 2s
start_period: 30s
failure_threshold: 3
success_threshold: 1

Failures during start_period are recorded, but the status remains starting. A success during start_period can mark the workload healthy.

Once healthy, isolated failures do not immediately flip the status. The workload becomes unhealthy only after failure_threshold consecutive failures.

Status

Instance responses include health_check and health_status.

disabled means no check is configured.

unknown means a check is configured but the instance is not currently active.

starting means the instance is initializing, or Hypeman has not yet observed enough successful or failed checks to declare the workload healthy or unhealthy.

healthy means the configured check has reached its success threshold.

unhealthy means the configured check has reached its failure threshold outside the start period.

Health status includes the last check time, last success time, last failure time, consecutive success and failure counts, and a truncated last error.

Lifecycle

Health checks do not affect lifecycle state.

Startup remains:

Initializing -> Running

With health checks enabled, the health dimension evolves separately:

unknown -> starting -> healthy
unknown -> starting -> unhealthy

Stopping, deleting, standing by, or restoring an instance stops active checks. Starting or restoring an instance begins a fresh health window.

Restart Policy

Health checks do not restart instances by themselves.

When an instance also has restart_policy.policy=on_failure or restart_policy.policy=always, an unhealthy health status becomes a restart-policy failure signal. The restart policy applies its normal backoff, max attempts, manual-stop suppression, and stable-window reset before Hypeman restarts the whole instance.

With restart_policy.policy=never or no restart policy, health checks only report status.

Health checks still do not mutate lifecycle state directly. The instance remains Running while unhealthy until restart policy chooses to stop and start it.

Documentation

Index

Constants

View Source
const (
	StateInitializing = "Initializing"
	StateRunning      = "Running"
)

Variables

This section is empty.

Functions

func DurationConfig

func DurationConfig(policy *Policy) (interval, timeout, startPeriod time.Duration, err error)

func Enabled

func Enabled(policy *Policy) bool

Types

type DefaultProbeRunner

type DefaultProbeRunner struct {
	HTTPClient *http.Client
	ExecRunner ExecRunner
}

func (DefaultProbeRunner) Check

func (r DefaultProbeRunner) Check(ctx context.Context, inst Instance, policy *Policy) ProbeResult

type ExecCheck

type ExecCheck struct {
	Command    []string `json:"command,omitempty"`
	WorkingDir string   `json:"working_dir,omitempty"`
}

type ExecRunner

type ExecRunner interface {
	Run(ctx context.Context, inst Instance, check ExecCheck, timeout time.Duration) error
}

type HTTPCheck

type HTTPCheck struct {
	Port           uint16 `json:"port"`
	Path           string `json:"path,omitempty"`
	Scheme         string `json:"scheme,omitempty"`
	ExpectedStatus int    `json:"expected_status,omitempty"`
}

type Instance

type Instance struct {
	ID              string
	Name            string
	State           string
	NetworkEnabled  bool
	IP              string
	StartedAt       *time.Time
	GuestAgentReady bool
	SkipGuestAgent  bool
	HealthCheck     *Policy
	Runtime         *Runtime
}

type Policy

type Policy struct {
	Type             Type       `json:"type,omitempty"`
	Interval         string     `json:"interval,omitempty"`
	Timeout          string     `json:"timeout,omitempty"`
	StartPeriod      string     `json:"start_period,omitempty"`
	FailureThreshold int        `json:"failure_threshold,omitempty"`
	SuccessThreshold int        `json:"success_threshold,omitempty"`
	HTTP             *HTTPCheck `json:"http,omitempty"`
	TCP              *TCPCheck  `json:"tcp,omitempty"`
	Exec             *ExecCheck `json:"exec,omitempty"`
}

func ClonePolicy

func ClonePolicy(policy *Policy) *Policy

func NormalizePolicy

func NormalizePolicy(policy *Policy) (*Policy, error)

type ProbeResult

type ProbeResult struct {
	Success bool
	Error   string
}

type ProbeRunner

type ProbeRunner interface {
	Check(ctx context.Context, inst Instance, policy *Policy) ProbeResult
}

type Runtime

type Runtime struct {
	Status               Status     `json:"status,omitempty"`
	StartedAt            *time.Time `json:"started_at,omitempty"`
	ConsecutiveSuccesses int        `json:"consecutive_successes,omitempty"`
	ConsecutiveFailures  int        `json:"consecutive_failures,omitempty"`
	LastCheckedAt        *time.Time `json:"last_checked_at,omitempty"`
	LastSuccessAt        *time.Time `json:"last_success_at,omitempty"`
	LastFailureAt        *time.Time `json:"last_failure_at,omitempty"`
	LastError            string     `json:"last_error,omitempty"`
}

func ApplyProbeResult

func ApplyProbeResult(policy *Policy, inst Instance, previous *Runtime, now time.Time, result ProbeResult) *Runtime

func CloneRuntime

func CloneRuntime(runtime *Runtime) *Runtime

type Status

type Status string
const (
	StatusDisabled  Status = "disabled"
	StatusStarting  Status = "starting"
	StatusHealthy   Status = "healthy"
	StatusUnhealthy Status = "unhealthy"
	StatusUnknown   Status = "unknown"
)

type StatusSnapshot

type StatusSnapshot struct {
	Status               Status
	ConsecutiveSuccesses int
	ConsecutiveFailures  int
	LastCheckedAt        *time.Time
	LastSuccessAt        *time.Time
	LastFailureAt        *time.Time
	LastError            string
}

func Snapshot

func Snapshot(policy *Policy, state string, runtime *Runtime) StatusSnapshot

type TCPCheck

type TCPCheck struct {
	Port uint16 `json:"port"`
}

type Type

type Type string
const (
	TypeNone Type = "none"
	TypeHTTP Type = "http"
	TypeTCP  Type = "tcp"
	TypeExec Type = "exec"
)

Jump to

Keyboard shortcuts

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