checks

package
v1.16.4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MPL-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinInterval is the minimal interval between
	// two checks. Do not allow for a interval below this value.
	// Otherwise we risk fork bombing a system.
	MinInterval = time.Second

	// DefaultBufSize is the maximum size of the captured
	// check output by default. Prevents an enormous buffer
	// from being captured
	DefaultBufSize = 4 * 1024 // 4KB

	// UserAgent is the value of the User-Agent header
	// for HTTP health checks.
	UserAgent = "Consul Health Check"
)
View Source
const DefaultDockerHost = "unix:///var/run/docker.sock"

Variables

View Source
var (
	ErrOSServiceStatusCritical = errors.New(errOSServiceStatusCritical)
)

Functions

func ParseHost

func ParseHost(host string) (string, string, string, error)

ParseHost verifies that the given host strings is valid. copied from github.com/docker/docker/client.go

Types

type AliasNotifier

type AliasNotifier interface {
	CheckNotifier

	AddAliasCheck(structs.CheckID, structs.ServiceID, chan<- struct{}) error
	RemoveAliasCheck(structs.CheckID, structs.ServiceID)
	Checks(*acl.EnterpriseMeta) map[structs.CheckID]*structs.HealthCheck
}

AliasNotifier is a CheckNotifier specifically for the Alias check. This requires additional methods that are satisfied by the agent local state.

type CheckAlias

type CheckAlias struct {
	Node      string            // Node name of the service. If empty, assumed to be this node.
	ServiceID structs.ServiceID // ID (not name) of the service to alias

	CheckID structs.CheckID             // ID of this check
	RPC     RPC                         // Used to query remote server if necessary
	RPCReq  structs.NodeSpecificRequest // Base request
	Notify  AliasNotifier               // For updating the check state

	acl.EnterpriseMeta
	// contains filtered or unexported fields
}

CheckAlias is a check type that aliases the health of another service instance or node. If the service aliased has any critical health checks, then this check is critical. If the service has no critical but warnings, then this check is warning, and if a service has only passing checks, then this check is passing.

func (*CheckAlias) Start

func (c *CheckAlias) Start()

Start is used to start the check, runs until Stop() func (c *CheckAlias) Start() {

func (*CheckAlias) Stop

func (c *CheckAlias) Stop()

Stop is used to stop the check.

type CheckDocker

type CheckDocker struct {
	CheckID           structs.CheckID
	ServiceID         structs.ServiceID
	Script            string
	ScriptArgs        []string
	DockerContainerID string
	Shell             string
	Interval          time.Duration
	Logger            hclog.Logger
	Client            *DockerClient
	StatusHandler     *StatusHandler
	// contains filtered or unexported fields
}

CheckDocker is used to periodically invoke a script to determine the health of an application running inside a Docker Container. We assume that the script is compatible with nagios plugins and expects the output in the same format. Supports failures_before_critical and success_before_passing.

func (*CheckDocker) Start

func (c *CheckDocker) Start()

func (*CheckDocker) Stop

func (c *CheckDocker) Stop()

type CheckGRPC

type CheckGRPC struct {
	CheckID         structs.CheckID
	ServiceID       structs.ServiceID
	GRPC            string
	Interval        time.Duration
	Timeout         time.Duration
	TLSClientConfig *tls.Config
	Logger          hclog.Logger
	StatusHandler   *StatusHandler

	// Set if checks are exposed through Connect proxies
	// If set, this is the target of check()
	ProxyGRPC string
	// contains filtered or unexported fields
}

CheckGRPC is used to periodically send request to a gRPC server application that implements gRPC health-checking protocol. The check is passing if returned status is SERVING. The check is critical if connection fails or returned status is not SERVING. Supports failures_before_critical and success_before_passing.

func (*CheckGRPC) CheckType

func (c *CheckGRPC) CheckType() structs.CheckType

func (*CheckGRPC) Start

func (c *CheckGRPC) Start()

func (*CheckGRPC) Stop

func (c *CheckGRPC) Stop()

type CheckH2PING

type CheckH2PING struct {
	CheckID         structs.CheckID
	ServiceID       structs.ServiceID
	H2PING          string
	Interval        time.Duration
	Timeout         time.Duration
	Logger          hclog.Logger
	TLSClientConfig *tls.Config
	StatusHandler   *StatusHandler
	// contains filtered or unexported fields
}

func (*CheckH2PING) Start

func (c *CheckH2PING) Start()

func (*CheckH2PING) Stop

func (c *CheckH2PING) Stop()

Stop is used to stop an H2PING check.

type CheckHTTP

type CheckHTTP struct {
	CheckID          structs.CheckID
	ServiceID        structs.ServiceID
	HTTP             string
	Header           map[string][]string
	Method           string
	Body             string
	Interval         time.Duration
	Timeout          time.Duration
	Logger           hclog.Logger
	TLSClientConfig  *tls.Config
	OutputMaxSize    int
	StatusHandler    *StatusHandler
	DisableRedirects bool

	// Set if checks are exposed through Connect proxies
	// If set, this is the target of check()
	ProxyHTTP string
	// contains filtered or unexported fields
}

CheckHTTP is used to periodically make an HTTP request to determine the health of a given check. The check is passing if the response code is 2XX. The check is warning if the response code is 429. The check is critical if the response code is anything else or if the request returns an error Supports failures_before_critical and success_before_passing.

func (*CheckHTTP) CheckType

func (c *CheckHTTP) CheckType() structs.CheckType

func (*CheckHTTP) Start

func (c *CheckHTTP) Start()

Start is used to start an HTTP check. The check runs until stop is called

func (*CheckHTTP) Stop

func (c *CheckHTTP) Stop()

Stop is used to stop an HTTP check.

type CheckIfServiceIDExists

type CheckIfServiceIDExists func(*structs.ServiceID) bool

CheckIfServiceIDExists is used to determine if a service exists

type CheckMonitor

type CheckMonitor struct {
	Notify        CheckNotifier
	CheckID       structs.CheckID
	ServiceID     structs.ServiceID
	Script        string
	ScriptArgs    []string
	Interval      time.Duration
	Timeout       time.Duration
	Logger        hclog.Logger
	OutputMaxSize int
	StatusHandler *StatusHandler
	// contains filtered or unexported fields
}

CheckMonitor is used to periodically invoke a script to determine the health of a given check. It is compatible with nagios plugins and expects the output in the same format. Supports failures_before_critical and success_before_passing.

func (*CheckMonitor) Start

func (c *CheckMonitor) Start()

Start is used to start a check monitor. Monitor runs until stop is called

func (*CheckMonitor) Stop

func (c *CheckMonitor) Stop()

Stop is used to stop a check monitor.

type CheckNotifier

type CheckNotifier interface {
	UpdateCheck(checkID structs.CheckID, status, output string)
	// ServiceExists return true if the given service does exists
	ServiceExists(serviceID structs.ServiceID) bool
}

CheckNotifier interface is used by the CheckMonitor to notify when a check has a status update. The update should take care to be idempotent.

type CheckOSService

type CheckOSService struct {
	CheckID       structs.CheckID
	ServiceID     structs.ServiceID
	OSService     string
	Interval      time.Duration
	Timeout       time.Duration
	Logger        hclog.Logger
	StatusHandler *StatusHandler
	Client        *OSServiceClient
	// contains filtered or unexported fields
}

func (*CheckOSService) CheckType

func (c *CheckOSService) CheckType() structs.CheckType

func (*CheckOSService) Start

func (c *CheckOSService) Start()

func (*CheckOSService) Stop

func (c *CheckOSService) Stop()

type CheckTCP

type CheckTCP struct {
	CheckID         structs.CheckID
	ServiceID       structs.ServiceID
	TCP             string
	Interval        time.Duration
	Timeout         time.Duration
	Logger          hclog.Logger
	TLSClientConfig *tls.Config
	StatusHandler   *StatusHandler
	// contains filtered or unexported fields
}

CheckTCP is used to periodically make a TCP connection to determine the health of a given check. The check is passing if the connection succeeds The check is critical if the connection returns an error Supports failures_before_critical and success_before_passing.

func (*CheckTCP) Start

func (c *CheckTCP) Start()

Start is used to start a TCP check. The check runs until stop is called

func (*CheckTCP) Stop

func (c *CheckTCP) Stop()

Stop is used to stop a TCP check.

type CheckTTL

type CheckTTL struct {
	Notify    CheckNotifier
	CheckID   structs.CheckID
	ServiceID structs.ServiceID
	TTL       time.Duration
	Logger    hclog.Logger

	OutputMaxSize int
	// contains filtered or unexported fields
}

CheckTTL is used to apply a TTL to check status, and enables clients to set the status of a check but upon the TTL expiring, the check status is automatically set to critical.

func (*CheckTTL) SetStatus

func (c *CheckTTL) SetStatus(status, output string) string

SetStatus is used to update the status of the check, and to renew the TTL. If expired, TTL is restarted. output is returned (might be truncated)

func (*CheckTTL) Start

func (c *CheckTTL) Start()

Start is used to start a check ttl, runs until Stop()

func (*CheckTTL) Stop

func (c *CheckTTL) Stop()

Stop is used to stop a check ttl.

type CheckUDP

type CheckUDP struct {
	CheckID       structs.CheckID
	ServiceID     structs.ServiceID
	UDP           string
	Message       string
	Interval      time.Duration
	Timeout       time.Duration
	Logger        hclog.Logger
	StatusHandler *StatusHandler
	// contains filtered or unexported fields
}

CheckUDP is used to periodically send a UDP datagram to determine the health of a given check. The check is passing if the connection succeeds, the response is bytes.Equal to the bytes passed in or if the error returned is a timeout error The check is critical if: the connection succeeds but the response is not equal to the bytes passed in, the connection succeeds but the error returned is not a timeout error or the connection fails

func (*CheckUDP) Start

func (c *CheckUDP) Start()

func (*CheckUDP) Stop

func (c *CheckUDP) Stop()

type DockerClient

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

DockerClient is a simplified client for the Docker Engine API to execute the health checks and avoid significant dependencies. It also consumes all data returned from the Docker API through a ring buffer with a fixed limit to avoid excessive resource consumption.

func NewDockerClient

func NewDockerClient(host string, maxbuf int64) (*DockerClient, error)

func (*DockerClient) Close

func (c *DockerClient) Close() error

func (*DockerClient) CreateExec

func (c *DockerClient) CreateExec(containerID string, cmd []string) (string, error)

func (*DockerClient) Host

func (c *DockerClient) Host() string

func (*DockerClient) InspectExec

func (c *DockerClient) InspectExec(containerID, execID string) (int, error)

func (*DockerClient) StartExec

func (c *DockerClient) StartExec(containerID, execID string) (*circbuf.Buffer, error)

type GrpcHealthProbe

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

GrpcHealthProbe connects to gRPC application and queries health service for application/service status.

func NewGrpcHealthProbe

func NewGrpcHealthProbe(target string, timeout time.Duration, tlsConfig *tls.Config) *GrpcHealthProbe

NewGrpcHealthProbe constructs GrpcHealthProbe from target string in format server[/service] If service is omitted, health of the entire application is probed

func (*GrpcHealthProbe) Check

func (probe *GrpcHealthProbe) Check(target string) error

Check if the target of this GrpcHealthProbe is healthy If nil is returned, target is healthy, otherwise target is not healthy

type OSServiceClient

type OSServiceClient struct {
}

func NewOSServiceClient

func NewOSServiceClient() (*OSServiceClient, error)

func (*OSServiceClient) Check

func (client *OSServiceClient) Check(serviceName string) error

type RPC

type RPC interface {
	RPC(ctx context.Context, method string, args interface{}, reply interface{}) error
}

RPC is an interface that an RPC client must implement. This is a helper interface that is implemented by the agent delegate for checks that need to make RPC calls.

type StatusHandler

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

StatusHandler keep tracks of successive error/success counts and ensures that status can be set to critical/passing only once the successive number of event reaches the given threshold.

func NewStatusHandler

func NewStatusHandler(inner CheckNotifier, logger hclog.Logger, successBeforePassing, failuresBeforeWarning, failuresBeforeCritical int) *StatusHandler

NewStatusHandler set counters values to threshold in order to immediatly update status after first check.

Jump to

Keyboard shortcuts

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