forked from jaegertracing/jaeger
/
tchan-zipkincore.go
105 lines (83 loc) · 2.94 KB
/
tchan-zipkincore.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 zipkincore is generated code used to make or handle TChannel calls using Thrift.
package zipkincore
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.
// TChanZipkinCollector is the interface that defines the server handler and client interface.
type TChanZipkinCollector interface {
SubmitZipkinBatch(ctx thrift.Context, spans []*Span) ([]*Response, error)
}
// Implementation of a client and service handler.
type tchanZipkinCollectorClient struct {
thriftService string
client thrift.TChanClient
}
func NewTChanZipkinCollectorInheritedClient(thriftService string, client thrift.TChanClient) *tchanZipkinCollectorClient {
return &tchanZipkinCollectorClient{
thriftService,
client,
}
}
// NewTChanZipkinCollectorClient creates a client that can be used to make remote calls.
func NewTChanZipkinCollectorClient(client thrift.TChanClient) TChanZipkinCollector {
return NewTChanZipkinCollectorInheritedClient("ZipkinCollector", client)
}
func (c *tchanZipkinCollectorClient) SubmitZipkinBatch(ctx thrift.Context, spans []*Span) ([]*Response, error) {
var resp ZipkinCollectorSubmitZipkinBatchResult
args := ZipkinCollectorSubmitZipkinBatchArgs{
Spans: spans,
}
success, err := c.client.Call(ctx, c.thriftService, "submitZipkinBatch", &args, &resp)
if err == nil && !success {
switch {
default:
err = fmt.Errorf("received no result or unknown exception for submitZipkinBatch")
}
}
return resp.GetSuccess(), err
}
type tchanZipkinCollectorServer struct {
handler TChanZipkinCollector
}
// NewTChanZipkinCollectorServer wraps a handler for TChanZipkinCollector so it can be
// registered with a thrift.Server.
func NewTChanZipkinCollectorServer(handler TChanZipkinCollector) thrift.TChanServer {
return &tchanZipkinCollectorServer{
handler,
}
}
func (s *tchanZipkinCollectorServer) Service() string {
return "ZipkinCollector"
}
func (s *tchanZipkinCollectorServer) Methods() []string {
return []string{
"submitZipkinBatch",
}
}
func (s *tchanZipkinCollectorServer) Handle(ctx thrift.Context, methodName string, protocol athrift.TProtocol) (bool, athrift.TStruct, error) {
switch methodName {
case "submitZipkinBatch":
return s.handleSubmitZipkinBatch(ctx, protocol)
default:
return false, nil, fmt.Errorf("method %v not found in service %v", methodName, s.Service())
}
}
func (s *tchanZipkinCollectorServer) handleSubmitZipkinBatch(ctx thrift.Context, protocol athrift.TProtocol) (bool, athrift.TStruct, error) {
var req ZipkinCollectorSubmitZipkinBatchArgs
var res ZipkinCollectorSubmitZipkinBatchResult
if err := req.Read(protocol); err != nil {
return false, nil, err
}
r, err :=
s.handler.SubmitZipkinBatch(ctx, req.Spans)
if err != nil {
return false, nil, err
} else {
res.Success = r
}
return err == nil, &res, nil
}