healthz

package
v1.42.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusOK is returned when all the registered checks pass.
	StatusOK = "OK"
	// StatusUnavailable is returned when any of the registered checks fail.
	StatusUnavailable = "Unavailable"
)

Variables

View Source
var (
	// DefaultRuntimeTTL is the default TTL of the collected runtime stats.
	DefaultRuntimeTTL = 15 * time.Second
	// DefaultChecker is the default golbal checker referenced by the shortcut
	// functions in this package. Change this variable with caution.
	DefaultChecker = NewChecker(&Config{RuntimeTTL: DefaultRuntimeTTL})
)

Functions

func Delete

func Delete(name string)

Delete is a shortcut for DefaultChecker.Delete. See there for more information.

func Deregister

func Deregister(name string)

Deregister is a shortcut for DefaultChecker.Deregister. See there for more information.

func Handler

func Handler() http.Handler

Handler is a shortcut for DefaultChecker.Handler. See there for more information.

func Register

func Register(name string, period time.Duration, fn CheckFunc)

Register is a shortcut for DefaultChecker.Register. See there for more information.

func Set

func Set(name string, value interface{})

Set is a shortcut for DefaultChecker.Set. See there for more information.

Types

type CheckFunc

type CheckFunc func() error

CheckFunc is an application health check function.

type Checker

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

Checker is a health status checker responsible for evaluating the registered checks as well as of collecting useful runtime information about the Go Process. It provides an HTTP handler that returns the current health status.

func NewChecker

func NewChecker(config *Config) *Checker

NewChecker creates a new Checker.

func (*Checker) Delete

func (c *Checker) Delete(name string)

Delete deletes a named entry from the configured metadata.

func (*Checker) Deregister

func (c *Checker) Deregister(name string)

Deregister deregisters a check.

func (*Checker) Handler

func (c *Checker) Handler() http.Handler

Handler returns an HTTP handler to be used as a health check endpoint. If the application is healthy and all the registered check pass, it returns a `200 OK` HTTP status code, otherwise, it fails with a `503 Service Unavailable` code. All responses contain a JSON encoded payload with information about the runtime system, current checks statuses and some configurable metadata.

func (*Checker) Register

func (c *Checker) Register(name string, period time.Duration, fn CheckFunc)

Register registers a check to be evaluated each given period.

func (*Checker) Set

func (c *Checker) Set(name string, value interface{})

Set sets a name value pair as a metadata entry to be returned with each response. This can be used to store useful debug information like version numbers.

func (*Checker) Status

func (c *Checker) Status() Status

Status returns the current service status.

type Config

type Config struct {
	RuntimeTTL time.Duration
}

Config parameterizes a Checker.

type Runtime

type Runtime struct {
	CollectedAt      time.Time `json:"-"`
	Arch             string    `json:"arch"`
	OS               string    `json:"os"`
	Version          string    `json:"version"`
	GoroutinesCount  int       `json:"goroutines_count"`
	HeapObjectsCount int       `json:"heap_objects_count"`
	AllocBytes       int       `json:"alloc_bytes"`
	TotalAllocBytes  int       `json:"total_alloc_bytes"`
}

Runtime contains statistics about the Go's process.

type Status

type Status struct {
	Status   string                 `json:"status"`
	Time     time.Time              `json:"time"`
	Since    time.Time              `json:"since"`
	Runtime  Runtime                `json:"runtime"`
	Failures map[string]string      `json:"failures,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

Status represents the service health status.

Jump to

Keyboard shortcuts

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