-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathserver.go
More file actions
82 lines (69 loc) · 1.89 KB
/
server.go
File metadata and controls
82 lines (69 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package proxy
import (
"context"
"io"
"net"
common "github.com/runconduit/conduit/controller/gen/common"
destination "github.com/runconduit/conduit/controller/gen/proxy/destination"
telemetry "github.com/runconduit/conduit/controller/gen/proxy/telemetry"
"github.com/runconduit/conduit/controller/util"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)
type (
server struct {
telemetryClient telemetry.TelemetryClient
destinationClient destination.DestinationClient
}
)
func (s *server) Report(ctx context.Context, req *telemetry.ReportRequest) (*telemetry.ReportResponse, error) {
log.Debug("Report")
resp, err := s.telemetryClient.Report(ctx, req)
if err != nil {
log.Errorf("Report: %v", err)
return nil, err
}
return resp, nil
}
func (s *server) Get(dest *common.Destination, stream destination.Destination_GetServer) error {
log := log.WithFields(
log.Fields{
"scheme": dest.Scheme,
"path": dest.Path,
})
log.Debug("Get")
rsp, err := s.destinationClient.Get(stream.Context(), dest)
if err != nil {
log.Error(err)
return err
}
for {
update, err := rsp.Recv()
if err == io.EOF {
break
}
if err != nil {
log.Error(err)
return err
}
log.Debug("Get update: %v", update)
stream.Send(update)
}
log.Debug("Get complete")
return nil
}
/*
* The Proxy-API server accepts requests from proxy instances and forwards those
* requests to the appropriate controller service.
*/
func NewServer(addr string, telemetryClient telemetry.TelemetryClient, destinationClient destination.DestinationClient) (*grpc.Server, net.Listener, error) {
lis, err := net.Listen("tcp", addr)
if err != nil {
return nil, nil, err
}
s := util.NewGrpcServer()
srv := server{telemetryClient: telemetryClient, destinationClient: destinationClient}
telemetry.RegisterTelemetryServer(s, &srv)
destination.RegisterDestinationServer(s, &srv)
return s, lis, nil
}