Skip to content

Commit

Permalink
Use grpc.NewClient instead of DialContext
Browse files Browse the repository at this point in the history
as it's been deprecated: https://pkg.go.dev/google.golang.org/grpc#DialContext

Signed-off-by: Isabella Basso do Amaral <[email protected]>
  • Loading branch information
isinyaaa committed Jul 15, 2024
1 parent 74ff182 commit 34adc4b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
26 changes: 8 additions & 18 deletions cmd/proxy.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package cmd

import (
"context"
"fmt"
"net/http"
"time"

"github.com/golang/glog"
"github.com/kubeflow/model-registry/internal/mlmdtypes"
Expand All @@ -15,32 +13,24 @@ import (
"google.golang.org/grpc/credentials/insecure"
)

var (
// proxyCmd represents the proxy command
proxyCmd = &cobra.Command{
Use: "proxy",
Short: "Starts the ml-metadata go OpenAPI proxy",
Long: `This command launches the ml-metadata go OpenAPI proxy server.
// proxyCmd represents the proxy command
var proxyCmd = &cobra.Command{
Use: "proxy",
Short: "Starts the ml-metadata go OpenAPI proxy",
Long: `This command launches the ml-metadata go OpenAPI proxy server.
The server connects to a mlmd CPP server. It supports options to customize the
hostname and port where it listens.'`,
RunE: runProxyServer,
}
)
RunE: runProxyServer,
}

func runProxyServer(cmd *cobra.Command, args []string) error {
glog.Infof("proxy server started at %s:%v", cfg.Hostname, cfg.Port)

ctxTimeout, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

mlmdAddr := fmt.Sprintf("%s:%d", proxyCfg.MLMDHostname, proxyCfg.MLMDPort)
glog.Infof("connecting to MLMD server %s..", mlmdAddr)
conn, err := grpc.DialContext(
ctxTimeout,
conn, err := grpc.NewClient(
mlmdAddr,
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions docs/mr_go_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ import (
"google.golang.org/grpc/credentials/insecure"
)

conn, err := grpc.DialContext(
context.Background(),
conn, err := grpc.NewClient(
"localhost:9090",
grpc.WithReturnConnectionError(),
grpc.WithBlock(), // optional
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
Expand All @@ -43,7 +40,7 @@ if err != nil {
defer conn.Close()
```

> NOTE: check [grpc doc](https://pkg.go.dev/google.golang.org/grpc#DialContext) for more details.
> NOTE: check [grpc doc](https://pkg.go.dev/google.golang.org/grpc#NewClient) for more details.
Once the gRPC connection is setup, let's create the `ModelRegistryService`:

Expand Down
5 changes: 1 addition & 4 deletions internal/testutils/test_container_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,8 @@ func SetupMLMetadataTestContainer(t *testing.T) (*grpc.ClientConn, proto.Metadat
t.Log("MLMD test container running at: ", mlmdAddr)

// setup grpc connection
conn, err := grpc.DialContext(
context.Background(),
conn, err := grpc.NewClient(
mlmdAddr,
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
Expand Down

0 comments on commit 34adc4b

Please sign in to comment.