checker

package
v0.0.0-...-537599a Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinInterval is the minimal interval between
	// two checks. Do not allow for an 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 = "Orbit Health Checker"
)
View Source
const (
	// HealthAny is special, and is used as a wild card,
	// not as a specific state.
	HealthAny      = "any"
	HealthPassing  = "passing"
	HealthWarning  = "warning"
	HealthCritical = "critical"
	HealthMaint    = "maintenance"
)

Variables

This section is empty.

Functions

func RandomStagger

func RandomStagger(interval time.Duration) time.Duration

RandomStagger returns an interval between 0 and the duration

Types

type Buffer

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

Buffer implements a circular buffer. It is a fixed size, and new writes overwrite older data, such that for a buffer of size N, for any amount of writes, only the last N bytes are retained.

func NewBuffer

func NewBuffer(size int64) (*Buffer, error)

NewBuffer creates a new buffer of a given size. The size must be greater than 0.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes provides a slice of the bytes written. This slice should not be written to.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the buffer so it has no content.

func (*Buffer) Size

func (b *Buffer) Size() int64

Size returns the size of the buffer

func (*Buffer) String

func (b *Buffer) String() string

String returns the contents of the buffer as a string

func (*Buffer) TotalWritten

func (b *Buffer) TotalWritten() int64

TotalWritten provides the total number of bytes written

func (*Buffer) Write

func (b *Buffer) Write(buf []byte) (int, error)

Write writes up to len(buf) bytes to the internal ring, overriding older data if necessary.

type CheckHTTP

type CheckHTTP struct {
	HTTP             string
	Header           map[string][]string
	Method           string
	Body             string
	Interval         time.Duration
	Timeout          time.Duration
	Logger           *zap.SugaredLogger
	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
}

func (*CheckHTTP) CheckType

func (c *CheckHTTP) CheckType() 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 CheckNotifier

type CheckNotifier interface {
	UpdateCheck(status, output string)
}

type CheckTCP

type CheckTCP struct {
	ServiceID       string
	TCP             string
	Interval        time.Duration
	Timeout         time.Duration
	Logger          *zap.SugaredLogger
	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 CheckType

type CheckType struct {
	Name   string
	Notes  string
	Status string

	ScriptArgs             []string
	HTTP                   string
	H2PING                 string
	H2PingUseTLS           bool
	Header                 map[string][]string
	Method                 string
	Body                   string
	DisableRedirects       bool
	TCP                    string
	TCPUseTLS              bool
	UDP                    string
	Interval               time.Duration
	AliasNode              string
	AliasService           string
	DockerContainerID      string
	Shell                  string
	GRPC                   string
	GRPCUseTLS             bool
	OSService              string
	TLSServerName          string
	TLSSkipVerify          bool
	Timeout                time.Duration
	TTL                    time.Duration
	SuccessBeforePassing   int
	FailuresBeforeWarning  int
	FailuresBeforeCritical int

	// Definition fields used when exposing checks through a proxy
	ProxyHTTP string
	ProxyGRPC string

	// DeregisterCriticalServiceAfter, if >0, will cause the associated
	// service, if any, to be deregistered if this check is critical for
	// longer than this duration.
	DeregisterCriticalServiceAfter time.Duration
	OutputMaxSize                  int
}

type CheckUDP

type CheckUDP struct {
	ServiceID     string
	UDP           string
	Message       string
	Interval      time.Duration
	Timeout       time.Duration
	Logger        *zap.SugaredLogger
	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 HealthCheck

type HealthCheck struct {
	Node        string
	CheckID     string
	Name        string
	Notes       string
	Status      string
	Output      string
	ServiceID   string
	ServiceName string
	ServiceTags []string
	Type        string
	Namespace   string `json:",omitempty"`
	Partition   string `json:",omitempty"`
	ExposedPort int
	PeerName    string `json:",omitempty"`

	Definition HealthCheckDefinition

	CreateIndex uint64
	ModifyIndex uint64
}

HealthCheck is used to represent a single check

type HealthCheckDefinition

type HealthCheckDefinition struct {
	HTTP                                   string
	Header                                 map[string][]string
	Method                                 string
	Body                                   string
	TLSServerName                          string
	TLSSkipVerify                          bool
	TCP                                    string
	TCPUseTLS                              bool
	UDP                                    string
	GRPC                                   string
	OSService                              string
	GRPCUseTLS                             bool
	TimeoutDuration                        time.Duration `json:"-"`
	IntervalDuration                       time.Duration `json:"-"`
	DeregisterCriticalServiceAfterDuration time.Duration `json:"-"`
}

HealthCheckDefinition is used to store the details about a health check's execution.

type StatusHandler

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

func NewStatusHandler

func NewStatusHandler(inner CheckNotifier, logger *zap.SugaredLogger, successBeforePassing, failuresBeforeWarning, failuresBeforeCritical int) *StatusHandler

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

Jump to

Keyboard shortcuts

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