MG-2235 - Check gRPC service is healthy during setup (#2245)

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
This commit is contained in:
b1ackd0t
2024-06-12 12:46:42 +03:00
committed by GitHub
parent 75a66a4f9b
commit 487dcc643c
25 changed files with 123 additions and 53 deletions
+8 -3
View File
@@ -18,16 +18,17 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/health"
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
)
const (
stopWaitTime = 5 * time.Second
)
const stopWaitTime = 5 * time.Second
type Server struct {
server.BaseServer
server *grpc.Server
registerService serviceRegister
health *health.Server
}
type serviceRegister func(srv *grpc.Server)
@@ -116,7 +117,10 @@ func (s *Server) Start() error {
grpcServerOptions = append(grpcServerOptions, creds)
s.server = grpc.NewServer(grpcServerOptions...)
s.health = health.NewServer()
grpchealth.RegisterHealthServer(s.server, s.health)
s.registerService(s.server)
s.health.SetServingStatus(s.Name, grpchealth.HealthCheckResponse_SERVING)
go func() {
errCh <- s.server.Serve(listener)
@@ -136,6 +140,7 @@ func (s *Server) Stop() error {
c := make(chan bool)
go func() {
defer close(c)
s.health.Shutdown()
s.server.GracefulStop()
}()
select {