health

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: Apache-2.0 Imports: 6 Imported by: 20

README

Health

Package contains tools that allow to add REST endpoint for handling health and readiness requests. Package also provides implementation for most typical checks that may be done to figure our if service is healthy/ready.

HTTP Handler

A handler to serve checks using /health and /ready endpoints can be added to your service in a following way:

	healthChecker := health.NewChecksHandler("/health", "/ready"),
	)
	healthChecker.AddReadiness("Readiness check name", readinessCheck)
	healthChecker.AddLiveness("Liveness check name", livenessCheck)

	s, err := server.NewServer(
		// register our health checks
		server.WithHealthChecks(healthChecker),
	)

In a sample above readinessCheck and livenessCheck are functions that perform a single check. It is possible to add multiple checks independently and handler will call them in sequence.

Checks

Packange provides several predefined checks:

  • DNSProbeCheck(host string, timeout time.Duration) returns a Check that determines whether a service with specified DNS name is reachable or not using net.Resolver's LookupHost method.
  • HTTPGetCheck(url string, timeout time.Duration) returns a Check that performs an HTTP GET request to the specified URL. It fails if timeout was exceeded or non-200-OK status code returned.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check func() error

Check

func DNSProbeCheck

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

DNSProbeCheck returns a Check that determines whether a service with specified DNS name is reachable or not using net.Resolver's LookupHost method.

func HTTPGetCheck

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

HTTPGetCheck returns a Check that performs an HTTP GET request to the specified URL. It fails if timeout was exceeded or non-200-OK status code returned.

type CheckContext added in v0.25.0

type CheckContext func(ctx context.Context) error

type Checker

type Checker interface {
	AddLiveness(name string, check Check)
	AddReadiness(name string, check Check)
	Handler() http.Handler
	RegisterHandler(mux *http.ServeMux)
	SetFailFast(failFast bool)
	GetFailFast() bool
}

Checker ...

func NewChecksHandler

func NewChecksHandler(healthPath, readyPath string) Checker

NewChecksHandler accepts two strings: health and ready paths. These paths will be used for liveness and readiness checks.

type CheckerContext added in v0.25.0

type CheckerContext interface {
	AddLiveness(name string, check CheckContext)
	AddReadiness(name string, check CheckContext)
	Handler() http.Handler
	RegisterHandler(mux *http.ServeMux)
	SetFailFast(failFast bool)
	GetFailFast() bool
}

CheckerContext ...

func NewChecksContextHandler added in v0.25.0

func NewChecksContextHandler(healthPath, readyPath string) CheckerContext

NewChecksContextHandler accepts two strings: health and ready paths. These paths will be used for liveness and readiness checks.

Jump to

Keyboard shortcuts

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