agent.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT.
  2. package agent
  3. import(
  4. "bytes"
  5. "context"
  6. "fmt"
  7. "time"
  8. "github.com/uber/jaeger-client-go/thrift"
  9. "github.com/uber/jaeger-client-go/thrift-gen/jaeger"
  10. "github.com/uber/jaeger-client-go/thrift-gen/zipkincore"
  11. )
  12. // (needed to ensure safety because of naive import list construction.)
  13. var _ = thrift.ZERO
  14. var _ = fmt.Printf
  15. var _ = context.Background
  16. var _ = time.Now
  17. var _ = bytes.Equal
  18. var _ = jaeger.GoUnusedProtection__
  19. var _ = zipkincore.GoUnusedProtection__
  20. type Agent interface {
  21. // Parameters:
  22. // - Spans
  23. EmitZipkinBatch(ctx context.Context, spans []*zipkincore.Span) (_err error)
  24. // Parameters:
  25. // - Batch
  26. EmitBatch(ctx context.Context, batch *jaeger.Batch) (_err error)
  27. }
  28. type AgentClient struct {
  29. c thrift.TClient
  30. meta thrift.ResponseMeta
  31. }
  32. func NewAgentClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AgentClient {
  33. return &AgentClient{
  34. c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)),
  35. }
  36. }
  37. func NewAgentClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AgentClient {
  38. return &AgentClient{
  39. c: thrift.NewTStandardClient(iprot, oprot),
  40. }
  41. }
  42. func NewAgentClient(c thrift.TClient) *AgentClient {
  43. return &AgentClient{
  44. c: c,
  45. }
  46. }
  47. func (p *AgentClient) Client_() thrift.TClient {
  48. return p.c
  49. }
  50. func (p *AgentClient) LastResponseMeta_() thrift.ResponseMeta {
  51. return p.meta
  52. }
  53. func (p *AgentClient) SetLastResponseMeta_(meta thrift.ResponseMeta) {
  54. p.meta = meta
  55. }
  56. // Parameters:
  57. // - Spans
  58. func (p *AgentClient) EmitZipkinBatch(ctx context.Context, spans []*zipkincore.Span) (_err error) {
  59. var _args0 AgentEmitZipkinBatchArgs
  60. _args0.Spans = spans
  61. p.SetLastResponseMeta_(thrift.ResponseMeta{})
  62. if _, err := p.Client_().Call(ctx, "emitZipkinBatch", &_args0, nil); err != nil {
  63. return err
  64. }
  65. return nil
  66. }
  67. // Parameters:
  68. // - Batch
  69. func (p *AgentClient) EmitBatch(ctx context.Context, batch *jaeger.Batch) (_err error) {
  70. var _args1 AgentEmitBatchArgs
  71. _args1.Batch = batch
  72. p.SetLastResponseMeta_(thrift.ResponseMeta{})
  73. if _, err := p.Client_().Call(ctx, "emitBatch", &_args1, nil); err != nil {
  74. return err
  75. }
  76. return nil
  77. }
  78. type AgentProcessor struct {
  79. processorMap map[string]thrift.TProcessorFunction
  80. handler Agent
  81. }
  82. func (p *AgentProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
  83. p.processorMap[key] = processor
  84. }
  85. func (p *AgentProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
  86. processor, ok = p.processorMap[key]
  87. return processor, ok
  88. }
  89. func (p *AgentProcessor) ProcessorMap() map[string]thrift.TProcessorFunction {
  90. return p.processorMap
  91. }
  92. func NewAgentProcessor(handler Agent) *AgentProcessor {
  93. self2 := &AgentProcessor{handler:handler, processorMap:make(map[string]thrift.TProcessorFunction)}
  94. self2.processorMap["emitZipkinBatch"] = &agentProcessorEmitZipkinBatch{handler:handler}
  95. self2.processorMap["emitBatch"] = &agentProcessorEmitBatch{handler:handler}
  96. return self2
  97. }
  98. func (p *AgentProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  99. name, _, seqId, err2 := iprot.ReadMessageBegin(ctx)
  100. if err2 != nil { return false, thrift.WrapTException(err2) }
  101. if processor, ok := p.GetProcessorFunction(name); ok {
  102. return processor.Process(ctx, seqId, iprot, oprot)
  103. }
  104. iprot.Skip(ctx, thrift.STRUCT)
  105. iprot.ReadMessageEnd(ctx)
  106. x3 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function " + name)
  107. oprot.WriteMessageBegin(ctx, name, thrift.EXCEPTION, seqId)
  108. x3.Write(ctx, oprot)
  109. oprot.WriteMessageEnd(ctx)
  110. oprot.Flush(ctx)
  111. return false, x3
  112. }
  113. type agentProcessorEmitZipkinBatch struct {
  114. handler Agent
  115. }
  116. func (p *agentProcessorEmitZipkinBatch) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  117. args := AgentEmitZipkinBatchArgs{}
  118. var err2 error
  119. if err2 = args.Read(ctx, iprot); err2 != nil {
  120. iprot.ReadMessageEnd(ctx)
  121. return false, thrift.WrapTException(err2)
  122. }
  123. iprot.ReadMessageEnd(ctx)
  124. tickerCancel := func() {}
  125. _ = tickerCancel
  126. if err2 = p.handler.EmitZipkinBatch(ctx, args.Spans); err2 != nil {
  127. tickerCancel()
  128. return true, thrift.WrapTException(err2)
  129. }
  130. tickerCancel()
  131. return true, nil
  132. }
  133. type agentProcessorEmitBatch struct {
  134. handler Agent
  135. }
  136. func (p *agentProcessorEmitBatch) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
  137. args := AgentEmitBatchArgs{}
  138. var err2 error
  139. if err2 = args.Read(ctx, iprot); err2 != nil {
  140. iprot.ReadMessageEnd(ctx)
  141. return false, thrift.WrapTException(err2)
  142. }
  143. iprot.ReadMessageEnd(ctx)
  144. tickerCancel := func() {}
  145. _ = tickerCancel
  146. if err2 = p.handler.EmitBatch(ctx, args.Batch); err2 != nil {
  147. tickerCancel()
  148. return true, thrift.WrapTException(err2)
  149. }
  150. tickerCancel()
  151. return true, nil
  152. }
  153. // HELPER FUNCTIONS AND STRUCTURES
  154. // Attributes:
  155. // - Spans
  156. type AgentEmitZipkinBatchArgs struct {
  157. Spans []*zipkincore.Span `thrift:"spans,1" db:"spans" json:"spans"`
  158. }
  159. func NewAgentEmitZipkinBatchArgs() *AgentEmitZipkinBatchArgs {
  160. return &AgentEmitZipkinBatchArgs{}
  161. }
  162. func (p *AgentEmitZipkinBatchArgs) GetSpans() []*zipkincore.Span {
  163. return p.Spans
  164. }
  165. func (p *AgentEmitZipkinBatchArgs) Read(ctx context.Context, iprot thrift.TProtocol) error {
  166. if _, err := iprot.ReadStructBegin(ctx); err != nil {
  167. return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
  168. }
  169. for {
  170. _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
  171. if err != nil {
  172. return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
  173. }
  174. if fieldTypeId == thrift.STOP { break; }
  175. switch fieldId {
  176. case 1:
  177. if fieldTypeId == thrift.LIST {
  178. if err := p.ReadField1(ctx, iprot); err != nil {
  179. return err
  180. }
  181. } else {
  182. if err := iprot.Skip(ctx, fieldTypeId); err != nil {
  183. return err
  184. }
  185. }
  186. default:
  187. if err := iprot.Skip(ctx, fieldTypeId); err != nil {
  188. return err
  189. }
  190. }
  191. if err := iprot.ReadFieldEnd(ctx); err != nil {
  192. return err
  193. }
  194. }
  195. if err := iprot.ReadStructEnd(ctx); err != nil {
  196. return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
  197. }
  198. return nil
  199. }
  200. func (p *AgentEmitZipkinBatchArgs) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
  201. _, size, err := iprot.ReadListBegin(ctx)
  202. if err != nil {
  203. return thrift.PrependError("error reading list begin: ", err)
  204. }
  205. tSlice := make([]*zipkincore.Span, 0, size)
  206. p.Spans = tSlice
  207. for i := 0; i < size; i ++ {
  208. _elem4 := &zipkincore.Span{}
  209. if err := _elem4.Read(ctx, iprot); err != nil {
  210. return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem4), err)
  211. }
  212. p.Spans = append(p.Spans, _elem4)
  213. }
  214. if err := iprot.ReadListEnd(ctx); err != nil {
  215. return thrift.PrependError("error reading list end: ", err)
  216. }
  217. return nil
  218. }
  219. func (p *AgentEmitZipkinBatchArgs) Write(ctx context.Context, oprot thrift.TProtocol) error {
  220. if err := oprot.WriteStructBegin(ctx, "emitZipkinBatch_args"); err != nil {
  221. return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) }
  222. if p != nil {
  223. if err := p.writeField1(ctx, oprot); err != nil { return err }
  224. }
  225. if err := oprot.WriteFieldStop(ctx); err != nil {
  226. return thrift.PrependError("write field stop error: ", err) }
  227. if err := oprot.WriteStructEnd(ctx); err != nil {
  228. return thrift.PrependError("write struct stop error: ", err) }
  229. return nil
  230. }
  231. func (p *AgentEmitZipkinBatchArgs) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
  232. if err := oprot.WriteFieldBegin(ctx, "spans", thrift.LIST, 1); err != nil {
  233. return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:spans: ", p), err) }
  234. if err := oprot.WriteListBegin(ctx, thrift.STRUCT, len(p.Spans)); err != nil {
  235. return thrift.PrependError("error writing list begin: ", err)
  236. }
  237. for _, v := range p.Spans {
  238. if err := v.Write(ctx, oprot); err != nil {
  239. return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err)
  240. }
  241. }
  242. if err := oprot.WriteListEnd(ctx); err != nil {
  243. return thrift.PrependError("error writing list end: ", err)
  244. }
  245. if err := oprot.WriteFieldEnd(ctx); err != nil {
  246. return thrift.PrependError(fmt.Sprintf("%T write field end error 1:spans: ", p), err) }
  247. return err
  248. }
  249. func (p *AgentEmitZipkinBatchArgs) String() string {
  250. if p == nil {
  251. return "<nil>"
  252. }
  253. return fmt.Sprintf("AgentEmitZipkinBatchArgs(%+v)", *p)
  254. }
  255. // Attributes:
  256. // - Batch
  257. type AgentEmitBatchArgs struct {
  258. Batch *jaeger.Batch `thrift:"batch,1" db:"batch" json:"batch"`
  259. }
  260. func NewAgentEmitBatchArgs() *AgentEmitBatchArgs {
  261. return &AgentEmitBatchArgs{}
  262. }
  263. var AgentEmitBatchArgs_Batch_DEFAULT *jaeger.Batch
  264. func (p *AgentEmitBatchArgs) GetBatch() *jaeger.Batch {
  265. if !p.IsSetBatch() {
  266. return AgentEmitBatchArgs_Batch_DEFAULT
  267. }
  268. return p.Batch
  269. }
  270. func (p *AgentEmitBatchArgs) IsSetBatch() bool {
  271. return p.Batch != nil
  272. }
  273. func (p *AgentEmitBatchArgs) Read(ctx context.Context, iprot thrift.TProtocol) error {
  274. if _, err := iprot.ReadStructBegin(ctx); err != nil {
  275. return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
  276. }
  277. for {
  278. _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin(ctx)
  279. if err != nil {
  280. return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
  281. }
  282. if fieldTypeId == thrift.STOP { break; }
  283. switch fieldId {
  284. case 1:
  285. if fieldTypeId == thrift.STRUCT {
  286. if err := p.ReadField1(ctx, iprot); err != nil {
  287. return err
  288. }
  289. } else {
  290. if err := iprot.Skip(ctx, fieldTypeId); err != nil {
  291. return err
  292. }
  293. }
  294. default:
  295. if err := iprot.Skip(ctx, fieldTypeId); err != nil {
  296. return err
  297. }
  298. }
  299. if err := iprot.ReadFieldEnd(ctx); err != nil {
  300. return err
  301. }
  302. }
  303. if err := iprot.ReadStructEnd(ctx); err != nil {
  304. return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
  305. }
  306. return nil
  307. }
  308. func (p *AgentEmitBatchArgs) ReadField1(ctx context.Context, iprot thrift.TProtocol) error {
  309. p.Batch = &jaeger.Batch{}
  310. if err := p.Batch.Read(ctx, iprot); err != nil {
  311. return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Batch), err)
  312. }
  313. return nil
  314. }
  315. func (p *AgentEmitBatchArgs) Write(ctx context.Context, oprot thrift.TProtocol) error {
  316. if err := oprot.WriteStructBegin(ctx, "emitBatch_args"); err != nil {
  317. return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) }
  318. if p != nil {
  319. if err := p.writeField1(ctx, oprot); err != nil { return err }
  320. }
  321. if err := oprot.WriteFieldStop(ctx); err != nil {
  322. return thrift.PrependError("write field stop error: ", err) }
  323. if err := oprot.WriteStructEnd(ctx); err != nil {
  324. return thrift.PrependError("write struct stop error: ", err) }
  325. return nil
  326. }
  327. func (p *AgentEmitBatchArgs) writeField1(ctx context.Context, oprot thrift.TProtocol) (err error) {
  328. if err := oprot.WriteFieldBegin(ctx, "batch", thrift.STRUCT, 1); err != nil {
  329. return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:batch: ", p), err) }
  330. if err := p.Batch.Write(ctx, oprot); err != nil {
  331. return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Batch), err)
  332. }
  333. if err := oprot.WriteFieldEnd(ctx); err != nil {
  334. return thrift.PrependError(fmt.Sprintf("%T write field end error 1:batch: ", p), err) }
  335. return err
  336. }
  337. func (p *AgentEmitBatchArgs) String() string {
  338. if p == nil {
  339. return "<nil>"
  340. }
  341. return fmt.Sprintf("AgentEmitBatchArgs(%+v)", *p)
  342. }