open-nomad/demo/grpc-checks/example/example.go
Seth Hoenig f2ef576510 demo: create a demo service for grpc healthchecks
Examples for HTTP based task-group service healthchecks are
covered by the `countdash` demo, but gRPC checks currently
have no runnable examples.

This PR adds a trivial gRPC enabled application that provides
a Service implementing the standard gRPC healthcheck interface.
2020-04-24 10:59:50 -06:00

32 lines
750 B
Go

package example
import (
"context"
"log"
ghc "google.golang.org/grpc/health/grpc_health_v1"
)
// Server is a trivial gRPC server that implements the standard grpc.health.v1
// interface.
type Server struct {
}
func New() *Server {
return new(Server)
}
func (s *Server) Check(ctx context.Context, hcr *ghc.HealthCheckRequest) (*ghc.HealthCheckResponse, error) {
log.Printf("Check:%s (%s)", hcr.Service, hcr.String())
return &ghc.HealthCheckResponse{
Status: ghc.HealthCheckResponse_SERVING,
}, nil
}
func (s *Server) Watch(hcr *ghc.HealthCheckRequest, hws ghc.Health_WatchServer) error {
log.Printf("Watch:%s (%s)", hcr.Service, hcr.String())
return hws.Send(&ghc.HealthCheckResponse{
Status: ghc.HealthCheckResponse_SERVING,
})
}