health

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: MIT Imports: 15 Imported by: 4

Documentation

Overview

Package health defines standard interfaces and utilities for health checks.

Index

Constants

Status const defines short name for grpc_health_v1.HealthCheckResponse_ServingStatus.

View Source
const (
	// OverallServiceName is service name of server's overall status.
	OverallServiceName = ""
)

Variables

This section is empty.

Functions

func NewClient added in v0.1.8

NewClient return a new HealthClient.

Types

type CheckFunc

type CheckFunc func(context.Context) error

CheckFunc is quick way to define a health checker.

func (CheckFunc) CheckHealth added in v0.2.1

func (c CheckFunc) CheckHealth(ctx context.Context) error

CheckHealth implements Checker interface.

type CheckRequest added in v0.1.8

type CheckRequest = grpc_health_v1.HealthCheckRequest

CheckRequest is an alias of grpc_health_v1.HealthCheckRequest.

type CheckResponse added in v0.1.8

type CheckResponse = grpc_health_v1.HealthCheckResponse

CheckResponse is an alias of grpc_health_v1.HealthCheckResponse

type Checker added in v0.2.1

type Checker interface {
	// CheckHealth establish health check to the target service.
	// Return error if target service cannot be reached
	// or not working properly.
	CheckHealth(ctx context.Context) error
}

Checker provide functionality for checking health of a service.

type Config added in v0.1.8

type Config struct {
	Interval time.Duration `envconfig:"HEALTH_CHECK_INTERVAL" default:"60s"`
	Timeout  time.Duration `envconfig:"HEALTH_CHECK_TIMEOUT" default:"1s"`
}

Config hold server config.

type MServer added in v0.1.8

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

MServer is a simple implementation of Server.

func NewServer added in v0.1.8

func NewServer(m map[string]Checker, opts ...ServerOption) *MServer

NewServer return new gRPC health server.

func (*MServer) Check added in v0.1.8

func (s *MServer) Check(ctx context.Context, req *CheckRequest) (*CheckResponse, error)

Check implements health.Server.

func (*MServer) Close added in v0.1.8

func (s *MServer) Close() error

Close implements health.Server.

func (*MServer) Init added in v0.1.8

func (s *MServer) Init(status Status) error

Init implements health.Server.

func (*MServer) Register added in v0.1.8

func (s *MServer) Register(srv *grpc.Server)

Register implements health.Server.

func (*MServer) ServeHTTP added in v0.1.8

func (s *MServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements health.Server.

func (*MServer) SetStatus added in v0.1.8

func (s *MServer) SetStatus(service string, status Status)

SetStatus implements health.Server

func (*MServer) Watch added in v0.1.8

func (s *MServer) Watch(req *CheckRequest, srv WatchServer) error

Watch implements health.Server.

type Server added in v0.1.8

type Server interface {
	// Implements grpc_health_v1.HealthServer for general health check and
	// load balancing according to gRPC protocol.
	grpc_health_v1.HealthServer
	// Implements http.Handler Check API via HTTP.
	http.Handler
	// Register register the Server with grpc.Server
	Register(srv *grpc.Server)
	// Init initialize status, perform necessary setup and start a
	// first health check immediately to update overall status and all
	// dependent services's status.
	Init(status Status) error
	// Close close the underlying resources.
	// It sets all serving status to NOT_SERVING, and configures the server to
	// ignore all future status changes.
	Close() error
}

Server provides health check services via both gRPC and HTTP. The implementation must follow protocol defined in https://github.com/grpc/grpc/blob/master/doc/health-checking.md

type ServerOption added in v0.1.8

type ServerOption func(srv *MServer)

ServerOption is a function to provide additional options for server.

func FromConfig added in v0.1.8

func FromConfig(conf Config) ServerOption

FromConfig is an option to override server's config.

func FromEnv added in v0.1.8

func FromEnv(opts ...config.ReadOption) ServerOption

FromEnv is an option to load config from environment variables.

func Interval added in v0.1.8

func Interval(d time.Duration) ServerOption

Interval is an option to set interval for health check.

func Logger added in v0.1.8

func Logger(l log.Logger) ServerOption

Logger is an option to set logger for the health check server.

func Timeout added in v0.1.8

func Timeout(d time.Duration) ServerOption

Timeout is an option to set timeout for each service health check.

type Status added in v0.1.8

Status is an alias of grpc_health_v1.HealthCheckResponse_ServingStatus.

type StatusSetter added in v0.1.8

type StatusSetter interface {
	// SetStatus is called when need to reset the serving status of a service
	// or insert a new service entry into the statusMap.
	// Use empty string for setting overall status.
	SetStatus(name string, status Status)
}

StatusSetter is an interface to set status for a service according to gRPC Health Check protocol.

type WatchServer added in v0.1.8

type WatchServer = grpc_health_v1.Health_WatchServer

WatchServer is an alias of grpc_health_v1.Health_WatchServer.

Jump to

Keyboard shortcuts

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