Documentation ¶
Overview ¶
Package health defines standard interfaces and utilities for health checks.
Index ¶
- Constants
- func NewClient(cc grpc.ClientConnInterface) grpc_health_v1.HealthClient
- type CheckFunc
- type CheckRequest
- type CheckResponse
- type Checker
- type Config
- type MServer
- func (s *MServer) Check(ctx context.Context, req *CheckRequest) (*CheckResponse, error)
- func (s *MServer) Close() error
- func (s *MServer) Init(status Status) error
- func (s *MServer) Register(srv *grpc.Server)
- func (s *MServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *MServer) SetStatus(service string, status Status)
- func (s *MServer) Watch(req *CheckRequest, srv WatchServer) error
- type Server
- type ServerOption
- type Status
- type StatusSetter
- type WatchServer
Constants ¶
const ( StatusUnknown = grpc_health_v1.HealthCheckResponse_UNKNOWN StatusServing = grpc_health_v1.HealthCheckResponse_SERVING StatusNotServing = grpc_health_v1.HealthCheckResponse_NOT_SERVING StatusServiceUnknown = grpc_health_v1.HealthCheckResponse_SERVICE_UNKNOWN )
Status const defines short name for grpc_health_v1.HealthCheckResponse_ServingStatus.
const (
// OverallServiceName is service name of server's overall status.
OverallServiceName = ""
)
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶ added in v0.1.8
func NewClient(cc grpc.ClientConnInterface) grpc_health_v1.HealthClient
NewClient return a new HealthClient.
Types ¶
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) ServeHTTP ¶ added in v0.1.8
func (s *MServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP 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
type Status = grpc_health_v1.HealthCheckResponse_ServingStatus
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.