health

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultInterval defines how often health check will run.
	// If DefaultTimeout > DefaultInterval, the next health check will be
	// dropped because of unfinished health check.
	DefaultInterval = 5 * time.Second

	// DefaultTimeout defines how long health check will run.
	// If the check function cannot be finished in time, a timeout error will be returned.
	DefaultTimeout = time.Second
)
View Source
const (
	StateUnknown   State = 0
	StateHealthy         = 1
	StateUnhealthy       = 2
)

Variables

This section is empty.

Functions

func RegisterHandlerClient

func RegisterHandlerClient(ctx context.Context, mux *runtime.ServeMux, conn grpc.ClientConnInterface) error

func RegisterServer

func RegisterServer(s grpc.ServiceRegistrar, srv Server)

Types

type CheckFunc

type CheckFunc func(ctx context.Context) error

CheckFunc is function which returns an error. It's an abstract definition of checking process. A customized checking process should be a CheckFunc.

Any panic in CheckFunc will cause process exit with error.

type Checker

type Checker interface {
	// HealthCheck checks service health status
	HealthCheck(ctx context.Context) error
}

Checker is an interface that implemented healtch check callback for health check runner.

type Reporter

type Reporter interface {
	// LastStatus gets last health status
	LastStatus() Status

	// StatusReportChan returns health status report channel
	// There is only one channel for each reporter instance
	// The message in channel should be consumed immediately, otherwise the message will be dropped
	StatusReportChan() chan Status
}

type RunOption

type RunOption func(*runOptions)

RunOption is used by a health runner. A runner will apply these options when running the health check.

func WithCheckInterval

func WithCheckInterval(interval time.Duration) RunOption

WithCheckInterval sets the period of health check interval.

func WithCheckTimeout

func WithCheckTimeout(d time.Duration) RunOption

WithCheckTimeout sets the timeout of health check.

func WithName

func WithName(name string) RunOption

WithName sets name of health check runner.

func WithPanicOnError

func WithPanicOnError(b bool) RunOption

WithPanicOnError indicates if we need to panic and crash the process when there is any error during health check.

If there is no error during health check, this option doesn't have any affect.

type Runner

type Runner interface {
	Reporter

	// AddCheck adds health check callback
	AddCheck(name string, cf CheckFunc)

	// Start starts health check runner and returns first result
	Start() Status

	// Stop stops health check runner
	Stop()
}

func NewRunner

func NewRunner(options ...RunOption) Runner

NewRunner creates a health runner.

type Server

func NewServer

func NewServer(healthReporter Reporter) Server

type State

type State int

State is health state code

type Status

type Status struct {
	State  State
	Error  error
	Source string // Source of error, usually is health check name
}

Status is health status

func (*Status) Equal

func (s *Status) Equal(d *Status) bool

Directories

Path Synopsis
Package proto is a reverse proxy.
Package proto is a reverse proxy.

Jump to

Keyboard shortcuts

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