部署准备
This commit is contained in:
1 parent
ee07869839
commit
c191974df7
6 files changed
+296
-10
No files matched your search
@@ -0,0 +1,38 @@
|
||||
// Command healthcheck checks the existing gRPC Health service for container readiness.
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/health/grpc_health_v1"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := check(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func check() error {
|
||||
conn, err := grpc.NewClient("127.0.0.1:50112", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
result, err := grpc_health_v1.NewHealthClient(conn).Check(ctx, &grpc_health_v1.HealthCheckRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.Status != grpc_health_v1.HealthCheckResponse_SERVING {
|
||||
return fmt.Errorf("gRPC service is %s", result.Status)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user