Skip to content

Commit

Permalink
Remove Error handling
Browse files Browse the repository at this point in the history
Instead of failing right away the grpcclient
returns an empty message and the error.
Now the client (relay) that implements the
grpcclient is responsibe to handle the error

Signed-off-by: David Schall <[email protected]>
  • Loading branch information
dhschall committed Dec 17, 2023
1 parent 95c2986 commit cdc9042
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 139 deletions.
16 changes: 9 additions & 7 deletions grpcclient/aes_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"math/rand"

log "github.com/sirupsen/logrus"
pb "github.com/vhive-serverless/vSwarm-proto/proto/aes"
)

Expand Down Expand Up @@ -49,16 +48,19 @@ type AesClient struct {
client pb.AesClient
}

func (c *AesClient) Init(ctx context.Context, ip, port string) {
log.Printf("Connect to: %s:%s\n", ip, port)
c.Connect(ctx, ip, port)
func (c *AesClient) Init(ctx context.Context, ip, port string) error {
err := c.Connect(ctx, ip, port)
if err != nil {
return err
}
c.client = pb.NewAesClient(c.conn)
return nil
}

func (c *AesClient) Request(ctx context.Context, req Input) string {
func (c *AesClient) Request(ctx context.Context, req Input) (string, error) {
r, err := c.client.ShowEncryption(ctx, &pb.PlainTextMessage{PlaintextMessage: req.Value})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetEncryptionInfo()
return r.GetEncryptionInfo(), nil
}
15 changes: 9 additions & 6 deletions grpcclient/auth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"math/rand"

log "github.com/sirupsen/logrus"
pb "github.com/vhive-serverless/vSwarm-proto/proto/auth"
)

Expand Down Expand Up @@ -38,16 +37,20 @@ type AuthClient struct {
client pb.GreeterClient
}

func (c *AuthClient) Init(ctx context.Context, ip, port string) {
c.Connect(ctx, ip, port)
func (c *AuthClient) Init(ctx context.Context, ip, port string) error {
err := c.Connect(ctx, ip, port)
if err != nil {
return err
}
c.client = pb.NewGreeterClient(c.conn)
return nil
}

func (c *AuthClient) Request(ctx context.Context, req Input) string {
func (c *AuthClient) Request(ctx context.Context, req Input) (string, error) {
var authMessage = req.Value
r, err := c.client.SayHello(ctx, &pb.HelloRequest{Name: authMessage})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetMessage()
return r.GetMessage(), nil
}
15 changes: 9 additions & 6 deletions grpcclient/fibonacci_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/rand"

pb "github.com/vhive-serverless/vSwarm-proto/proto/fibonacci"
log "github.com/sirupsen/logrus"
)

type FibonacciGenerator struct {
Expand Down Expand Up @@ -37,16 +36,20 @@ type FibonacciClient struct {
client pb.GreeterClient
}

func (c *FibonacciClient) Init(ctx context.Context, ip, port string) {
c.Connect(ctx, ip, port)
func (c *FibonacciClient) Init(ctx context.Context, ip, port string) error {
err := c.Connect(ctx, ip, port)
if err != nil {
return err
}
c.client = pb.NewGreeterClient(c.conn)
return nil
}

func (c *FibonacciClient) Request(ctx context.Context, req Input) string {
func (c *FibonacciClient) Request(ctx context.Context, req Input) (string, error) {
var fibonacciMessage = req.Value
r, err := c.client.SayHello(ctx, &pb.HelloRequest{Name: fibonacciMessage})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetMessage()
return r.GetMessage(), nil
}
16 changes: 9 additions & 7 deletions grpcclient/gptj_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
pb "github.com/vhive-serverless/vSwarm-proto/proto/gptj"
)


type GptJGenerator struct {
GeneratorBase
}
Expand All @@ -33,17 +32,20 @@ func (c *GptJClient) GetGenerator() Generator {
return new(GptJGenerator)
}


func (c *GptJClient) Init(ctx context.Context, ip, port string) {
func (c *GptJClient) Init(ctx context.Context, ip, port string) error {
log.Printf("Connect to: %s:%s\n", ip, port)
c.Connect(ctx, ip, port)
err := c.Connect(ctx, ip, port)
if err != nil {
return err
}
c.client = pb.NewGptJBenchmarkClient(c.conn)
return nil
}

func (c *GptJClient) Request(ctx context.Context, req Input) string {
func (c *GptJClient) Request(ctx context.Context, req Input) (string, error) {
r, err := c.client.GetBenchmark(ctx, &pb.GptJBenchmarkRequest{Regenerate: req.Value})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetLatencyInfo();
return r.GetLatencyInfo(), nil
}
13 changes: 7 additions & 6 deletions grpcclient/grpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (s *GeneratorBase) Decrement() int {
// ------ gRPC Client interface ------
// Every client must implement this interface
type GrpcClient interface {
Init(ctx context.Context, ip, port string)
Request(ctx context.Context, req Input) string
Init(ctx context.Context, ip, port string) error
Request(ctx context.Context, req Input) (string, error)
Close()
GetGenerator() Generator
}
Expand All @@ -90,12 +90,12 @@ type ClientBase struct {
conn *grpc.ClientConn
}

func (c *ClientBase) Connect(ctx context.Context, ip, port string) {
func (c *ClientBase) Connect(ctx context.Context, ip, port string) error {
c.ip = ip
c.port = port
// Connect to the given address
address := fmt.Sprintf("%s:%s", c.ip, c.port)
log.Debug("Connect to ", address)
log.Println("Connect to ", address)
var conn *grpc.ClientConn
var err error
if tracing.IsTracingEnabled() {
Expand All @@ -110,10 +110,11 @@ func (c *ClientBase) Connect(ctx context.Context, ip, port string) {
log.Fields{
"event": "Connecting to benchmark server",
"key": err,
}).Fatal("Failed to connect.")
})
return err
}
c.conn = conn

return nil
}

func (c *ClientBase) Close() {
Expand Down
15 changes: 9 additions & 6 deletions grpcclient/helloworld_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

pb "github.com/vhive-serverless/vSwarm-proto/proto/helloworld"
log "github.com/sirupsen/logrus"
)

// type HelloWorldGenerator struct {
Expand Down Expand Up @@ -58,15 +57,19 @@ type HelloWorldClient struct {
client pb.GreeterClient
}

func (c *HelloWorldClient) Init(ctx context.Context, ip, port string) {
c.Connect(ctx, ip, port)
func (c *HelloWorldClient) Init(ctx context.Context, ip, port string) error {
err := c.Connect(ctx, ip, port)
if err != nil {
return err
}
c.client = pb.NewGreeterClient(c.conn)
return nil
}

func (c *HelloWorldClient) Request(ctx context.Context, req Input) string {
func (c *HelloWorldClient) Request(ctx context.Context, req Input) (string, error) {
r, err := c.client.SayHello(ctx, &pb.HelloRequest{Name: req.Value})
if err != nil {
log.Fatalf("could not greet: %v", err)
return "", err
}
return r.GetMessage()
return r.GetMessage(), nil
}
Loading

0 comments on commit cdc9042

Please sign in to comment.