From 9e1d9e95bbec5cf8bc8b13c49cffc7ae6938ba76 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Wed, 17 May 2023 21:09:26 +0900 Subject: [PATCH] Change health check service name --- grpcstub.go | 11 ++++++++--- grpcstub_test.go | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/grpcstub.go b/grpcstub.go index 1bc9f57..aa5c71b 100644 --- a/grpcstub.go +++ b/grpcstub.go @@ -46,6 +46,11 @@ const ( status_closed ) +const ( + HealthCheckService_DEFAULT = "default" + HealthCheckService_FLAPPING = "flapping" +) + type Message map[string]interface{} type Request struct { @@ -441,10 +446,10 @@ func (s *Server) registerServer() { if s.healthCheck { healthSrv := health.NewServer() healthpb.RegisterHealthServer(s.server, healthSrv) - healthSrv.SetServingStatus("grpcstub", healthpb.HealthCheckResponse_SERVING) + healthSrv.SetServingStatus(HealthCheckService_DEFAULT, healthpb.HealthCheckResponse_SERVING) go func() { status := healthpb.HealthCheckResponse_SERVING - healthSrv.SetServingStatus("flipflop", status) + healthSrv.SetServingStatus(HealthCheckService_FLAPPING, status) for { switch s.status { case status_start, status_starting: @@ -453,7 +458,7 @@ func (s *Server) registerServer() { } else { status = healthpb.HealthCheckResponse_SERVING } - healthSrv.SetServingStatus("flipflop", status) + healthSrv.SetServingStatus(HealthCheckService_FLAPPING, status) } time.Sleep(100 * time.Millisecond) } diff --git a/grpcstub_test.go b/grpcstub_test.go index 570d51d..304f12a 100644 --- a/grpcstub_test.go +++ b/grpcstub_test.go @@ -794,7 +794,7 @@ func TestHealthCheck(t *testing.T) { }) client := healthpb.NewHealthClient(ts.ClientConn()) _, err := client.Check(ctx, &healthpb.HealthCheckRequest{ - Service: "grpcstub", + Service: HealthCheckService_DEFAULT, }) if err != nil { if !tt.wantErr {