Skip to content

Commit

Permalink
Merge pull request #45 from k1LoW/fix-service
Browse files Browse the repository at this point in the history
Change health check service name
  • Loading branch information
k1LoW authored May 17, 2023
2 parents 607e77d + 9e1d9e9 commit 6eebd9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions grpcstub.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const (
status_closed
)

const (
HealthCheckService_DEFAULT = "default"
HealthCheckService_FLAPPING = "flapping"
)

type Message map[string]interface{}

type Request struct {
Expand Down Expand Up @@ -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:
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion grpcstub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6eebd9c

Please sign in to comment.