prober

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitReached = errors.New("the read limit is reached")

ErrLimitReached means that the read limit is reached.

Functions

This section is empty.

Types

type ExecProber

type ExecProber interface {
	// Probe executes a command to check a service status.
	//
	// If the process terminates with any exit code besides 0, Failure will be returned.
	// The merged result of stdout + stderr are returned as output.
	Probe(ctx context.Context, name string, args ...string) (Result, string, error)
}

ExecProber executes a command to check a service status.

func NewExecProber

func NewExecProber() ExecProber

NewExecProber creates an ExecProber.

type HTTPGetProber

type HTTPGetProber interface {
	// Probe executes an HTTP GET request to determine service status.
	//
	// Any non-successful status code (< 200 or >= 400) or HTTP/network communication error will return Failure.
	// A potentially truncated version of the HTTP response body is returned as output.
	Probe(ctx context.Context, url *url.URL, headers http.Header) (Result, string, error)
}

HTTPGetProber executes HTTP GET requests to determine service status.

func NewHTTPGetProber

func NewHTTPGetProber() HTTPGetProber

NewHTTPGetProber creates a HTTPGetProber that will perform an HTTP GET request to determine service status.

type Manager

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

Manager creates standardized Prober instances from shared instances of underlying implementations for common probe types.

func NewManager

func NewManager() *Manager

NewManager creates a Manager instance to create standard Prober types.

func (*Manager) Exec

func (m *Manager) Exec(name string, args ...string) ProberFunc

Exec returns a ProberFunc that performs exec probes for a specific command.

func (*Manager) HTTPGet

func (m *Manager) HTTPGet(u *url.URL, headers http.Header) ProberFunc

HTTPGet returns a ProberFunc that performs HTTP GET probes for a specific URL & header combination.

func (*Manager) TCPSocket

func (m *Manager) TCPSocket(host string, port int) ProberFunc

TCPSocket returns a ProberFunc that performs TCP socket probes for a specific host & port combination.

type Prober

type Prober interface {
	// Probe executes a single status check.
	//
	// result is the current service status
	// output is optional info from the probe (such as a process stdout or HTTP response)
	// err indicates an issue with the probe itself and that the result should be ignored
	Probe(ctx context.Context) (result Result, output string, err error)
}

Prober performs a check to determine a service status.

type ProberFunc

type ProberFunc func(ctx context.Context) (Result, string, error)

ProberFunc is a functional version of Prober.

func (ProberFunc) Probe

func (f ProberFunc) Probe(ctx context.Context) (Result, string, error)

Probe executes a single status check.

result is the current service status output is optional info from the probe (such as a process stdout or HTTP response) err indicates an issue with the probe itself and that the result should be ignored

type Result

type Result string

Result is a string used to indicate service status.

const (
	// Success indicates that the service is healthy.
	Success Result = "success"
	// Warning indicates that the service is healthy but additional diagnostic information might be attached.
	Warning Result = "warning"
	// Failure indicates that the service is not healthy.
	Failure Result = "failure"
	// Unknown indicates that the prober was unable to determine the service status due to an internal issue.
	//
	// An Unknown result should also include an error in the Prober return values.
	Unknown Result = "unknown"
)

type TCPSocketProber

type TCPSocketProber interface {
	// Probe establishes a TCP socket to determine service status.
	//
	// Any error establishing the TCP connection will return Failure.
	// In the event of inability to establish a TCP connection, the output will include error information.
	// Successful TCP connections will result in no output returned.
	Probe(ctx context.Context, host string, port int) (Result, string, error)
}

TCPSocketProber establishes a TCP socket to determine service status.

func NewTCPSocketProber

func NewTCPSocketProber() TCPSocketProber

NewTCPSocketProber creates a TCPSocketProber that checks connectivity to a given address to determine service status.

Jump to

Keyboard shortcuts

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