Skip to content

Commit

Permalink
Fix SearviceHealthStatus (#449)
Browse files Browse the repository at this point in the history
It was failing to connect due to an SSL issue but was using
deprecated grpc calls.
  • Loading branch information
ronenh authored Sep 5, 2024
1 parent c14ec76 commit 674a9e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
30 changes: 12 additions & 18 deletions pkg/cli/cc/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,25 @@ import (
"fmt"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
client "github.com/aserto-dev/go-aserto"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
)

const rpcTimeout = time.Second * 30

// ServiceHealthStatus adopted from grpc-health-probe cli implementation
// https://github.com/grpc-ecosystem/grpc-health-probe/blob/master/main.go.
func ServiceHealthStatus(addr, service string) bool {
connTimeout := time.Second * 30
rpcTimeout := time.Second * 30

dialCtx, dialCancel := context.WithTimeout(context.Background(), connTimeout)
defer dialCancel()

dialOpts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
}

conn, err := grpc.DialContext(dialCtx, addr, dialOpts...) //nolint: staticcheck
func ServiceHealthStatus(ctx context.Context, addr, service string) (bool, error) {
conn, err := client.NewConnection(
client.WithAddr(addr),
client.WithInsecure(true),
)
if err != nil {
return false
return false, err
}
defer conn.Close()

rpcCtx, rpcCancel := context.WithTimeout(context.Background(), rpcTimeout)
rpcCtx, rpcCancel := context.WithTimeout(ctx, rpcTimeout)
defer rpcCancel()

if err := Retry(rpcTimeout, time.Millisecond*100, func() error {
Expand All @@ -44,8 +38,8 @@ func ServiceHealthStatus(addr, service string) bool {

return nil
}); err != nil {
return false
return false, nil
}

return true
return true, nil
}
4 changes: 3 additions & 1 deletion pkg/cli/cmd/templates/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ func (cmd *InstallTemplateCmd) installTemplate(c *cc.CommonCtx, tmpl *template)
fmt.Fprintln(c.StdErr(), "Please change to using the new TOPAZ_DB_DIR and TOPAZ_CERTS_DIR environment variables.")
}
addr, _ := cfg.HealthService()
if !cc.ServiceHealthStatus(addr, "model") {
if health, err := cc.ServiceHealthStatus(c.Context, addr, "model"); err != nil {
return fmt.Errorf("unable to check health status: %w", err)
} else if !health {
return fmt.Errorf("gRPC endpoint not SERVING")
}
if model, ok := cfg.Configuration.APIConfig.Services["model"]; !ok {
Expand Down

0 comments on commit 674a9e6

Please sign in to comment.