forked from jaegertracing/jaeger
/
tchan-jaeger.go
105 lines (83 loc) · 2.75 KB
/
tchan-jaeger.go
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// @generated Code generated by thrift-gen. Do not modify.
// Package jaeger is generated code used to make or handle TChannel calls using Thrift.
package jaeger
import (
"fmt"
athrift "github.com/apache/thrift/lib/go/thrift"
"github.com/uber/tchannel-go/thrift"
)
// Interfaces for the service and client for the services defined in the IDL.
// TChanCollector is the interface that defines the server handler and client interface.
type TChanCollector interface {
SubmitBatches(ctx thrift.Context, batches []*Batch) ([]*BatchSubmitResponse, error)
}
// Implementation of a client and service handler.
type tchanCollectorClient struct {
thriftService string
client thrift.TChanClient
}
func NewTChanCollectorInheritedClient(thriftService string, client thrift.TChanClient) *tchanCollectorClient {
return &tchanCollectorClient{
thriftService,
client,
}
}
// NewTChanCollectorClient creates a client that can be used to make remote calls.
func NewTChanCollectorClient(client thrift.TChanClient) TChanCollector {
return NewTChanCollectorInheritedClient("Collector", client)
}
func (c *tchanCollectorClient) SubmitBatches(ctx thrift.Context, batches []*Batch) ([]*BatchSubmitResponse, error) {
var resp CollectorSubmitBatchesResult
args := CollectorSubmitBatchesArgs{
Batches: batches,
}
success, err := c.client.Call(ctx, c.thriftService, "submitBatches", &args, &resp)
if err == nil && !success {
switch {
default:
err = fmt.Errorf("received no result or unknown exception for submitBatches")
}
}
return resp.GetSuccess(), err
}
type tchanCollectorServer struct {
handler TChanCollector
}
// NewTChanCollectorServer wraps a handler for TChanCollector so it can be
// registered with a thrift.Server.
func NewTChanCollectorServer(handler TChanCollector) thrift.TChanServer {
return &tchanCollectorServer{
handler,
}
}
func (s *tchanCollectorServer) Service() string {
return "Collector"
}
func (s *tchanCollectorServer) Methods() []string {
return []string{
"submitBatches",
}
}
func (s *tchanCollectorServer) Handle(ctx thrift.Context, methodName string, protocol athrift.TProtocol) (bool, athrift.TStruct, error) {
switch methodName {
case "submitBatches":
return s.handleSubmitBatches(ctx, protocol)
default:
return false, nil, fmt.Errorf("method %v not found in service %v", methodName, s.Service())
}
}
func (s *tchanCollectorServer) handleSubmitBatches(ctx thrift.Context, protocol athrift.TProtocol) (bool, athrift.TStruct, error) {
var req CollectorSubmitBatchesArgs
var res CollectorSubmitBatchesResult
if err := req.Read(protocol); err != nil {
return false, nil, err
}
r, err :=
s.handler.SubmitBatches(ctx, req.Batches)
if err != nil {
return false, nil, err
} else {
res.Success = r
}
return err == nil, &res, nil
}