healthx

package
v0.0.628 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 3 Imported by: 25

Documentation

Overview

Package healthx providers helpers for returning health status information via HTTP.

Index

Constants

View Source
const (
	// AliveCheckPath is the path where information about the life state of the instance is provided.
	AliveCheckPath = "/health/alive"
	// ReadyCheckPath is the path where information about the ready state of the instance is provided.
	ReadyCheckPath = "/health/ready"
	// VersionPath is the path where information about the software version of the instance is provided.
	VersionPath = "/version"
)

Variables

This section is empty.

Functions

func NoopReadyChecker

func NoopReadyChecker() error

NoopReadyChecker is always ready.

func RoutesToObserve

func RoutesToObserve() []string

RoutesToObserve returns a string of all the available routes of this module.

Types

type Handler

type Handler struct {
	H             herodot.Writer
	VersionString string
	ReadyChecks   ReadyCheckers
}

Handler handles HTTP requests to health and version endpoints.

func NewHandler

func NewHandler(
	h herodot.Writer,
	version string,
	readyChecks ReadyCheckers,
) *Handler

NewHandler instantiates a handler.

func (*Handler) Alive

func (h *Handler) Alive() http.Handler

Alive returns an ok status if the instance is ready to handle HTTP requests.

swagger:route GET /health/alive health isInstanceAlive

Check alive status

This endpoint returns a 200 status code when the HTTP server is up running. This status does currently not include checks whether the database connection is working.

If the service supports TLS Edge Termination, this endpoint does not require the `X-Forwarded-Proto` header to be set.

Be aware that if you are running multiple nodes of this service, the health status will never refer to the cluster state, only to a single instance.

Produces:
- application/json
- text/plain

Responses:
  200: healthStatus
  default: unexpectedError

func (*Handler) Ready

func (h *Handler) Ready(shareErrors bool) http.Handler

Ready returns an ok status if the instance is ready to handle HTTP requests and all ReadyCheckers are ok.

swagger:route GET /health/ready health isInstanceReady

Check readiness status

This endpoint returns a 200 status code when the HTTP server is up running and the environment dependencies (e.g. the database) are responsive as well.

If the service supports TLS Edge Termination, this endpoint does not require the `X-Forwarded-Proto` header to be set.

Be aware that if you are running multiple nodes of this service, the health status will never refer to the cluster state, only to a single instance.

Produces:
- application/json
- text/plain

Responses:
  200: healthStatus
  503: healthNotReadyStatus
  default: unexpectedError

func (*Handler) SetHealthRoutes added in v0.0.207

func (h *Handler) SetHealthRoutes(r router, shareErrors bool, opts ...Options)

SetHealthRoutes registers this handler's routes for health checking.

func (*Handler) SetVersionRoutes added in v0.0.207

func (h *Handler) SetVersionRoutes(r router, opts ...Options)

SetVersionRoutes registers this handler's routes for health checking.

func (*Handler) Version

func (h *Handler) Version() http.Handler

Version returns this service's versions.

swagger:route GET /version version getVersion

Get service version

This endpoint returns the service version typically notated using semantic versioning.

If the service supports TLS Edge Termination, this endpoint does not require the `X-Forwarded-Proto` header to be set.

Be aware that if you are running multiple nodes of this service, the health status will never refer to the cluster state, only to a single instance.

    Produces:
    - application/json

	   Responses:
			200: version

type Options added in v0.0.402

type Options func(*options)

func WithMiddleware added in v0.0.402

func WithMiddleware(h func(http.Handler) http.Handler) Options

WithMiddleware accepts a http.Handler to be run on the route handlers

type ReadyChecker

type ReadyChecker func(r *http.Request) error

ReadyChecker should return an error if the component is not ready yet.

type ReadyCheckers added in v0.0.11

type ReadyCheckers map[string]ReadyChecker

ReadyCheckers is a map of ReadyCheckers.

Jump to

Keyboard shortcuts

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