()
| 41 | var test = flag.Bool("test", false, "if set, only 1 RPC is performed before exiting") |
| 42 | |
| 43 | func main() { |
| 44 | flag.Parse() |
| 45 | |
| 46 | // Set up a connection to the server. Configure to use our custom LB |
| 47 | // policy which will receive all the ORCA load reports. |
| 48 | conn, err := grpc.NewClient(*addr, |
| 49 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 50 | grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"orca_example":{}}]}`), |
| 51 | ) |
| 52 | if err != nil { |
| 53 | log.Fatalf("did not connect: %v", err) |
| 54 | } |
| 55 | defer conn.Close() |
| 56 | |
| 57 | c := pb.NewEchoClient(conn) |
| 58 | |
| 59 | // Perform RPCs once per second. |
| 60 | ticker := time.NewTicker(time.Second) |
| 61 | for range ticker.C { |
| 62 | func() { |
| 63 | // Use an anonymous function to ensure context cancellation via defer. |
| 64 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 65 | defer cancel() |
| 66 | if _, err := c.UnaryEcho(ctx, &pb.EchoRequest{Message: "test echo message"}); err != nil { |
| 67 | log.Fatalf("Error from UnaryEcho call: %v", err) |
| 68 | } |
| 69 | }() |
| 70 | if *test { |
| 71 | return |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | } |
| 76 | |
| 77 | // Register an ORCA load balancing policy to receive per-call metrics and |
| 78 | // out-of-band metrics. |
nothing calls this directly
no test coverage detected