handlers

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: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GrpcHandler

type GrpcHandler interface {
	// following items are copied from previous `Handler` interface with
	// the same meaning, except that an additional parameter for specifying
	// check execution interval was added
	http.Handler
	AddLivenessCheck(name string, check checks.Check, interval time.Duration) error
	AddReadinessCheck(name string, check checks.Check, interval time.Duration) error
	LiveEndpoint(http.ResponseWriter, *http.Request)
	ReadyEndpoint(http.ResponseWriter, *http.Request)

	// AddGrpcReadinessCheck opens a stream (Watch rpc of Health service) and
	// listens for health status changes of a gRPC dependency.
	AddGrpcReadinessCheck(name string, grpcClient grpc_health_v1.HealthClient) error

	// Close performs cleanup on all background checks and resources
	Close()
}

GrpcHandler is similar to Handler, but has support for gRPC:

  • `AddGrpcReadinessCheck` opens a stream (Watch rpc of Health service) and listens for health status changes of a gRPC dependency
  • sets correct serving status of gRPC Health server automatically.

Another difference is, that readiness and liveness checks are executed periodically and not only on `/live` or `/ready` HTTP GET requests.

func NewGrpcHandler

func NewGrpcHandler(hs *health.Server, opts ...GrpcHandlerOption) GrpcHandler

type GrpcHandlerOption

type GrpcHandlerOption func(*grpcHandler)

GrpcOption represents option for NewGrpcHandler.

func WithZapLogger

func WithZapLogger(log *zap.Logger) GrpcHandlerOption

WithZapLogger sets zap logger

type Handler

type Handler interface {
	// The Handler is an http.Handler, so it can be exposed directly and handle
	// /live and /ready endpoints.
	http.Handler

	// AddLivenessCheck adds a check that indicates that this instance of the
	// application should be destroyed or restarted. A failed liveness check
	// indicates that this instance is unhealthy, not some upstream dependency.
	// Every liveness check is also included as a readiness check.
	// Error is returned in case check `name` has already been added.
	AddLivenessCheck(name string, check checks.Check) error

	// AddReadinessCheck adds a check that indicates that this instance of the
	// application is currently unable to serve requests because of an upstream
	// or some transient failure. If a readiness check fails, this instance
	// should no longer receiver requests, but should not be restarted or
	// destroyed.
	// Error is returned in case check `name` has already been added.
	AddReadinessCheck(name string, check checks.Check) error

	// LiveEndpoint is the HTTP handler for just the /live endpoint, which is
	// useful if you need to attach it into your own HTTP handler tree.
	LiveEndpoint(http.ResponseWriter, *http.Request)

	// ReadyEndpoint is the HTTP handler for just the /ready endpoint, which is
	// useful if you need to attach it into your own HTTP handler tree.
	ReadyEndpoint(http.ResponseWriter, *http.Request)
}

Handler is an http.Handler with additional methods that register health and readiness checks. It handles handle "/live" and "/ready" HTTP endpoints.

func NewHandler

func NewHandler() Handler

NewHandler creates a new basic Handler

func NewMetricsHandler

func NewMetricsHandler(registry prometheus.Registerer, namespace string) Handler

NewMetricsHandler returns a healthcheck Handler that also exposes metrics into the provided Prometheus registry.

Jump to

Keyboard shortcuts

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