Skip to content

Commit

Permalink
Warn client when invocation fail.
Browse files Browse the repository at this point in the history
Before the relay panics when the function did
not repond in time or something breaks.
Instead of breaking we send back a waring to the
invoking client.

Signed-off-by: David Schall <[email protected]>
  • Loading branch information
dhschall committed Aug 2, 2023
1 parent 171924a commit 20525bf
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions tools/relay/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ var (
value = flag.String("value", "helloWorld", "String input to pass to benchmark")
functionMethod = flag.String("function-method", "default", "Which method of benchmark to invoke")

clientReqRecv = 0
funcInvSuccess = 0
funcInvFail = 0

// Client
grpcClient grpcClients.GrpcClient
inputGenerator grpcClients.Generator
Expand All @@ -77,6 +81,11 @@ func isDebuggingEnabled() bool {
}
}

func printStats() {
log.Printf("Client Requests: %d", clientReqRecv)
log.Printf("Function Invocations: %d successful, %d fail", funcInvSuccess, funcInvFail)
}

func main() {
flag.Parse()

Expand Down Expand Up @@ -139,17 +148,29 @@ func main() {
log.Printf("Started relay server at %s", *address)

if err := grpcServer.Serve(listener); err != nil {
log.Fatalf("failed to serve: %v", err)
log.Fatalf("Failed to serve: %v", err)
}
}

func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
log.Info("Received from invoker: ", in.GetName())
log.Debug("Received from invoker: ", in.GetName())
clientReqRecv++

if clientReqRecv%100 == 0 {
printStats()
}

// Create new packet
pkt := inputGenerator.Next()
log.Debug("Send to func: ", pkt)
reply := grpcClient.Request(ctx, pkt)
reply, err := grpcClient.Request(ctx, pkt)

Check failure on line 166 in tools/relay/server.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (./tools/relay)

assignment mismatch: 2 variables but grpcClient.Request returns 1 value (typecheck)

Check failure on line 166 in tools/relay/server.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (./tools/relay)

assignment mismatch: 2 variables but grpcClient.Request returns 1 value (typecheck)
if err != nil {
log.Warnf("Failed to send request to function: %v\n", err)
funcInvFail++
return nil, err
}

funcInvSuccess++
log.Debug("Recv from func: ", reply)

return &pb.HelloReply{Message: reply}, nil
Expand Down

0 comments on commit 20525bf

Please sign in to comment.