health

package
v0.0.0-...-d59d86f Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package health contains utilities for health checking, as well as health status information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHealthChecker

func AddHealthChecker(checker HealthChecker)

AddHealthChecker adds a health checker to the list of known HealthChecker objects. Any subsequent call to NewHealthChecker will know about this HealthChecker.

func IsExitError

func IsExitError(err error) bool

Types

type CommandRunner

type CommandRunner interface {
	RunInContainer(podFullName, uuid, containerName string, cmd []string) ([]byte, error)
}

type ExecHealthChecker

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

func (*ExecHealthChecker) CanCheck

func (e *ExecHealthChecker) CanCheck(probe *api.LivenessProbe) bool

func (*ExecHealthChecker) HealthCheck

func (e *ExecHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error)

type HTTPGetInterface

type HTTPGetInterface interface {
	Get(url string) (*http.Response, error)
}

HTTPGetInterface is an abstract interface for testability. It abstracts the interface of http.Client.Get. This is exported because some other packages may want to do direct HTTP checks.

type HTTPHealthChecker

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

HTTPHealthChecker is an implementation of HealthChecker which checks container health by sending HTTP Get requests.

func (*HTTPHealthChecker) CanCheck

func (h *HTTPHealthChecker) CanCheck(probe *api.LivenessProbe) bool

func (*HTTPHealthChecker) HealthCheck

func (h *HTTPHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error)

HealthCheck checks if the container is healthy by trying sending HTTP Get requests to the container.

type HealthChecker

type HealthChecker interface {
	HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error)
	CanCheck(probe *api.LivenessProbe) bool
}

HealthChecker defines an abstract interface for checking container health.

func NewExecHealthChecker

func NewExecHealthChecker(runner CommandRunner) HealthChecker

func NewHTTPHealthChecker

func NewHTTPHealthChecker(client *http.Client) HealthChecker

func NewHealthChecker

func NewHealthChecker() HealthChecker

NewHealthChecker creates a new HealthChecker which supports multiple types of liveness probes.

type Status

type Status int

Status represents the result of a single health-check operation.

const (
	Healthy Status = iota
	Unhealthy
	Unknown
)

Status values must be one of these constants.

func DoHTTPCheck

func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error)

DoHTTPCheck checks if a GET request to the url succeeds. If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Healthy. If the HTTP response code is unsuccessful, it returns Unhealthy. It returns Unknown and err if the HTTP communication itself fails. This is exported because some other packages may want to do direct HTTP checks.

func DoTCPCheck

func DoTCPCheck(addr string) (Status, error)

DoTCPCheck checks that a TCP socket to the address can be opened. If the socket can be opened, it returns Healthy. If the socket fails to open, it returns Unhealthy. This is exported because some other packages may want to do direct TCP checks.

func (Status) String

func (s Status) String() string

type TCPHealthChecker

type TCPHealthChecker struct{}

func (*TCPHealthChecker) CanCheck

func (t *TCPHealthChecker) CanCheck(probe *api.LivenessProbe) bool

func (*TCPHealthChecker) HealthCheck

func (t *TCPHealthChecker) HealthCheck(podFullName, podUUID string, currentState api.PodState, container api.Container) (Status, error)

Jump to

Keyboard shortcuts

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