-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from hidevopsio/grpc-health
support customized health check
- Loading branch information
Showing
10 changed files
with
135 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package at | ||
|
||
// HealthCheckService is the annotation for health check service | ||
type HealthCheckService interface { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package grpc | ||
|
||
import ( | ||
"context" | ||
pb "google.golang.org/grpc/health/grpc_health_v1" | ||
"hidevops.io/hiboot/pkg/at" | ||
) | ||
|
||
// controller | ||
type healthCheckService struct { | ||
at.HealthCheckService | ||
// declare HelloServiceClient | ||
healthClient pb.HealthClient | ||
} | ||
|
||
// Init inject helloServiceClient | ||
func newHealthCheckService(healthClient pb.HealthClient) *healthCheckService { | ||
return &healthCheckService{ | ||
healthClient: healthClient, | ||
} | ||
} | ||
|
||
// Status return health check display name grpc | ||
func (c *healthCheckService) Name() (name string) { | ||
return Profile | ||
} | ||
|
||
// Status return grpc health check status as bool | ||
func (c *healthCheckService) Status() (up bool) { | ||
resp, err := c.healthClient.Check(context.TODO(), &pb.HealthCheckRequest{}) | ||
if err == nil { | ||
up = resp.Status == pb.HealthCheckResponse_SERVING | ||
} | ||
return | ||
} |