()
| 55 | } |
| 56 | |
| 57 | func main() { |
| 58 | flag.Parse() |
| 59 | |
| 60 | lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *port)) |
| 61 | if err != nil { |
| 62 | log.Fatalf("Failed to listen: %v", err) |
| 63 | } |
| 64 | fmt.Printf("Server listening at %v\n", lis.Addr()) |
| 65 | |
| 66 | // Create the gRPC server with the orca.CallMetricsServerOption() option, |
| 67 | // which will enable per-call metric recording. No ServerMetricsProvider |
| 68 | // is given here because the out-of-band reporting is enabled separately. |
| 69 | s := grpc.NewServer(orca.CallMetricsServerOption(nil)) |
| 70 | pb.RegisterEchoServer(s, &server{}) |
| 71 | |
| 72 | // Register the orca service for out-of-band metric reporting, and set the |
| 73 | // minimum reporting interval to 3 seconds. Note that, by default, the |
| 74 | // minimum interval must be at least 30 seconds, but 3 seconds is set via |
| 75 | // an internal-only option for illustration purposes only. |
| 76 | smr := orca.NewServerMetricsRecorder() |
| 77 | opts := orca.ServiceOptions{ |
| 78 | MinReportingInterval: 3 * time.Second, |
| 79 | ServerMetricsProvider: smr, |
| 80 | } |
| 81 | internal.ORCAAllowAnyMinReportingInterval.(func(so *orca.ServiceOptions))(&opts) |
| 82 | if err := orca.Register(s, opts); err != nil { |
| 83 | log.Fatalf("Failed to register ORCA service: %v", err) |
| 84 | } |
| 85 | |
| 86 | // Simulate CPU utilization reporting. |
| 87 | go func() { |
| 88 | for { |
| 89 | smr.SetCPUUtilization(.5) |
| 90 | time.Sleep(2 * time.Second) |
| 91 | smr.SetCPUUtilization(.9) |
| 92 | time.Sleep(2 * time.Second) |
| 93 | } |
| 94 | }() |
| 95 | |
| 96 | s.Serve(lis) |
| 97 | } |
nothing calls this directly
no test coverage detected