-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
tchan-sampling.go
105 lines (83 loc) · 3.02 KB
/
tchan-sampling.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 sampling is generated code used to make or handle TChannel calls using Thrift.
package sampling
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.
// TChanSamplingManager is the interface that defines the server handler and client interface.
type TChanSamplingManager interface {
GetSamplingStrategy(ctx thrift.Context, serviceName string) (*SamplingStrategyResponse, error)
}
// Implementation of a client and service handler.
type tchanSamplingManagerClient struct {
thriftService string
client thrift.TChanClient
}
func NewTChanSamplingManagerInheritedClient(thriftService string, client thrift.TChanClient) *tchanSamplingManagerClient {
return &tchanSamplingManagerClient{
thriftService,
client,
}
}
// NewTChanSamplingManagerClient creates a client that can be used to make remote calls.
func NewTChanSamplingManagerClient(client thrift.TChanClient) TChanSamplingManager {
return NewTChanSamplingManagerInheritedClient("SamplingManager", client)
}
func (c *tchanSamplingManagerClient) GetSamplingStrategy(ctx thrift.Context, serviceName string) (*SamplingStrategyResponse, error) {
var resp SamplingManagerGetSamplingStrategyResult
args := SamplingManagerGetSamplingStrategyArgs{
ServiceName: serviceName,
}
success, err := c.client.Call(ctx, c.thriftService, "getSamplingStrategy", &args, &resp)
if err == nil && !success {
switch {
default:
err = fmt.Errorf("received no result or unknown exception for getSamplingStrategy")
}
}
return resp.GetSuccess(), err
}
type tchanSamplingManagerServer struct {
handler TChanSamplingManager
}
// NewTChanSamplingManagerServer wraps a handler for TChanSamplingManager so it can be
// registered with a thrift.Server.
func NewTChanSamplingManagerServer(handler TChanSamplingManager) thrift.TChanServer {
return &tchanSamplingManagerServer{
handler,
}
}
func (s *tchanSamplingManagerServer) Service() string {
return "SamplingManager"
}
func (s *tchanSamplingManagerServer) Methods() []string {
return []string{
"getSamplingStrategy",
}
}
func (s *tchanSamplingManagerServer) Handle(ctx thrift.Context, methodName string, protocol athrift.TProtocol) (bool, athrift.TStruct, error) {
switch methodName {
case "getSamplingStrategy":
return s.handleGetSamplingStrategy(ctx, protocol)
default:
return false, nil, fmt.Errorf("method %v not found in service %v", methodName, s.Service())
}
}
func (s *tchanSamplingManagerServer) handleGetSamplingStrategy(ctx thrift.Context, protocol athrift.TProtocol) (bool, athrift.TStruct, error) {
var req SamplingManagerGetSamplingStrategyArgs
var res SamplingManagerGetSamplingStrategyResult
if err := req.Read(protocol); err != nil {
return false, nil, err
}
r, err :=
s.handler.GetSamplingStrategy(ctx, req.ServiceName)
if err != nil {
return false, nil, err
} else {
res.Success = r
}
return err == nil, &res, nil
}