check

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeout is returned when a check times out during evaluation
	ErrTimeout = fmt.Errorf("timed out waiting for check")
)

Functions

This section is empty.

Types

type Check

type Check interface {
	GetMetadata() Metadata
	Watch(ctx context.Context, channel chan Report)
}

Check is the smallest unit of health in gracefully. Checks should be JSON serializable.

type Error added in v0.0.6

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

Error is an error that is JSON serializable.

func WrapError added in v0.0.6

func WrapError(err error) *Error

WrapError will wrap the supplied err (if present) with a JSON serializable wrapper.

func (*Error) MarshalJSON added in v0.0.6

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON enables JSON serialization of this error.

func (*Error) UnmarshalJSON added in v0.0.6

func (e *Error) UnmarshalJSON(bytes []byte) error

UnmarshalJSON enables JSON deserialization of this error.

func (*Error) Unwrap added in v0.0.6

func (e *Error) Unwrap() error

Unwrap provides access to the underlying error object.

type Metadata

type Metadata struct {
	Name    string `json:"name"`
	Runbook string `json:"runbook,omitempty"`
	Weight  uint   `json:"weight"`
}

Metadata contains information common to every check.

type Periodic

type Periodic struct {
	Metadata
	Interval time.Duration   `json:"interval,string"`
	Timeout  time.Duration   `json:"timeout,string"`
	Clock    clockwork.Clock `json:"-"`
	RunFunc  RunFunc         `json:"-"`
}

Periodic is a Check implementation that runs a provided function on a set interval and configured timeout. This is a common type of Check.

func (*Periodic) GetMetadata

func (p *Periodic) GetMetadata() Metadata

GetMetadata returns meta information about the check.

func (*Periodic) Once

func (p *Periodic) Once(parent context.Context) Result

Once performs a one time evaluation of the check.

func (*Periodic) Watch

func (p *Periodic) Watch(ctx context.Context, channel chan Report)

Watch sets up a go routine to run the check on the configured interval.

type Report

type Report struct {
	Check  Check
	Result Result
}

Report is a single emission of a check and it's one time evaluation.

type Result

type Result struct {
	State     state.State `json:"state"`
	CurrentHP float32     `json:"currentHP,omitempty"`
	Error     error       `json:"error,omitempty"`
	Timestamp time.Time   `json:"timestamp"`
}

Result represents the outcome of a given check. This information is useful to help diagnose issues in the system.

type RunFunc

type RunFunc = func(ctx context.Context) (state.State, error)

RunFunc is a simple function that defines a unary check for state.

type Stream

type Stream struct {
	Metadata
	Clock     clockwork.Clock `json:"-"`
	WatchFunc WatchFunc       `json:"-"`
}

Stream is a Check implementation

func (*Stream) GetMetadata

func (s *Stream) GetMetadata() Metadata

GetMetadata returns meta information about the check.

func (*Stream) Watch

func (s *Stream) Watch(ctx context.Context, channel chan Report)

Watch will observe a stream of changes in a checks state.

type WatchFunc

type WatchFunc = func(ctx context.Context, channel chan Result)

WatchFunc defines an easy to use function that starts a watch.

Jump to

Keyboard shortcuts

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