checks

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoData = errors.New("no data yet")

ErrNoData is returned if the first call of an Async() wrapped Check has not yet returned.

Functions

This section is empty.

Types

type Check

type Check func() error

Check is a health/readiness check.

func Async

func Async(check Check, interval time.Duration) Check

Async converts a Check into an asynchronous check that runs in a background goroutine at a fixed interval. The check is called at a fixed rate, not with a fixed delay between invocations. If your check takes longer than the interval to execute, the next execution will happen immediately.

Note: if you need to clean up the background goroutine, use AsyncWithContext().

func AsyncWithContext

func AsyncWithContext(ctx context.Context, check Check, interval time.Duration) Check

AsyncWithContext converts a Check into an asynchronous check that runs in a background goroutine at a fixed interval. The check is called at a fixed rate, not with a fixed delay between invocations. If your check takes longer than the interval to execute, the next execution will happen immediately.

Note: if you don't need to cancel execution (because this runs forever), use Async()

func CheckGRPC

func CheckGRPC(grpcClient grpc_health_v1.HealthClient) Check

CheckRedis returns a Check function to check for readiness of given grpc service.

func CheckRedis

func CheckRedis(client redis.Cmdable) Check

CheckRedis returns a Check function that validates Redis connection.

func DNSResolveCheck

func DNSResolveCheck(host string, timeout time.Duration) Check

DNSResolveCheck returns a Check that makes sure the provided host can resolve to at least one IP address within the specified timeout.

func DatabaseSelectCheck

func DatabaseSelectCheck(client *sql.DB, timeout time.Duration) Check

DatabaseSelectCheck returns a Check that validates connectivity to a database using `SELECT 1` query execution.

func GoroutineCountCheck

func GoroutineCountCheck(threshold int) Check

GoroutineCountCheck returns a Check that fails if too many goroutines are running (which could indicate a resource leak).

func HTTPGetCheck

func HTTPGetCheck(url string, timeout time.Duration) Check

HTTPGetCheck returns a Check that performs an HTTP GET request against the specified URL. The check fails if the response times out or returns a non-200 status code.

func TCPDialCheck

func TCPDialCheck(addr string, timeout time.Duration) Check

TCPDialCheck returns a Check that checks TCP connectivity to the provided endpoint.

func Timeout

func Timeout(check Check, timeout time.Duration) Check

Timeout adds a timeout to a Check. If the underlying check takes longer than the timeout, it returns an error.

type TimeoutError

type TimeoutError time.Duration

TimeoutError is the error returned when a Timeout-wrapped Check takes too long

func (TimeoutError) Error

func (e TimeoutError) Error() string

func (TimeoutError) Temporary

func (e TimeoutError) Temporary() bool

Temporary returns whether this error is temporary (always true for timeoutError)

func (TimeoutError) Timeout

func (e TimeoutError) Timeout() bool

Timeout returns whether this error is a timeout (always true for timeoutError)

Jump to

Keyboard shortcuts

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