From 1225f0b3fa18502ce19cf201a0f07b8a45540338 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Thu, 5 Mar 2015 23:12:46 +0100 Subject: [PATCH 01/38] Another direction for package server --- addsvc/.gitignore | 1 + addsvc/endpoint.go | 21 +++++++ addsvc/enhancements.go | 22 ++++++++ addsvc/grpc_binding.go | 27 +++++++++ addsvc/implementations.go | 21 +++++++ addsvc/json_http_binding.go | 68 ++++++++++++++++++++++ addsvc/main.go | 81 ++++++++++++++++++++++++++ addsvc/pb/add.pb.go | 110 ++++++++++++++++++++++++++++++++++++ addsvc/pb/add.proto | 20 +++++++ addsvc/request_response.go | 13 +++++ server/server.go | 20 +++++++ transport/codec/codec.go | 17 ++++++ 12 files changed, 421 insertions(+) create mode 100644 addsvc/.gitignore create mode 100644 addsvc/endpoint.go create mode 100644 addsvc/enhancements.go create mode 100644 addsvc/grpc_binding.go create mode 100644 addsvc/implementations.go create mode 100644 addsvc/json_http_binding.go create mode 100644 addsvc/main.go create mode 100644 addsvc/pb/add.pb.go create mode 100644 addsvc/pb/add.proto create mode 100644 addsvc/request_response.go create mode 100644 server/server.go create mode 100644 transport/codec/codec.go diff --git a/addsvc/.gitignore b/addsvc/.gitignore new file mode 100644 index 000000000..87a25340f --- /dev/null +++ b/addsvc/.gitignore @@ -0,0 +1 @@ +addsvc diff --git a/addsvc/endpoint.go b/addsvc/endpoint.go new file mode 100644 index 000000000..64a504d28 --- /dev/null +++ b/addsvc/endpoint.go @@ -0,0 +1,21 @@ +package main + +import ( + "github.com/peterbourgon/gokit/server" + "golang.org/x/net/context" +) + +func makeEndpoint(a Add) server.Endpoint { + return func(ctx context.Context, req server.Request) (server.Response, error) { + addReq, ok := req.(*request) + if !ok { + return nil, server.ErrBadCast + } + + v := a(addReq.A, addReq.B) + + return response{ + V: v, + }, nil + } +} diff --git a/addsvc/enhancements.go b/addsvc/enhancements.go new file mode 100644 index 000000000..9d87327ab --- /dev/null +++ b/addsvc/enhancements.go @@ -0,0 +1,22 @@ +package main + +import ( + "encoding/json" + "io" + "time" +) + +func logging(w io.Writer, add Add) Add { + return func(a, b int64) (v int64) { + defer func(begin time.Time) { + json.NewEncoder(w).Encode(map[string]interface{}{ + "a": a, + "b": b, + "result": v, + "took": time.Since(begin), + }) + }(time.Now()) + v = add(a, b) + return + } +} diff --git a/addsvc/grpc_binding.go b/addsvc/grpc_binding.go new file mode 100644 index 000000000..fbb8d0c8a --- /dev/null +++ b/addsvc/grpc_binding.go @@ -0,0 +1,27 @@ +package main + +import ( + "github.com/peterbourgon/gokit/addsvc/pb" + "github.com/peterbourgon/gokit/server" + "golang.org/x/net/context" +) + +type grpcBinding struct{ server.Endpoint } + +// Add implements the proto3 AddServer by forwarding to the wrapped Endpoint. +func (b grpcBinding) Add(ctx context.Context, req *pb.AddRequest) (*pb.AddReply, error) { + addReq := request{req.A, req.B} + r, err := b.Endpoint(ctx, addReq) + if err != nil { + return nil, err + } + + resp, ok := r.(*response) + if !ok { + return nil, server.ErrBadCast + } + + return &pb.AddReply{ + V: resp.V, + }, nil +} diff --git a/addsvc/implementations.go b/addsvc/implementations.go new file mode 100644 index 000000000..b8deaf00e --- /dev/null +++ b/addsvc/implementations.go @@ -0,0 +1,21 @@ +package main + +// Add is the abstract definition of what this service does. +// It could easily be an interface type with multiple methods. +type Add func(int64, int64) int64 + +func pureAdd(a, b int64) int64 { return a + b } + +func addVia(r Resource) Add { + return func(a, b int64) int64 { + return r.Value(a) + r.Value(b) + } +} + +type Resource interface { + Value(int64) int64 +} + +type mockResource struct{} + +func (mockResource) Value(i int64) int64 { return i } diff --git a/addsvc/json_http_binding.go b/addsvc/json_http_binding.go new file mode 100644 index 000000000..4ad48fadb --- /dev/null +++ b/addsvc/json_http_binding.go @@ -0,0 +1,68 @@ +package main + +import ( + "encoding/json" + "io" + "net/http" + + "github.com/peterbourgon/gokit/transport/codec" + + "github.com/peterbourgon/gokit/server" + "golang.org/x/net/context" +) + +type jsonCodec struct{} + +func (jsonCodec) Decode(_ context.Context, r io.Reader) (server.Request, error) { + var req request + err := json.NewDecoder(r).Decode(req) + return req, err +} + +func (jsonCodec) Encode(w io.Writer, resp server.Response) error { + return json.NewEncoder(w).Encode(resp) +} + +type httpBinding struct { + context.Context + codec.Codec + server.Endpoint +} + +func (b httpBinding) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // If the context is canceled, we should not perform work. + select { + case <-b.Context.Done(): + http.Error(w, "context is canceled", http.StatusServiceUnavailable) + return + default: + } + + // Generate a context for this request. + // TODO read headers to determine what kind of context to create + ctx, cancel := context.WithCancel(b.Context) + defer cancel() + + // Perform HTTP-specific context amendments. + // TODO extract e.g. trace ID + + // Decode request. + req, err := b.Codec.Decode(ctx, r.Body) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + // Execute RPC. + resp, err := b.Endpoint(ctx, req) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // Encode response. + if err := b.Codec.Encode(w, resp); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} diff --git a/addsvc/main.go b/addsvc/main.go new file mode 100644 index 000000000..701a7aac3 --- /dev/null +++ b/addsvc/main.go @@ -0,0 +1,81 @@ +package main + +import ( + "flag" + "fmt" + "log" + "net" + "net/http" + "os" + "os/signal" + "syscall" + + "github.com/peterbourgon/gokit/addsvc/pb" + + "github.com/peterbourgon/gokit/server" + "golang.org/x/net/context" + + "google.golang.org/grpc" +) + +func main() { + var ( + httpJSONAddr = flag.String("http.json.addr", ":8001", "Address for HTTP/JSON server") + grpcTCPAddr = flag.String("grpc.tcp.port", ":8002", "Address for gRPC TCP server") + ) + flag.Parse() + + // Add-service-domain + var a Add + a = pureAdd + a = logging(logWriter{}, a) + + // Server-domain + var e server.Endpoint + e = makeEndpoint(a) + // e = server.ChainableEnhancement(arg1, arg2, e) + // e = server.ChainableEnhancement(arg1, arg2, e) + + root := context.Background() + errc := make(chan error, 3) + + go func() { + errc <- interrupt() + }() + + go func() { + ln, err := net.Listen("tcp", *grpcTCPAddr) + if err != nil { + errc <- err + return + } + s := grpc.NewServer() + pb.RegisterAddServer(s, grpcBinding{e}) + log.Printf("gRPC server on TCP %s", *grpcTCPAddr) + errc <- s.Serve(ln) + }() + + go func() { + ctx, cancel := context.WithCancel(root) + defer cancel() + mux := http.NewServeMux() + mux.Handle("/add", httpBinding{ctx, jsonCodec{}, e}) + log.Printf("HTTP/JSON server on %s", *httpJSONAddr) + errc <- http.ListenAndServe(*httpJSONAddr, mux) + }() + + log.Fatal(<-errc) +} + +type logWriter struct{} + +func (logWriter) Write(p []byte) (int, error) { + log.Printf("%s", p) + return len(p), nil +} + +func interrupt() error { + c := make(chan os.Signal) + signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) + return fmt.Errorf("%s", <-c) +} diff --git a/addsvc/pb/add.pb.go b/addsvc/pb/add.pb.go new file mode 100644 index 000000000..c9876e7a6 --- /dev/null +++ b/addsvc/pb/add.pb.go @@ -0,0 +1,110 @@ +// Code generated by protoc-gen-go. +// source: add.proto +// DO NOT EDIT! + +/* +Package pb is a generated protocol buffer package. + +It is generated from these files: + add.proto + +It has these top-level messages: + AddRequest + AddReply +*/ +package pb + +import proto "github.com/golang/protobuf/proto" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal + +// The request contains two parameters. +type AddRequest struct { + A int64 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"` + B int64 `protobuf:"varint,2,opt,name=b" json:"b,omitempty"` +} + +func (m *AddRequest) Reset() { *m = AddRequest{} } +func (m *AddRequest) String() string { return proto.CompactTextString(m) } +func (*AddRequest) ProtoMessage() {} + +// The response contains the result of the calculation. +type AddReply struct { + V int64 `protobuf:"varint,1,opt,name=v" json:"v,omitempty"` +} + +func (m *AddReply) Reset() { *m = AddReply{} } +func (m *AddReply) String() string { return proto.CompactTextString(m) } +func (*AddReply) ProtoMessage() {} + +func init() { +} + +// Client API for Add service + +type AddClient interface { + // Adds two int32s. + Add(ctx context.Context, in *AddRequest, opts ...grpc.CallOption) (*AddReply, error) +} + +type addClient struct { + cc *grpc.ClientConn +} + +func NewAddClient(cc *grpc.ClientConn) AddClient { + return &addClient{cc} +} + +func (c *addClient) Add(ctx context.Context, in *AddRequest, opts ...grpc.CallOption) (*AddReply, error) { + out := new(AddReply) + err := grpc.Invoke(ctx, "/pb.Add/Add", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Add service + +type AddServer interface { + // Adds two int32s. + Add(context.Context, *AddRequest) (*AddReply, error) +} + +func RegisterAddServer(s *grpc.Server, srv AddServer) { + s.RegisterService(&_Add_serviceDesc, srv) +} + +func _Add_Add_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) { + in := new(AddRequest) + if err := proto.Unmarshal(buf, in); err != nil { + return nil, err + } + out, err := srv.(AddServer).Add(ctx, in) + if err != nil { + return nil, err + } + return out, nil +} + +var _Add_serviceDesc = grpc.ServiceDesc{ + ServiceName: "pb.Add", + HandlerType: (*AddServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Add", + Handler: _Add_Add_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, +} diff --git a/addsvc/pb/add.proto b/addsvc/pb/add.proto new file mode 100644 index 000000000..4e470f847 --- /dev/null +++ b/addsvc/pb/add.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package pb; + +// The Add service definition. +service Add { + // Adds two int32s. + rpc Add (AddRequest) returns (AddReply) {} +} + +// The request contains two parameters. +message AddRequest { + int64 a = 1; + int64 b = 2; +} + +// The response contains the result of the calculation. +message AddReply { + int64 v = 1; +} diff --git a/addsvc/request_response.go b/addsvc/request_response.go new file mode 100644 index 000000000..77936934f --- /dev/null +++ b/addsvc/request_response.go @@ -0,0 +1,13 @@ +package main + +// The request and response types should be annotated sufficiently for all +// transports we intend to use. + +type request struct { + A int64 `json:"a"` + B int64 `json:"b"` +} + +type response struct { + V int64 `json:"v"` +} diff --git a/server/server.go b/server/server.go new file mode 100644 index 000000000..6eea198bf --- /dev/null +++ b/server/server.go @@ -0,0 +1,20 @@ +package server + +import ( + "errors" + + "golang.org/x/net/context" +) + +// Request is an RPC request. +type Request interface{} + +// Response is an RPC response. +type Response interface{} + +// Endpoint is the fundamental building block of package server. +// It represents a single RPC method. +type Endpoint func(context.Context, Request) (Response, error) + +// ErrBadCast indicates a type error during decoding or encoding. +var ErrBadCast = errors.New("bad cast") diff --git a/transport/codec/codec.go b/transport/codec/codec.go new file mode 100644 index 000000000..f3a25e5d0 --- /dev/null +++ b/transport/codec/codec.go @@ -0,0 +1,17 @@ +package codec + +import ( + "io" + + "golang.org/x/net/context" + + "github.com/peterbourgon/gokit/server" +) + +// Codec defines how to decode and encode requests and responses. Decode takes +// a context because the request may be accompanied by information that needs +// to be applied there. +type Codec interface { + Decode(context.Context, io.Reader) (server.Request, error) + Encode(io.Writer, server.Response) error +} From 1a47496ae77a9e50a5a554122305d0f71ecd6b99 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Thu, 5 Mar 2015 23:38:08 +0100 Subject: [PATCH 02/38] Clarifications --- ...n_http_binding.go => http_json_binding.go} | 4 ++-- addsvc/main.go | 20 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) rename addsvc/{json_http_binding.go => http_json_binding.go} (100%) diff --git a/addsvc/json_http_binding.go b/addsvc/http_json_binding.go similarity index 100% rename from addsvc/json_http_binding.go rename to addsvc/http_json_binding.go index 4ad48fadb..e35b0af55 100644 --- a/addsvc/json_http_binding.go +++ b/addsvc/http_json_binding.go @@ -5,10 +5,10 @@ import ( "io" "net/http" - "github.com/peterbourgon/gokit/transport/codec" + "golang.org/x/net/context" "github.com/peterbourgon/gokit/server" - "golang.org/x/net/context" + "github.com/peterbourgon/gokit/transport/codec" ) type jsonCodec struct{} diff --git a/addsvc/main.go b/addsvc/main.go index 701a7aac3..f30afc17a 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -10,51 +10,53 @@ import ( "os/signal" "syscall" - "github.com/peterbourgon/gokit/addsvc/pb" - - "github.com/peterbourgon/gokit/server" "golang.org/x/net/context" - "google.golang.org/grpc" + + "github.com/peterbourgon/gokit/addsvc/pb" + "github.com/peterbourgon/gokit/server" ) func main() { var ( httpJSONAddr = flag.String("http.json.addr", ":8001", "Address for HTTP/JSON server") - grpcTCPAddr = flag.String("grpc.tcp.port", ":8002", "Address for gRPC TCP server") + grpcTCPAddr = flag.String("grpc.tcp.addr", ":8002", "Address for gRPC (TCP) server") ) flag.Parse() - // Add-service-domain + // Our business and operational domain var a Add a = pureAdd a = logging(logWriter{}, a) - // Server-domain + // `package server` domain var e server.Endpoint e = makeEndpoint(a) // e = server.ChainableEnhancement(arg1, arg2, e) // e = server.ChainableEnhancement(arg1, arg2, e) + // Mechanical stuff root := context.Background() - errc := make(chan error, 3) + errc := make(chan error) go func() { errc <- interrupt() }() + // Transport: gRPC go func() { ln, err := net.Listen("tcp", *grpcTCPAddr) if err != nil { errc <- err return } - s := grpc.NewServer() + s := grpc.NewServer() // uses its own context? pb.RegisterAddServer(s, grpcBinding{e}) log.Printf("gRPC server on TCP %s", *grpcTCPAddr) errc <- s.Serve(ln) }() + // Transport: HTTP/JSON go func() { ctx, cancel := context.WithCancel(root) defer cancel() From b5e562a44fdf9a7c53a0d86d4e0fc34c4e704648 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Thu, 5 Mar 2015 23:42:09 +0100 Subject: [PATCH 03/38] Fix proto definition --- addsvc/pb/add.pb.go | 4 ++-- addsvc/pb/add.proto | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addsvc/pb/add.pb.go b/addsvc/pb/add.pb.go index c9876e7a6..21791c60a 100644 --- a/addsvc/pb/add.pb.go +++ b/addsvc/pb/add.pb.go @@ -53,7 +53,7 @@ func init() { // Client API for Add service type AddClient interface { - // Adds two int32s. + // Adds two integers. Add(ctx context.Context, in *AddRequest, opts ...grpc.CallOption) (*AddReply, error) } @@ -77,7 +77,7 @@ func (c *addClient) Add(ctx context.Context, in *AddRequest, opts ...grpc.CallOp // Server API for Add service type AddServer interface { - // Adds two int32s. + // Adds two integers. Add(context.Context, *AddRequest) (*AddReply, error) } diff --git a/addsvc/pb/add.proto b/addsvc/pb/add.proto index 4e470f847..eca5f20e0 100644 --- a/addsvc/pb/add.proto +++ b/addsvc/pb/add.proto @@ -4,7 +4,7 @@ package pb; // The Add service definition. service Add { - // Adds two int32s. + // Adds two integers. rpc Add (AddRequest) returns (AddReply) {} } From d37eb84cdbdec31eedd9bf75feeaa0a4d1aaf66e Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 13 Mar 2015 00:23:35 +0100 Subject: [PATCH 04/38] Illustrate metrics --- addsvc/{implementations.go => add.go} | 1 + addsvc/endpoint.go | 5 ++++ addsvc/grpc_binding.go | 21 +++++++++++++++ addsvc/http_json_binding.go | 39 +++++++++++++++++++++++---- addsvc/main.go | 29 ++++++++++++++++++-- 5 files changed, 88 insertions(+), 7 deletions(-) rename addsvc/{implementations.go => add.go} (87%) diff --git a/addsvc/implementations.go b/addsvc/add.go similarity index 87% rename from addsvc/implementations.go rename to addsvc/add.go index b8deaf00e..fd6fa3850 100644 --- a/addsvc/implementations.go +++ b/addsvc/add.go @@ -12,6 +12,7 @@ func addVia(r Resource) Add { } } +// Resource represents some dependency, outside of our control. type Resource interface { Value(int64) int64 } diff --git a/addsvc/endpoint.go b/addsvc/endpoint.go index 64a504d28..22e7377f5 100644 --- a/addsvc/endpoint.go +++ b/addsvc/endpoint.go @@ -5,6 +5,11 @@ import ( "golang.org/x/net/context" ) +// makeEndpoint returns a server.Endpoint wrapping the passed Add. If Add were +// an interface with multiple methods, we'd need individual endpoints for +// each. +// +// This function is just boiler-plate; in theory, it could be generated. func makeEndpoint(a Add) server.Endpoint { return func(ctx context.Context, req server.Request) (server.Response, error) { addReq, ok := req.(*request) diff --git a/addsvc/grpc_binding.go b/addsvc/grpc_binding.go index fbb8d0c8a..448a81e7a 100644 --- a/addsvc/grpc_binding.go +++ b/addsvc/grpc_binding.go @@ -1,11 +1,16 @@ package main import ( + "time" + "github.com/peterbourgon/gokit/addsvc/pb" + "github.com/peterbourgon/gokit/metrics" "github.com/peterbourgon/gokit/server" "golang.org/x/net/context" ) +// A binding wraps an Endpoint so that it's usable by a transport. grpcBinding +// makes an Endpoint usable over gRPC. type grpcBinding struct{ server.Endpoint } // Add implements the proto3 AddServer by forwarding to the wrapped Endpoint. @@ -25,3 +30,19 @@ func (b grpcBinding) Add(ctx context.Context, req *pb.AddRequest) (*pb.AddReply, V: resp.V, }, nil } + +func grpcInstrument(requests metrics.Counter, duration metrics.Histogram, next pb.AddServer) pb.AddServer { + return grpcInstrumented{requests, duration, next} +} + +type grpcInstrumented struct { + requests metrics.Counter + duration metrics.Histogram + next pb.AddServer +} + +func (i grpcInstrumented) Add(ctx context.Context, req *pb.AddRequest) (*pb.AddReply, error) { + i.requests.Add(1) + defer func(begin time.Time) { i.duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) + return i.next.Add(ctx, req) +} diff --git a/addsvc/http_json_binding.go b/addsvc/http_json_binding.go index e35b0af55..0c6fd507e 100644 --- a/addsvc/http_json_binding.go +++ b/addsvc/http_json_binding.go @@ -4,29 +4,41 @@ import ( "encoding/json" "io" "net/http" + "time" "golang.org/x/net/context" + "github.com/peterbourgon/gokit/metrics" "github.com/peterbourgon/gokit/server" "github.com/peterbourgon/gokit/transport/codec" ) +// jsonCodec decodes and encodes requests and responses respectively as JSON. +// It requires that the (package main) request and response structs support +// JSON de/serialization. +// +// This type is mostly boiler-plate; in theory, it could be generated. type jsonCodec struct{} func (jsonCodec) Decode(_ context.Context, r io.Reader) (server.Request, error) { var req request - err := json.NewDecoder(r).Decode(req) - return req, err + err := json.NewDecoder(r).Decode(&req) + return &req, err } func (jsonCodec) Encode(w io.Writer, resp server.Response) error { return json.NewEncoder(w).Encode(resp) } +// A binding wraps an Endpoint so that it's usable by a transport. httpBinding +// makes an Endpoint usable over HTTP. It combines a parent context, a codec, +// and an endpoint to expose. It implements http.Handler by decoding a request +// from the HTTP request body, and encoding a response to the response writer. type httpBinding struct { - context.Context - codec.Codec - server.Endpoint + context.Context // parent context + codec.Codec // how to decode requests and encode responses + contentType string // what we report as the response ContentType + server.Endpoint // the endpoint being bound } func (b httpBinding) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -61,8 +73,25 @@ func (b httpBinding) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Encode response. + w.Header().Set("Content-Type", b.contentType) if err := b.Codec.Encode(w, resp); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } } + +func httpInstrument(requests metrics.Counter, duration metrics.Histogram, next http.Handler) http.Handler { + return httpInstrumented{requests, duration, next} +} + +type httpInstrumented struct { + requests metrics.Counter + duration metrics.Histogram + next http.Handler +} + +func (i httpInstrumented) ServeHTTP(w http.ResponseWriter, r *http.Request) { + i.requests.Add(1) + defer func(begin time.Time) { i.duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) + i.next.ServeHTTP(w, r) +} diff --git a/addsvc/main.go b/addsvc/main.go index f30afc17a..2d8420228 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -3,17 +3,22 @@ package main import ( "flag" "fmt" + "io/ioutil" "log" "net" "net/http" "os" "os/signal" "syscall" + "time" "golang.org/x/net/context" "google.golang.org/grpc" "github.com/peterbourgon/gokit/addsvc/pb" + "github.com/peterbourgon/gokit/metrics" + "github.com/peterbourgon/gokit/metrics/expvar" + "github.com/peterbourgon/gokit/metrics/statsd" "github.com/peterbourgon/gokit/server" ) @@ -35,6 +40,16 @@ func main() { // e = server.ChainableEnhancement(arg1, arg2, e) // e = server.ChainableEnhancement(arg1, arg2, e) + // `package metrics` domain + requests := metrics.NewMultiCounter( + expvar.NewCounter("requests"), + statsd.NewCounter(ioutil.Discard, "requests", time.Second), + ) + duration := metrics.NewMultiHistogram( + expvar.NewHistogram("duration_ns", 0, 100000000, 3), + statsd.NewHistogram(ioutil.Discard, "duration_ns", time.Second), + ) + // Mechanical stuff root := context.Background() errc := make(chan error) @@ -51,7 +66,12 @@ func main() { return } s := grpc.NewServer() // uses its own context? - pb.RegisterAddServer(s, grpcBinding{e}) + + var addServer pb.AddServer + addServer = grpcBinding{e} + addServer = grpcInstrument(requests, duration, addServer) + + pb.RegisterAddServer(s, addServer) log.Printf("gRPC server on TCP %s", *grpcTCPAddr) errc <- s.Serve(ln) }() @@ -61,7 +81,12 @@ func main() { ctx, cancel := context.WithCancel(root) defer cancel() mux := http.NewServeMux() - mux.Handle("/add", httpBinding{ctx, jsonCodec{}, e}) + + var handler http.Handler + handler = httpBinding{ctx, jsonCodec{}, "application/json", e} + handler = httpInstrument(requests, duration, handler) + + mux.Handle("/add", handler) log.Printf("HTTP/JSON server on %s", *httpJSONAddr) errc <- http.ListenAndServe(*httpJSONAddr, mux) }() From 1c2aff67b316a3437ef5e2438828691b48309016 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 13 Mar 2015 00:30:12 +0100 Subject: [PATCH 05/38] Per-transport fielded metrics --- addsvc/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addsvc/main.go b/addsvc/main.go index 2d8420228..183d560ae 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -66,10 +66,11 @@ func main() { return } s := grpc.NewServer() // uses its own context? + field := metrics.Field{Key: "transport", Value: "grpc"} var addServer pb.AddServer addServer = grpcBinding{e} - addServer = grpcInstrument(requests, duration, addServer) + addServer = grpcInstrument(requests.With(field), duration.With(field), addServer) pb.RegisterAddServer(s, addServer) log.Printf("gRPC server on TCP %s", *grpcTCPAddr) @@ -81,10 +82,11 @@ func main() { ctx, cancel := context.WithCancel(root) defer cancel() mux := http.NewServeMux() + field := metrics.Field{Key: "transport", Value: "http"} var handler http.Handler handler = httpBinding{ctx, jsonCodec{}, "application/json", e} - handler = httpInstrument(requests, duration, handler) + handler = httpInstrument(requests.With(field), duration.With(field), handler) mux.Handle("/add", handler) log.Printf("HTTP/JSON server on %s", *httpJSONAddr) From 760967252c164b82a91067cd603e2194f90b57cc Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Sat, 14 Mar 2015 11:38:50 +0100 Subject: [PATCH 06/38] addsvc: protobuf3 compile script --- addsvc/pb/compile.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 addsvc/pb/compile.sh diff --git a/addsvc/pb/compile.sh b/addsvc/pb/compile.sh new file mode 100755 index 000000000..6fce4a588 --- /dev/null +++ b/addsvc/pb/compile.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# https://github.com/grpc/grpc-common/tree/master/go +protoc add.proto --go_out=plugins=grpc:. From c937cf4caa06e2599f0c418ba1b04b853ff5e9e6 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Sat, 14 Mar 2015 11:39:09 +0100 Subject: [PATCH 07/38] addsvc: add Thrift bindings --- addsvc/main.go | 62 ++- addsvc/thrift/add.thrift | 7 + addsvc/thrift/compile.sh | 4 + .../add_service-remote/add_service-remote.go | 144 ++++++ addsvc/thrift/gen-go/add/addservice.go | 433 ++++++++++++++++++ addsvc/thrift/gen-go/add/constants.go | 18 + addsvc/thrift/gen-go/add/ttypes.go | 105 +++++ addsvc/thrift_binding.go | 49 ++ 8 files changed, 820 insertions(+), 2 deletions(-) create mode 100644 addsvc/thrift/add.thrift create mode 100755 addsvc/thrift/compile.sh create mode 100755 addsvc/thrift/gen-go/add/add_service-remote/add_service-remote.go create mode 100644 addsvc/thrift/gen-go/add/addservice.go create mode 100644 addsvc/thrift/gen-go/add/constants.go create mode 100644 addsvc/thrift/gen-go/add/ttypes.go create mode 100644 addsvc/thrift_binding.go diff --git a/addsvc/main.go b/addsvc/main.go index 183d560ae..eea91f9eb 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -12,10 +12,13 @@ import ( "syscall" "time" + "git.apache.org/thrift.git/lib/go/thrift" + "golang.org/x/net/context" "google.golang.org/grpc" "github.com/peterbourgon/gokit/addsvc/pb" + thriftadd "github.com/peterbourgon/gokit/addsvc/thrift/gen-go/add" "github.com/peterbourgon/gokit/metrics" "github.com/peterbourgon/gokit/metrics/expvar" "github.com/peterbourgon/gokit/metrics/statsd" @@ -24,8 +27,12 @@ import ( func main() { var ( - httpJSONAddr = flag.String("http.json.addr", ":8001", "Address for HTTP/JSON server") - grpcTCPAddr = flag.String("grpc.tcp.addr", ":8002", "Address for gRPC (TCP) server") + httpJSONAddr = flag.String("http.json.addr", ":8001", "Address for HTTP/JSON server") + grpcTCPAddr = flag.String("grpc.tcp.addr", ":8002", "Address for gRPC (TCP) server") + thriftTCPAddr = flag.String("thrift.tcp.addr", ":8003", "Address for Thrift (TCP) server") + thriftProtocol = flag.String("thrift.protocol", "binary", "binary, compact, json, simplejson") + thriftBufferSize = flag.Int("thrift.transport.bufsz", 0, "Thrift transport buffer size (0 = unbuffered)") + thriftFramed = flag.Bool("thrift.framed", false, "use framed transport") ) flag.Parse() @@ -93,6 +100,57 @@ func main() { errc <- http.ListenAndServe(*httpJSONAddr, mux) }() + // Transport: Thrift + go func() { + ctx, cancel := context.WithCancel(root) + defer cancel() + + var protocolFactory thrift.TProtocolFactory + switch *thriftProtocol { + case "binary": + protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() + case "compact": + protocolFactory = thrift.NewTCompactProtocolFactory() + case "json": + protocolFactory = thrift.NewTJSONProtocolFactory() + case "simplejson": + protocolFactory = thrift.NewTSimpleJSONProtocolFactory() + default: + errc <- fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol) + return + } + + var transportFactory thrift.TTransportFactory + if *thriftBufferSize > 0 { + transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize) + } else { + transportFactory = thrift.NewTTransportFactory() + } + + if *thriftFramed { + transportFactory = thrift.NewTFramedTransportFactory(transportFactory) + } + + transport, err := thrift.NewTServerSocket(*thriftTCPAddr) + if err != nil { + errc <- err + return + } + + var handler thriftadd.AddService + handler = thriftBinding{ctx, e} + field := metrics.Field{Key: "transport", Value: "thrift"} + handler = thriftInstrument(requests.With(field), duration.With(field), handler) + + log.Printf("Thrift (TCP) server on %s", *thriftTCPAddr) + errc <- thrift.NewTSimpleServer4( + thriftadd.NewAddServiceProcessor(thriftBinding{ctx, e}), + transport, + transportFactory, + protocolFactory, + ).Serve() + }() + log.Fatal(<-errc) } diff --git a/addsvc/thrift/add.thrift b/addsvc/thrift/add.thrift new file mode 100644 index 000000000..969c10421 --- /dev/null +++ b/addsvc/thrift/add.thrift @@ -0,0 +1,7 @@ +struct AddReply { + 1: i64 value +} + +service AddService { + AddReply Add(1: i64 a, 2: i64 b) +} diff --git a/addsvc/thrift/compile.sh b/addsvc/thrift/compile.sh new file mode 100755 index 000000000..27e8341a9 --- /dev/null +++ b/addsvc/thrift/compile.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +# https://thrift.apache.org/tutorial/go +thrift -r --gen go add.thrift diff --git a/addsvc/thrift/gen-go/add/add_service-remote/add_service-remote.go b/addsvc/thrift/gen-go/add/add_service-remote/add_service-remote.go new file mode 100755 index 000000000..9835c8f0f --- /dev/null +++ b/addsvc/thrift/gen-go/add/add_service-remote/add_service-remote.go @@ -0,0 +1,144 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package main + +import ( + "add" + "flag" + "fmt" + "git.apache.org/thrift.git/lib/go/thrift" + "math" + "net" + "net/url" + "os" + "strconv" + "strings" +) + +func Usage() { + fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") + flag.PrintDefaults() + fmt.Fprintln(os.Stderr, "\nFunctions:") + fmt.Fprintln(os.Stderr, " AddReply Add(i64 a, i64 b)") + fmt.Fprintln(os.Stderr) + os.Exit(0) +} + +func main() { + flag.Usage = Usage + var host string + var port int + var protocol string + var urlString string + var framed bool + var useHttp bool + var parsedUrl url.URL + var trans thrift.TTransport + _ = strconv.Atoi + _ = math.Abs + flag.Usage = Usage + flag.StringVar(&host, "h", "localhost", "Specify host and port") + flag.IntVar(&port, "p", 9090, "Specify port") + flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") + flag.StringVar(&urlString, "u", "", "Specify the url") + flag.BoolVar(&framed, "framed", false, "Use framed transport") + flag.BoolVar(&useHttp, "http", false, "Use http") + flag.Parse() + + if len(urlString) > 0 { + parsedUrl, err := url.Parse(urlString) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + host = parsedUrl.Host + useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" + } else if useHttp { + _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + } + + cmd := flag.Arg(0) + var err error + if useHttp { + trans, err = thrift.NewTHttpClient(parsedUrl.String()) + } else { + portStr := fmt.Sprint(port) + if strings.Contains(host, ":") { + host, portStr, err = net.SplitHostPort(host) + if err != nil { + fmt.Fprintln(os.Stderr, "error with host:", err) + os.Exit(1) + } + } + trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) + if err != nil { + fmt.Fprintln(os.Stderr, "error resolving address:", err) + os.Exit(1) + } + if framed { + trans = thrift.NewTFramedTransport(trans) + } + } + if err != nil { + fmt.Fprintln(os.Stderr, "Error creating transport", err) + os.Exit(1) + } + defer trans.Close() + var protocolFactory thrift.TProtocolFactory + switch protocol { + case "compact": + protocolFactory = thrift.NewTCompactProtocolFactory() + break + case "simplejson": + protocolFactory = thrift.NewTSimpleJSONProtocolFactory() + break + case "json": + protocolFactory = thrift.NewTJSONProtocolFactory() + break + case "binary", "": + protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() + break + default: + fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) + Usage() + os.Exit(1) + } + client := add.NewAddServiceClientFactory(trans, protocolFactory) + if err := trans.Open(); err != nil { + fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) + os.Exit(1) + } + + switch cmd { + case "Add": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "Add requires 2 args") + flag.Usage() + } + argvalue0, err4 := (strconv.ParseInt(flag.Arg(1), 10, 64)) + if err4 != nil { + Usage() + return + } + value0 := argvalue0 + argvalue1, err5 := (strconv.ParseInt(flag.Arg(2), 10, 64)) + if err5 != nil { + Usage() + return + } + value1 := argvalue1 + fmt.Print(client.Add(value0, value1)) + fmt.Print("\n") + break + case "": + Usage() + break + default: + fmt.Fprintln(os.Stderr, "Invalid function ", cmd) + } +} diff --git a/addsvc/thrift/gen-go/add/addservice.go b/addsvc/thrift/gen-go/add/addservice.go new file mode 100644 index 000000000..f986f110c --- /dev/null +++ b/addsvc/thrift/gen-go/add/addservice.go @@ -0,0 +1,433 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package add + +import ( + "bytes" + "fmt" + "git.apache.org/thrift.git/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +type AddService interface { + // Parameters: + // - A + // - B + Add(a int64, b int64) (r *AddReply, err error) +} + +type AddServiceClient struct { + Transport thrift.TTransport + ProtocolFactory thrift.TProtocolFactory + InputProtocol thrift.TProtocol + OutputProtocol thrift.TProtocol + SeqId int32 +} + +func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient { + return &AddServiceClient{Transport: t, + ProtocolFactory: f, + InputProtocol: f.GetProtocol(t), + OutputProtocol: f.GetProtocol(t), + SeqId: 0, + } +} + +func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient { + return &AddServiceClient{Transport: t, + ProtocolFactory: nil, + InputProtocol: iprot, + OutputProtocol: oprot, + SeqId: 0, + } +} + +// Parameters: +// - A +// - B +func (p *AddServiceClient) Add(a int64, b int64) (r *AddReply, err error) { + if err = p.sendAdd(a, b); err != nil { + return + } + return p.recvAdd() +} + +func (p *AddServiceClient) sendAdd(a int64, b int64) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("Add", thrift.CALL, p.SeqId); err != nil { + return + } + args := AddArgs{ + A: a, + B: b, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *AddServiceClient) recvAdd() (value *AddReply, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error1 error + error1, err = error0.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error1 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Add failed: out of sequence response") + return + } + result := AddResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +type AddServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler AddService +} + +func (p *AddServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *AddServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *AddServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewAddServiceProcessor(handler AddService) *AddServiceProcessor { + + self2 := &AddServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self2.processorMap["Add"] = &addServiceProcessorAdd{handler: handler} + return self2 +} + +func (p *AddServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x3 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x3.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, x3 + +} + +type addServiceProcessorAdd struct { + handler AddService +} + +func (p *addServiceProcessorAdd) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := AddArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("Add", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := AddResult{} + var retval *AddReply + var err2 error + if retval, err2 = p.handler.Add(args.A, args.B); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Add: "+err2.Error()) + oprot.WriteMessageBegin("Add", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("Add", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +// HELPER FUNCTIONS AND STRUCTURES + +type AddArgs struct { + A int64 `thrift:"a,1" json:"a"` + B int64 `thrift:"b,2" json:"b"` +} + +func NewAddArgs() *AddArgs { + return &AddArgs{} +} + +func (p *AddArgs) GetA() int64 { + return p.A +} + +func (p *AddArgs) GetB() int64 { + return p.B +} +func (p *AddArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *AddArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.A = v + } + return nil +} + +func (p *AddArgs) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.B = v + } + return nil +} + +func (p *AddArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Add_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *AddArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("a", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:a: %s", p, err) + } + if err := oprot.WriteI64(int64(p.A)); err != nil { + return fmt.Errorf("%T.a (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:a: %s", p, err) + } + return err +} + +func (p *AddArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("b", thrift.I64, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:b: %s", p, err) + } + if err := oprot.WriteI64(int64(p.B)); err != nil { + return fmt.Errorf("%T.b (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:b: %s", p, err) + } + return err +} + +func (p *AddArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AddArgs(%+v)", *p) +} + +type AddResult struct { + Success *AddReply `thrift:"success,0" json:"success"` +} + +func NewAddResult() *AddResult { + return &AddResult{} +} + +var AddResult_Success_DEFAULT *AddReply + +func (p *AddResult) GetSuccess() *AddReply { + if !p.IsSetSuccess() { + return AddResult_Success_DEFAULT + } + return p.Success +} +func (p *AddResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *AddResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *AddResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = &AddReply{} + if err := p.Success.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Success, err) + } + return nil +} + +func (p *AddResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Add_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *AddResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := p.Success.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Success, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *AddResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AddResult(%+v)", *p) +} diff --git a/addsvc/thrift/gen-go/add/constants.go b/addsvc/thrift/gen-go/add/constants.go new file mode 100644 index 000000000..82134cb2e --- /dev/null +++ b/addsvc/thrift/gen-go/add/constants.go @@ -0,0 +1,18 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package add + +import ( + "bytes" + "fmt" + "git.apache.org/thrift.git/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +func init() { +} diff --git a/addsvc/thrift/gen-go/add/ttypes.go b/addsvc/thrift/gen-go/add/ttypes.go new file mode 100644 index 000000000..5bb531796 --- /dev/null +++ b/addsvc/thrift/gen-go/add/ttypes.go @@ -0,0 +1,105 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package add + +import ( + "bytes" + "fmt" + "git.apache.org/thrift.git/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var GoUnusedProtection__ int + +type AddReply struct { + Value int64 `thrift:"value,1" json:"value"` +} + +func NewAddReply() *AddReply { + return &AddReply{} +} + +func (p *AddReply) GetValue() int64 { + return p.Value +} +func (p *AddReply) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *AddReply) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Value = v + } + return nil +} + +func (p *AddReply) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("AddReply"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *AddReply) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("value", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:value: %s", p, err) + } + if err := oprot.WriteI64(int64(p.Value)); err != nil { + return fmt.Errorf("%T.value (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:value: %s", p, err) + } + return err +} + +func (p *AddReply) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AddReply(%+v)", *p) +} diff --git a/addsvc/thrift_binding.go b/addsvc/thrift_binding.go new file mode 100644 index 000000000..3f5aff27b --- /dev/null +++ b/addsvc/thrift_binding.go @@ -0,0 +1,49 @@ +package main + +import ( + "time" + + "golang.org/x/net/context" + + thriftadd "github.com/peterbourgon/gokit/addsvc/thrift/gen-go/add" + "github.com/peterbourgon/gokit/metrics" + "github.com/peterbourgon/gokit/server" +) + +// A binding wraps an Endpoint so that it's usable by a transport. +// thriftBinding makes an Endpoint usable over Thrift. +type thriftBinding struct { + context.Context + server.Endpoint +} + +// Add implements Thrift's AddService interface. +func (tb thriftBinding) Add(a, b int64) (*thriftadd.AddReply, error) { + r, err := tb.Endpoint(tb.Context, request{a, b}) + if err != nil { + return nil, err + } + + resp, ok := r.(*response) + if !ok { + return nil, server.ErrBadCast + } + + return &thriftadd.AddReply{Value: resp.V}, nil +} + +func thriftInstrument(requests metrics.Counter, duration metrics.Histogram, next thriftadd.AddService) thriftadd.AddService { + return thriftInstrumented{requests, duration, next} +} + +type thriftInstrumented struct { + requests metrics.Counter + duration metrics.Histogram + next thriftadd.AddService +} + +func (i thriftInstrumented) Add(a, b int64) (*thriftadd.AddReply, error) { + i.requests.Add(1) + defer func(begin time.Time) { i.duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) + return i.next.Add(a, b) +} From 1a0510c05448b92936860556e3ae3afb4aab31bb Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Sat, 14 Mar 2015 11:50:26 +0100 Subject: [PATCH 08/38] server: context checking to Endpoint --- addsvc/endpoint.go | 6 ++++++ addsvc/http_json_binding.go | 17 ++--------------- server/server.go | 4 ++++ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/addsvc/endpoint.go b/addsvc/endpoint.go index 22e7377f5..444f42f09 100644 --- a/addsvc/endpoint.go +++ b/addsvc/endpoint.go @@ -12,6 +12,12 @@ import ( // This function is just boiler-plate; in theory, it could be generated. func makeEndpoint(a Add) server.Endpoint { return func(ctx context.Context, req server.Request) (server.Response, error) { + select { + case <-ctx.Done(): + return nil, server.ErrContextCanceled + default: + } + addReq, ok := req.(*request) if !ok { return nil, server.ErrBadCast diff --git a/addsvc/http_json_binding.go b/addsvc/http_json_binding.go index 0c6fd507e..b538b41f6 100644 --- a/addsvc/http_json_binding.go +++ b/addsvc/http_json_binding.go @@ -42,31 +42,18 @@ type httpBinding struct { } func (b httpBinding) ServeHTTP(w http.ResponseWriter, r *http.Request) { - // If the context is canceled, we should not perform work. - select { - case <-b.Context.Done(): - http.Error(w, "context is canceled", http.StatusServiceUnavailable) - return - default: - } - - // Generate a context for this request. - // TODO read headers to determine what kind of context to create - ctx, cancel := context.WithCancel(b.Context) - defer cancel() - // Perform HTTP-specific context amendments. // TODO extract e.g. trace ID // Decode request. - req, err := b.Codec.Decode(ctx, r.Body) + req, err := b.Codec.Decode(b.Context, r.Body) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } // Execute RPC. - resp, err := b.Endpoint(ctx, req) + resp, err := b.Endpoint(b.Context, req) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/server/server.go b/server/server.go index 6eea198bf..a1542027d 100644 --- a/server/server.go +++ b/server/server.go @@ -18,3 +18,7 @@ type Endpoint func(context.Context, Request) (Response, error) // ErrBadCast indicates a type error during decoding or encoding. var ErrBadCast = errors.New("bad cast") + +// ErrContextCanceled indicates a controlling context was canceled before the +// request could be served. +var ErrContextCanceled = errors.New("context was canceled") From bc6b60e02a8f4f9181f7171e8be9bc8be968872f Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Sat, 14 Mar 2015 11:53:10 +0100 Subject: [PATCH 09/38] addsvc: small rename --- addsvc/{http_json_binding.go => httpjson_binding.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename addsvc/{http_json_binding.go => httpjson_binding.go} (100%) diff --git a/addsvc/http_json_binding.go b/addsvc/httpjson_binding.go similarity index 100% rename from addsvc/http_json_binding.go rename to addsvc/httpjson_binding.go From b8402c6a4f0719bc80a2d3289191849046fe87e8 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 17 Mar 2015 09:55:07 +0100 Subject: [PATCH 10/38] Many server and transport enhancements - zipkin: helpers for working with Zipkin traces - server/gate: example of a composable Endpoint middleware - transport/cors: example of a composable HTTP middleware - Integration with addsvc --- addsvc/httpjson_binding.go | 10 +++-- addsvc/main.go | 9 ++++- server/gate.go | 16 ++++++++ server/zipkin/zipkin.go | 55 +++++++++++++++++++++++++ transport/codec/codec.go | 6 +-- transport/http/cors/cors.go | 81 +++++++++++++++++++++++++++++++++++++ 6 files changed, 169 insertions(+), 8 deletions(-) create mode 100644 server/gate.go create mode 100644 server/zipkin/zipkin.go create mode 100644 transport/http/cors/cors.go diff --git a/addsvc/httpjson_binding.go b/addsvc/httpjson_binding.go index b538b41f6..735e47d79 100644 --- a/addsvc/httpjson_binding.go +++ b/addsvc/httpjson_binding.go @@ -10,6 +10,7 @@ import ( "github.com/peterbourgon/gokit/metrics" "github.com/peterbourgon/gokit/server" + "github.com/peterbourgon/gokit/server/zipkin" "github.com/peterbourgon/gokit/transport/codec" ) @@ -20,10 +21,10 @@ import ( // This type is mostly boiler-plate; in theory, it could be generated. type jsonCodec struct{} -func (jsonCodec) Decode(_ context.Context, r io.Reader) (server.Request, error) { +func (jsonCodec) Decode(ctx context.Context, r io.Reader) (server.Request, context.Context, error) { var req request err := json.NewDecoder(r).Decode(&req) - return &req, err + return &req, ctx, err } func (jsonCodec) Encode(w io.Writer, resp server.Response) error { @@ -43,14 +44,15 @@ type httpBinding struct { func (b httpBinding) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Perform HTTP-specific context amendments. - // TODO extract e.g. trace ID + b.Context = zipkin.GetHeaders(b.Context, r.Header) // Decode request. - req, err := b.Codec.Decode(b.Context, r.Body) + req, ctx, err := b.Codec.Decode(b.Context, r.Body) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } + b.Context = ctx // Execute RPC. resp, err := b.Endpoint(b.Context, req) diff --git a/addsvc/main.go b/addsvc/main.go index eea91f9eb..4536e7c74 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -23,6 +23,8 @@ import ( "github.com/peterbourgon/gokit/metrics/expvar" "github.com/peterbourgon/gokit/metrics/statsd" "github.com/peterbourgon/gokit/server" + "github.com/peterbourgon/gokit/server/zipkin" + "github.com/peterbourgon/gokit/transport/http/cors" ) func main() { @@ -44,7 +46,7 @@ func main() { // `package server` domain var e server.Endpoint e = makeEndpoint(a) - // e = server.ChainableEnhancement(arg1, arg2, e) + e = server.Gate(zipkin.RequireInContext, e) // must have Zipkin headers // e = server.ChainableEnhancement(arg1, arg2, e) // `package metrics` domain @@ -78,6 +80,8 @@ func main() { var addServer pb.AddServer addServer = grpcBinding{e} addServer = grpcInstrument(requests.With(field), duration.With(field), addServer) + // Note that this will always fail, because the Endpoint is gated on + // Zipkin headers, and we don't extract them from the gRPC request. pb.RegisterAddServer(s, addServer) log.Printf("gRPC server on TCP %s", *grpcTCPAddr) @@ -94,6 +98,7 @@ func main() { var handler http.Handler handler = httpBinding{ctx, jsonCodec{}, "application/json", e} handler = httpInstrument(requests.With(field), duration.With(field), handler) + handler = cors.Middleware(cors.MaxAge(5 * time.Minute))(handler) mux.Handle("/add", handler) log.Printf("HTTP/JSON server on %s", *httpJSONAddr) @@ -141,6 +146,8 @@ func main() { handler = thriftBinding{ctx, e} field := metrics.Field{Key: "transport", Value: "thrift"} handler = thriftInstrument(requests.With(field), duration.With(field), handler) + // Note that this will always fail, because the Endpoint is gated on + // Zipkin headers, and we don't extract them from the Thrift request. log.Printf("Thrift (TCP) server on %s", *thriftTCPAddr) errc <- thrift.NewTSimpleServer4( diff --git a/server/gate.go b/server/gate.go new file mode 100644 index 000000000..3264dc8b5 --- /dev/null +++ b/server/gate.go @@ -0,0 +1,16 @@ +package server + +import ( + "golang.org/x/net/context" +) + +// Gate wraps an endpoint with a gating function. If the gating function +// returns an error, the request is aborted, and that error is returned. +func Gate(allow func(context.Context, Request) error, next Endpoint) Endpoint { + return func(ctx context.Context, req Request) (Response, error) { + if err := allow(ctx, req); err != nil { + return nil, err + } + return next(ctx, req) + } +} diff --git a/server/zipkin/zipkin.go b/server/zipkin/zipkin.go new file mode 100644 index 000000000..096b26a8c --- /dev/null +++ b/server/zipkin/zipkin.go @@ -0,0 +1,55 @@ +package zipkin + +import ( + "errors" + "net/http" + + "github.com/peterbourgon/gokit/server" + + "golang.org/x/net/context" +) + +const ( + // https://github.com/racker/tryfer#headers + traceIDHTTPHeader = "X-B3-TraceId" + spanIDHTTPHeader = "X-B3-SpanId" + parentSpanIDHTTPHeader = "X-B3-ParentSpanId" + + // TraceIDContextKey holds the Zipkin TraceId, if available. + TraceIDContextKey = "Zipkin-Trace-ID" + + // SpanIDContextKey holds the Zipkin SpanId, if available. + SpanIDContextKey = "Zipkin-Span-ID" + + // ParentSpanIDContextKey holds the Zipkin ParentSpanId, if available. + ParentSpanIDContextKey = "Zipkin-Parent-Span-ID" +) + +// ErrMissingZipkinHeaders is returned when a context doesn't contain Zipkin +// trace, span, or parent span IDs. +var ErrMissingZipkinHeaders = errors.New("Zipkin headers missing from request context") + +// GetHeaders extracts Zipkin headers from the HTTP request, and populates +// them into the context, if present. +func GetHeaders(ctx context.Context, header http.Header) context.Context { + if val := header.Get(traceIDHTTPHeader); val != "" { + ctx = context.WithValue(ctx, TraceIDContextKey, val) + } + if val := header.Get(spanIDHTTPHeader); val != "" { + ctx = context.WithValue(ctx, SpanIDContextKey, val) + } + if val := header.Get(parentSpanIDHTTPHeader); val != "" { + ctx = context.WithValue(ctx, ParentSpanIDContextKey, val) + } + return ctx +} + +// RequireInContext implements the server.Gate allow func by checking if the +// context contains extracted Zipkin headers. Contexts without all headers +// aren't allowed to proceed. +func RequireInContext(ctx context.Context, _ server.Request) error { + if ctx.Value(TraceIDContextKey) == nil || ctx.Value(SpanIDContextKey) == nil || ctx.Value(ParentSpanIDContextKey) == nil { + return ErrMissingZipkinHeaders + } + return nil +} diff --git a/transport/codec/codec.go b/transport/codec/codec.go index f3a25e5d0..6df01752f 100644 --- a/transport/codec/codec.go +++ b/transport/codec/codec.go @@ -9,9 +9,9 @@ import ( ) // Codec defines how to decode and encode requests and responses. Decode takes -// a context because the request may be accompanied by information that needs -// to be applied there. +// and returns a context because the request may be accompanied by information +// that needs to be applied there. type Codec interface { - Decode(context.Context, io.Reader) (server.Request, error) + Decode(context.Context, io.Reader) (server.Request, context.Context, error) Encode(io.Writer, server.Response) error } diff --git a/transport/http/cors/cors.go b/transport/http/cors/cors.go new file mode 100644 index 000000000..ad1a64630 --- /dev/null +++ b/transport/http/cors/cors.go @@ -0,0 +1,81 @@ +package cors + +import ( + "net/http" + "strconv" + "strings" + "time" +) + +// Option changes CORS behavior. +type Option func(*options) + +// MaxAge sets the Access-Control-Max-Age header for OPTIONS requests whose +// Access-Control-Request-Method is GET. By default, max age is 10 minutes. +func MaxAge(age time.Duration) Option { + return func(o *options) { o.maxAge = age } +} + +// AllowMethods sets Access-Control-Allow-Methods. By default, only the GET +// method is allowed. +func AllowMethods(methods ...string) Option { + return func(o *options) { o.allowMethods = methods } +} + +// AllowHeaders sets Access-Control-Allow-Headers. By default, the headers +// Accept, Accept-Encoding, Authorization, Content-Type, and Origin are +// allowed. +func AllowHeaders(headers ...string) Option { + return func(o *options) { o.allowHeaders = headers } +} + +// AllowOrigin sets Access-Control-Allow-Origin. By default, * is allowed. +func AllowOrigin(origin string) Option { + return func(o *options) { o.allowOrigin = origin } +} + +type options struct { + maxAge time.Duration + allowMethods []string + allowHeaders []string + allowOrigin string +} + +// Middleware returns a chainable HTTP handler that applies headers to allow +// CORS related requests. +func Middleware(opts ...Option) func(http.Handler) http.Handler { + o := &options{ + maxAge: 10 * time.Minute, + allowMethods: []string{"GET"}, + allowHeaders: []string{"Accept", "Accept-Encoding", "Authorization", "Content-Type", "Origin"}, + allowOrigin: "*", + } + for _, opt := range opts { + opt(o) + } + + // via https://github.com/streadway/handy/blob/master/cors/cors.go + + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Access-Control-Allow-Methods", strings.Join(o.allowMethods, ", ")) + w.Header().Set("Access-Control-Allow-Headers", strings.Join(o.allowHeaders, ", ")) + w.Header().Set("Access-Control-Allow-Origin", o.allowOrigin) + + switch r.Method { + case "OPTIONS": + if r.Header.Get("Access-Control-Request-Method") == "GET" { + w.Header().Set("Access-Control-Max-Age", strconv.Itoa(int(o.maxAge/time.Second))) + return + } + w.WriteHeader(http.StatusUnauthorized) + + case "HEAD", "GET": + next.ServeHTTP(w, r) + + default: + w.WriteHeader(http.StatusMethodNotAllowed) + } + }) + } +} From 8f82101c40ddd1867f78a9b8ea80b264b1e59cde Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 18 Mar 2015 12:56:42 +0100 Subject: [PATCH 11/38] Consistently use alice-style chainable middlewares --- addsvc/grpc_binding.go | 6 ++++-- addsvc/httpjson_binding.go | 22 ++++++++-------------- addsvc/main.go | 9 ++++----- addsvc/thrift_binding.go | 6 ++++-- server/gate.go | 14 ++++++++------ 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/addsvc/grpc_binding.go b/addsvc/grpc_binding.go index 448a81e7a..c04ef2fa7 100644 --- a/addsvc/grpc_binding.go +++ b/addsvc/grpc_binding.go @@ -31,8 +31,10 @@ func (b grpcBinding) Add(ctx context.Context, req *pb.AddRequest) (*pb.AddReply, }, nil } -func grpcInstrument(requests metrics.Counter, duration metrics.Histogram, next pb.AddServer) pb.AddServer { - return grpcInstrumented{requests, duration, next} +func grpcInstrument(requests metrics.Counter, duration metrics.Histogram) func(pb.AddServer) pb.AddServer { + return func(next pb.AddServer) pb.AddServer { + return grpcInstrumented{requests, duration, next} + } } type grpcInstrumented struct { diff --git a/addsvc/httpjson_binding.go b/addsvc/httpjson_binding.go index 735e47d79..60dcab7ed 100644 --- a/addsvc/httpjson_binding.go +++ b/addsvc/httpjson_binding.go @@ -69,18 +69,12 @@ func (b httpBinding) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -func httpInstrument(requests metrics.Counter, duration metrics.Histogram, next http.Handler) http.Handler { - return httpInstrumented{requests, duration, next} -} - -type httpInstrumented struct { - requests metrics.Counter - duration metrics.Histogram - next http.Handler -} - -func (i httpInstrumented) ServeHTTP(w http.ResponseWriter, r *http.Request) { - i.requests.Add(1) - defer func(begin time.Time) { i.duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) - i.next.ServeHTTP(w, r) +func httpInstrument(requests metrics.Counter, duration metrics.Histogram) func(http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + requests.Add(1) + defer func(begin time.Time) { duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) + next.ServeHTTP(w, r) + }) + } } diff --git a/addsvc/main.go b/addsvc/main.go index 4536e7c74..48d52b57c 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -13,7 +13,6 @@ import ( "time" "git.apache.org/thrift.git/lib/go/thrift" - "golang.org/x/net/context" "google.golang.org/grpc" @@ -46,7 +45,7 @@ func main() { // `package server` domain var e server.Endpoint e = makeEndpoint(a) - e = server.Gate(zipkin.RequireInContext, e) // must have Zipkin headers + e = server.Gate(zipkin.RequireInContext)(e) // must have Zipkin headers // e = server.ChainableEnhancement(arg1, arg2, e) // `package metrics` domain @@ -79,7 +78,7 @@ func main() { var addServer pb.AddServer addServer = grpcBinding{e} - addServer = grpcInstrument(requests.With(field), duration.With(field), addServer) + addServer = grpcInstrument(requests.With(field), duration.With(field))(addServer) // Note that this will always fail, because the Endpoint is gated on // Zipkin headers, and we don't extract them from the gRPC request. @@ -97,7 +96,7 @@ func main() { var handler http.Handler handler = httpBinding{ctx, jsonCodec{}, "application/json", e} - handler = httpInstrument(requests.With(field), duration.With(field), handler) + handler = httpInstrument(requests.With(field), duration.With(field))(handler) handler = cors.Middleware(cors.MaxAge(5 * time.Minute))(handler) mux.Handle("/add", handler) @@ -145,7 +144,7 @@ func main() { var handler thriftadd.AddService handler = thriftBinding{ctx, e} field := metrics.Field{Key: "transport", Value: "thrift"} - handler = thriftInstrument(requests.With(field), duration.With(field), handler) + handler = thriftInstrument(requests.With(field), duration.With(field))(handler) // Note that this will always fail, because the Endpoint is gated on // Zipkin headers, and we don't extract them from the Thrift request. diff --git a/addsvc/thrift_binding.go b/addsvc/thrift_binding.go index 3f5aff27b..0888eed04 100644 --- a/addsvc/thrift_binding.go +++ b/addsvc/thrift_binding.go @@ -32,8 +32,10 @@ func (tb thriftBinding) Add(a, b int64) (*thriftadd.AddReply, error) { return &thriftadd.AddReply{Value: resp.V}, nil } -func thriftInstrument(requests metrics.Counter, duration metrics.Histogram, next thriftadd.AddService) thriftadd.AddService { - return thriftInstrumented{requests, duration, next} +func thriftInstrument(requests metrics.Counter, duration metrics.Histogram) func(thriftadd.AddService) thriftadd.AddService { + return func(next thriftadd.AddService) thriftadd.AddService { + return thriftInstrumented{requests, duration, next} + } } type thriftInstrumented struct { diff --git a/server/gate.go b/server/gate.go index 3264dc8b5..324ea779f 100644 --- a/server/gate.go +++ b/server/gate.go @@ -4,13 +4,15 @@ import ( "golang.org/x/net/context" ) -// Gate wraps an endpoint with a gating function. If the gating function +// Gate returns a middleware that gates requests. If the gating function // returns an error, the request is aborted, and that error is returned. -func Gate(allow func(context.Context, Request) error, next Endpoint) Endpoint { - return func(ctx context.Context, req Request) (Response, error) { - if err := allow(ctx, req); err != nil { - return nil, err +func Gate(allow func(context.Context, Request) error) func(Endpoint) Endpoint { + return func(next Endpoint) Endpoint { + return func(ctx context.Context, req Request) (Response, error) { + if err := allow(ctx, req); err != nil { + return nil, err + } + return next(ctx, req) } - return next(ctx, req) } } From 7c5fc0c351a472bfce338898384c635449d474a8 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 18 Mar 2015 13:18:15 +0100 Subject: [PATCH 12/38] addsvc: stub out Thrift until they fix codegen See https://issues.apache.org/jira/browse/THRIFT-3021 --- addsvc/main.go | 63 +-- addsvc/thrift/compile.sh | 4 + .../add_service-remote/add_service-remote.go | 144 ------ addsvc/thrift/gen-go/add/addservice.go | 433 ------------------ addsvc/thrift/gen-go/add/constants.go | 18 - addsvc/thrift/gen-go/add/ttypes.go | 105 ----- addsvc/thrift_binding.go | 51 --- 7 files changed, 6 insertions(+), 812 deletions(-) delete mode 100755 addsvc/thrift/gen-go/add/add_service-remote/add_service-remote.go delete mode 100644 addsvc/thrift/gen-go/add/addservice.go delete mode 100644 addsvc/thrift/gen-go/add/constants.go delete mode 100644 addsvc/thrift/gen-go/add/ttypes.go delete mode 100644 addsvc/thrift_binding.go diff --git a/addsvc/main.go b/addsvc/main.go index 48d52b57c..33e8992da 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -12,12 +12,10 @@ import ( "syscall" "time" - "git.apache.org/thrift.git/lib/go/thrift" "golang.org/x/net/context" "google.golang.org/grpc" "github.com/peterbourgon/gokit/addsvc/pb" - thriftadd "github.com/peterbourgon/gokit/addsvc/thrift/gen-go/add" "github.com/peterbourgon/gokit/metrics" "github.com/peterbourgon/gokit/metrics/expvar" "github.com/peterbourgon/gokit/metrics/statsd" @@ -28,12 +26,8 @@ import ( func main() { var ( - httpJSONAddr = flag.String("http.json.addr", ":8001", "Address for HTTP/JSON server") - grpcTCPAddr = flag.String("grpc.tcp.addr", ":8002", "Address for gRPC (TCP) server") - thriftTCPAddr = flag.String("thrift.tcp.addr", ":8003", "Address for Thrift (TCP) server") - thriftProtocol = flag.String("thrift.protocol", "binary", "binary, compact, json, simplejson") - thriftBufferSize = flag.Int("thrift.transport.bufsz", 0, "Thrift transport buffer size (0 = unbuffered)") - thriftFramed = flag.Bool("thrift.framed", false, "use framed transport") + httpJSONAddr = flag.String("http.json.addr", ":8001", "Address for HTTP/JSON server") + grpcTCPAddr = flag.String("grpc.tcp.addr", ":8002", "Address for gRPC (TCP) server") ) flag.Parse() @@ -104,59 +98,6 @@ func main() { errc <- http.ListenAndServe(*httpJSONAddr, mux) }() - // Transport: Thrift - go func() { - ctx, cancel := context.WithCancel(root) - defer cancel() - - var protocolFactory thrift.TProtocolFactory - switch *thriftProtocol { - case "binary": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - default: - errc <- fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol) - return - } - - var transportFactory thrift.TTransportFactory - if *thriftBufferSize > 0 { - transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize) - } else { - transportFactory = thrift.NewTTransportFactory() - } - - if *thriftFramed { - transportFactory = thrift.NewTFramedTransportFactory(transportFactory) - } - - transport, err := thrift.NewTServerSocket(*thriftTCPAddr) - if err != nil { - errc <- err - return - } - - var handler thriftadd.AddService - handler = thriftBinding{ctx, e} - field := metrics.Field{Key: "transport", Value: "thrift"} - handler = thriftInstrument(requests.With(field), duration.With(field))(handler) - // Note that this will always fail, because the Endpoint is gated on - // Zipkin headers, and we don't extract them from the Thrift request. - - log.Printf("Thrift (TCP) server on %s", *thriftTCPAddr) - errc <- thrift.NewTSimpleServer4( - thriftadd.NewAddServiceProcessor(thriftBinding{ctx, e}), - transport, - transportFactory, - protocolFactory, - ).Serve() - }() - log.Fatal(<-errc) } diff --git a/addsvc/thrift/compile.sh b/addsvc/thrift/compile.sh index 27e8341a9..30e755438 100755 --- a/addsvc/thrift/compile.sh +++ b/addsvc/thrift/compile.sh @@ -1,4 +1,8 @@ #!/usr/bin/env sh +# Thrift code generation for Go is broken in the current stable (0.9.2) +# release. Leaving this stubbed out until the fix is released. +# https://issues.apache.org/jira/browse/THRIFT-3021 + # https://thrift.apache.org/tutorial/go thrift -r --gen go add.thrift diff --git a/addsvc/thrift/gen-go/add/add_service-remote/add_service-remote.go b/addsvc/thrift/gen-go/add/add_service-remote/add_service-remote.go deleted file mode 100755 index 9835c8f0f..000000000 --- a/addsvc/thrift/gen-go/add/add_service-remote/add_service-remote.go +++ /dev/null @@ -1,144 +0,0 @@ -// Autogenerated by Thrift Compiler (0.9.2) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package main - -import ( - "add" - "flag" - "fmt" - "git.apache.org/thrift.git/lib/go/thrift" - "math" - "net" - "net/url" - "os" - "strconv" - "strings" -) - -func Usage() { - fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") - flag.PrintDefaults() - fmt.Fprintln(os.Stderr, "\nFunctions:") - fmt.Fprintln(os.Stderr, " AddReply Add(i64 a, i64 b)") - fmt.Fprintln(os.Stderr) - os.Exit(0) -} - -func main() { - flag.Usage = Usage - var host string - var port int - var protocol string - var urlString string - var framed bool - var useHttp bool - var parsedUrl url.URL - var trans thrift.TTransport - _ = strconv.Atoi - _ = math.Abs - flag.Usage = Usage - flag.StringVar(&host, "h", "localhost", "Specify host and port") - flag.IntVar(&port, "p", 9090, "Specify port") - flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") - flag.StringVar(&urlString, "u", "", "Specify the url") - flag.BoolVar(&framed, "framed", false, "Use framed transport") - flag.BoolVar(&useHttp, "http", false, "Use http") - flag.Parse() - - if len(urlString) > 0 { - parsedUrl, err := url.Parse(urlString) - if err != nil { - fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) - flag.Usage() - } - host = parsedUrl.Host - useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" - } else if useHttp { - _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) - if err != nil { - fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) - flag.Usage() - } - } - - cmd := flag.Arg(0) - var err error - if useHttp { - trans, err = thrift.NewTHttpClient(parsedUrl.String()) - } else { - portStr := fmt.Sprint(port) - if strings.Contains(host, ":") { - host, portStr, err = net.SplitHostPort(host) - if err != nil { - fmt.Fprintln(os.Stderr, "error with host:", err) - os.Exit(1) - } - } - trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) - if err != nil { - fmt.Fprintln(os.Stderr, "error resolving address:", err) - os.Exit(1) - } - if framed { - trans = thrift.NewTFramedTransport(trans) - } - } - if err != nil { - fmt.Fprintln(os.Stderr, "Error creating transport", err) - os.Exit(1) - } - defer trans.Close() - var protocolFactory thrift.TProtocolFactory - switch protocol { - case "compact": - protocolFactory = thrift.NewTCompactProtocolFactory() - break - case "simplejson": - protocolFactory = thrift.NewTSimpleJSONProtocolFactory() - break - case "json": - protocolFactory = thrift.NewTJSONProtocolFactory() - break - case "binary", "": - protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() - break - default: - fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) - Usage() - os.Exit(1) - } - client := add.NewAddServiceClientFactory(trans, protocolFactory) - if err := trans.Open(); err != nil { - fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) - os.Exit(1) - } - - switch cmd { - case "Add": - if flag.NArg()-1 != 2 { - fmt.Fprintln(os.Stderr, "Add requires 2 args") - flag.Usage() - } - argvalue0, err4 := (strconv.ParseInt(flag.Arg(1), 10, 64)) - if err4 != nil { - Usage() - return - } - value0 := argvalue0 - argvalue1, err5 := (strconv.ParseInt(flag.Arg(2), 10, 64)) - if err5 != nil { - Usage() - return - } - value1 := argvalue1 - fmt.Print(client.Add(value0, value1)) - fmt.Print("\n") - break - case "": - Usage() - break - default: - fmt.Fprintln(os.Stderr, "Invalid function ", cmd) - } -} diff --git a/addsvc/thrift/gen-go/add/addservice.go b/addsvc/thrift/gen-go/add/addservice.go deleted file mode 100644 index f986f110c..000000000 --- a/addsvc/thrift/gen-go/add/addservice.go +++ /dev/null @@ -1,433 +0,0 @@ -// Autogenerated by Thrift Compiler (0.9.2) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package add - -import ( - "bytes" - "fmt" - "git.apache.org/thrift.git/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = bytes.Equal - -type AddService interface { - // Parameters: - // - A - // - B - Add(a int64, b int64) (r *AddReply, err error) -} - -type AddServiceClient struct { - Transport thrift.TTransport - ProtocolFactory thrift.TProtocolFactory - InputProtocol thrift.TProtocol - OutputProtocol thrift.TProtocol - SeqId int32 -} - -func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient { - return &AddServiceClient{Transport: t, - ProtocolFactory: f, - InputProtocol: f.GetProtocol(t), - OutputProtocol: f.GetProtocol(t), - SeqId: 0, - } -} - -func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient { - return &AddServiceClient{Transport: t, - ProtocolFactory: nil, - InputProtocol: iprot, - OutputProtocol: oprot, - SeqId: 0, - } -} - -// Parameters: -// - A -// - B -func (p *AddServiceClient) Add(a int64, b int64) (r *AddReply, err error) { - if err = p.sendAdd(a, b); err != nil { - return - } - return p.recvAdd() -} - -func (p *AddServiceClient) sendAdd(a int64, b int64) (err error) { - oprot := p.OutputProtocol - if oprot == nil { - oprot = p.ProtocolFactory.GetProtocol(p.Transport) - p.OutputProtocol = oprot - } - p.SeqId++ - if err = oprot.WriteMessageBegin("Add", thrift.CALL, p.SeqId); err != nil { - return - } - args := AddArgs{ - A: a, - B: b, - } - if err = args.Write(oprot); err != nil { - return - } - if err = oprot.WriteMessageEnd(); err != nil { - return - } - return oprot.Flush() -} - -func (p *AddServiceClient) recvAdd() (value *AddReply, err error) { - iprot := p.InputProtocol - if iprot == nil { - iprot = p.ProtocolFactory.GetProtocol(p.Transport) - p.InputProtocol = iprot - } - _, mTypeId, seqId, err := iprot.ReadMessageBegin() - if err != nil { - return - } - if mTypeId == thrift.EXCEPTION { - error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") - var error1 error - error1, err = error0.Read(iprot) - if err != nil { - return - } - if err = iprot.ReadMessageEnd(); err != nil { - return - } - err = error1 - return - } - if p.SeqId != seqId { - err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Add failed: out of sequence response") - return - } - result := AddResult{} - if err = result.Read(iprot); err != nil { - return - } - if err = iprot.ReadMessageEnd(); err != nil { - return - } - value = result.GetSuccess() - return -} - -type AddServiceProcessor struct { - processorMap map[string]thrift.TProcessorFunction - handler AddService -} - -func (p *AddServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { - p.processorMap[key] = processor -} - -func (p *AddServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { - processor, ok = p.processorMap[key] - return processor, ok -} - -func (p *AddServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { - return p.processorMap -} - -func NewAddServiceProcessor(handler AddService) *AddServiceProcessor { - - self2 := &AddServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} - self2.processorMap["Add"] = &addServiceProcessorAdd{handler: handler} - return self2 -} - -func (p *AddServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - name, _, seqId, err := iprot.ReadMessageBegin() - if err != nil { - return false, err - } - if processor, ok := p.GetProcessorFunction(name); ok { - return processor.Process(seqId, iprot, oprot) - } - iprot.Skip(thrift.STRUCT) - iprot.ReadMessageEnd() - x3 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) - oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) - x3.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush() - return false, x3 - -} - -type addServiceProcessorAdd struct { - handler AddService -} - -func (p *addServiceProcessorAdd) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { - args := AddArgs{} - if err = args.Read(iprot); err != nil { - iprot.ReadMessageEnd() - x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) - oprot.WriteMessageBegin("Add", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush() - return false, err - } - - iprot.ReadMessageEnd() - result := AddResult{} - var retval *AddReply - var err2 error - if retval, err2 = p.handler.Add(args.A, args.B); err2 != nil { - x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Add: "+err2.Error()) - oprot.WriteMessageBegin("Add", thrift.EXCEPTION, seqId) - x.Write(oprot) - oprot.WriteMessageEnd() - oprot.Flush() - return true, err2 - } else { - result.Success = retval - } - if err2 = oprot.WriteMessageBegin("Add", thrift.REPLY, seqId); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(); err == nil && err2 != nil { - err = err2 - } - if err != nil { - return - } - return true, err -} - -// HELPER FUNCTIONS AND STRUCTURES - -type AddArgs struct { - A int64 `thrift:"a,1" json:"a"` - B int64 `thrift:"b,2" json:"b"` -} - -func NewAddArgs() *AddArgs { - return &AddArgs{} -} - -func (p *AddArgs) GetA() int64 { - return p.A -} - -func (p *AddArgs) GetB() int64 { - return p.B -} -func (p *AddArgs) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return fmt.Errorf("%T read error: %s", p, err) - } - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 1: - if err := p.ReadField1(iprot); err != nil { - return err - } - case 2: - if err := p.ReadField2(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return fmt.Errorf("%T read struct end error: %s", p, err) - } - return nil -} - -func (p *AddArgs) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return fmt.Errorf("error reading field 1: %s", err) - } else { - p.A = v - } - return nil -} - -func (p *AddArgs) ReadField2(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return fmt.Errorf("error reading field 2: %s", err) - } else { - p.B = v - } - return nil -} - -func (p *AddArgs) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Add_args"); err != nil { - return fmt.Errorf("%T write struct begin error: %s", p, err) - } - if err := p.writeField1(oprot); err != nil { - return err - } - if err := p.writeField2(oprot); err != nil { - return err - } - if err := oprot.WriteFieldStop(); err != nil { - return fmt.Errorf("write field stop error: %s", err) - } - if err := oprot.WriteStructEnd(); err != nil { - return fmt.Errorf("write struct stop error: %s", err) - } - return nil -} - -func (p *AddArgs) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("a", thrift.I64, 1); err != nil { - return fmt.Errorf("%T write field begin error 1:a: %s", p, err) - } - if err := oprot.WriteI64(int64(p.A)); err != nil { - return fmt.Errorf("%T.a (1) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return fmt.Errorf("%T write field end error 1:a: %s", p, err) - } - return err -} - -func (p *AddArgs) writeField2(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("b", thrift.I64, 2); err != nil { - return fmt.Errorf("%T write field begin error 2:b: %s", p, err) - } - if err := oprot.WriteI64(int64(p.B)); err != nil { - return fmt.Errorf("%T.b (2) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return fmt.Errorf("%T write field end error 2:b: %s", p, err) - } - return err -} - -func (p *AddArgs) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddArgs(%+v)", *p) -} - -type AddResult struct { - Success *AddReply `thrift:"success,0" json:"success"` -} - -func NewAddResult() *AddResult { - return &AddResult{} -} - -var AddResult_Success_DEFAULT *AddReply - -func (p *AddResult) GetSuccess() *AddReply { - if !p.IsSetSuccess() { - return AddResult_Success_DEFAULT - } - return p.Success -} -func (p *AddResult) IsSetSuccess() bool { - return p.Success != nil -} - -func (p *AddResult) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return fmt.Errorf("%T read error: %s", p, err) - } - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 0: - if err := p.ReadField0(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return fmt.Errorf("%T read struct end error: %s", p, err) - } - return nil -} - -func (p *AddResult) ReadField0(iprot thrift.TProtocol) error { - p.Success = &AddReply{} - if err := p.Success.Read(iprot); err != nil { - return fmt.Errorf("%T error reading struct: %s", p.Success, err) - } - return nil -} - -func (p *AddResult) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("Add_result"); err != nil { - return fmt.Errorf("%T write struct begin error: %s", p, err) - } - if err := p.writeField0(oprot); err != nil { - return err - } - if err := oprot.WriteFieldStop(); err != nil { - return fmt.Errorf("write field stop error: %s", err) - } - if err := oprot.WriteStructEnd(); err != nil { - return fmt.Errorf("write struct stop error: %s", err) - } - return nil -} - -func (p *AddResult) writeField0(oprot thrift.TProtocol) (err error) { - if p.IsSetSuccess() { - if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { - return fmt.Errorf("%T write field begin error 0:success: %s", p, err) - } - if err := p.Success.Write(oprot); err != nil { - return fmt.Errorf("%T error writing struct: %s", p.Success, err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return fmt.Errorf("%T write field end error 0:success: %s", p, err) - } - } - return err -} - -func (p *AddResult) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddResult(%+v)", *p) -} diff --git a/addsvc/thrift/gen-go/add/constants.go b/addsvc/thrift/gen-go/add/constants.go deleted file mode 100644 index 82134cb2e..000000000 --- a/addsvc/thrift/gen-go/add/constants.go +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated by Thrift Compiler (0.9.2) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package add - -import ( - "bytes" - "fmt" - "git.apache.org/thrift.git/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = bytes.Equal - -func init() { -} diff --git a/addsvc/thrift/gen-go/add/ttypes.go b/addsvc/thrift/gen-go/add/ttypes.go deleted file mode 100644 index 5bb531796..000000000 --- a/addsvc/thrift/gen-go/add/ttypes.go +++ /dev/null @@ -1,105 +0,0 @@ -// Autogenerated by Thrift Compiler (0.9.2) -// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING - -package add - -import ( - "bytes" - "fmt" - "git.apache.org/thrift.git/lib/go/thrift" -) - -// (needed to ensure safety because of naive import list construction.) -var _ = thrift.ZERO -var _ = fmt.Printf -var _ = bytes.Equal - -var GoUnusedProtection__ int - -type AddReply struct { - Value int64 `thrift:"value,1" json:"value"` -} - -func NewAddReply() *AddReply { - return &AddReply{} -} - -func (p *AddReply) GetValue() int64 { - return p.Value -} -func (p *AddReply) Read(iprot thrift.TProtocol) error { - if _, err := iprot.ReadStructBegin(); err != nil { - return fmt.Errorf("%T read error: %s", p, err) - } - for { - _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() - if err != nil { - return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) - } - if fieldTypeId == thrift.STOP { - break - } - switch fieldId { - case 1: - if err := p.ReadField1(iprot); err != nil { - return err - } - default: - if err := iprot.Skip(fieldTypeId); err != nil { - return err - } - } - if err := iprot.ReadFieldEnd(); err != nil { - return err - } - } - if err := iprot.ReadStructEnd(); err != nil { - return fmt.Errorf("%T read struct end error: %s", p, err) - } - return nil -} - -func (p *AddReply) ReadField1(iprot thrift.TProtocol) error { - if v, err := iprot.ReadI64(); err != nil { - return fmt.Errorf("error reading field 1: %s", err) - } else { - p.Value = v - } - return nil -} - -func (p *AddReply) Write(oprot thrift.TProtocol) error { - if err := oprot.WriteStructBegin("AddReply"); err != nil { - return fmt.Errorf("%T write struct begin error: %s", p, err) - } - if err := p.writeField1(oprot); err != nil { - return err - } - if err := oprot.WriteFieldStop(); err != nil { - return fmt.Errorf("write field stop error: %s", err) - } - if err := oprot.WriteStructEnd(); err != nil { - return fmt.Errorf("write struct stop error: %s", err) - } - return nil -} - -func (p *AddReply) writeField1(oprot thrift.TProtocol) (err error) { - if err := oprot.WriteFieldBegin("value", thrift.I64, 1); err != nil { - return fmt.Errorf("%T write field begin error 1:value: %s", p, err) - } - if err := oprot.WriteI64(int64(p.Value)); err != nil { - return fmt.Errorf("%T.value (1) field write error: %s", p, err) - } - if err := oprot.WriteFieldEnd(); err != nil { - return fmt.Errorf("%T write field end error 1:value: %s", p, err) - } - return err -} - -func (p *AddReply) String() string { - if p == nil { - return "" - } - return fmt.Sprintf("AddReply(%+v)", *p) -} diff --git a/addsvc/thrift_binding.go b/addsvc/thrift_binding.go deleted file mode 100644 index 0888eed04..000000000 --- a/addsvc/thrift_binding.go +++ /dev/null @@ -1,51 +0,0 @@ -package main - -import ( - "time" - - "golang.org/x/net/context" - - thriftadd "github.com/peterbourgon/gokit/addsvc/thrift/gen-go/add" - "github.com/peterbourgon/gokit/metrics" - "github.com/peterbourgon/gokit/server" -) - -// A binding wraps an Endpoint so that it's usable by a transport. -// thriftBinding makes an Endpoint usable over Thrift. -type thriftBinding struct { - context.Context - server.Endpoint -} - -// Add implements Thrift's AddService interface. -func (tb thriftBinding) Add(a, b int64) (*thriftadd.AddReply, error) { - r, err := tb.Endpoint(tb.Context, request{a, b}) - if err != nil { - return nil, err - } - - resp, ok := r.(*response) - if !ok { - return nil, server.ErrBadCast - } - - return &thriftadd.AddReply{Value: resp.V}, nil -} - -func thriftInstrument(requests metrics.Counter, duration metrics.Histogram) func(thriftadd.AddService) thriftadd.AddService { - return func(next thriftadd.AddService) thriftadd.AddService { - return thriftInstrumented{requests, duration, next} - } -} - -type thriftInstrumented struct { - requests metrics.Counter - duration metrics.Histogram - next thriftadd.AddService -} - -func (i thriftInstrumented) Add(a, b int64) (*thriftadd.AddReply, error) { - i.requests.Add(1) - defer func(begin time.Time) { i.duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) - return i.next.Add(a, b) -} From b1de2129e5da3471a70c1333f948427060f9503e Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 27 Mar 2015 15:11:07 +0100 Subject: [PATCH 13/38] transport: http: tests for CORS After writing these, I'm not sure it makes sense to "port" functionality into gokit this way. It's probably better just to bridge the package directly as a middleware. Will try that next... --- transport/http/cors/cors_test.go | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 transport/http/cors/cors_test.go diff --git a/transport/http/cors/cors_test.go b/transport/http/cors/cors_test.go new file mode 100644 index 000000000..9f729d499 --- /dev/null +++ b/transport/http/cors/cors_test.go @@ -0,0 +1,76 @@ +package cors_test + +import ( + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/peterbourgon/gokit/transport/http/cors" +) + +func TestProperGet(t *testing.T) { + resp := httptest.NewRecorder() + + cors.Middleware()(code(http.StatusNotFound)).ServeHTTP(resp, &http.Request{ + Method: "GET", + Header: map[string][]string{"Origin": {"localhost"}}, + }) + + if want, have := http.StatusNotFound, resp.Code; want != have { + t.Fatalf("want %d, have %d", want, have) + } + + if want, have := "*", resp.HeaderMap.Get("Access-Control-Allow-Origin"); want != have { + t.Fatalf("want %q, have %q", want, have) + } + + for _, header := range []string{"Origin", "Accept", "Accept-Encoding", "Authorization", "Content-Type"} { + if headers := resp.HeaderMap.Get("Access-Control-Allow-Headers"); !strings.Contains(headers, header) { + t.Fatalf("looking for %q, got %v", header, headers) + } + } +} + +func TestGetWithPost(t *testing.T) { + resp := httptest.NewRecorder() + + cors.Middleware()(code(http.StatusTeapot)).ServeHTTP(resp, &http.Request{ + Method: "POST", + Header: map[string][]string{"Origin": {"localhost"}}, + }) + + if want, have := http.StatusMethodNotAllowed, resp.Code; want != have { + t.Fatalf("want %d, have %d", want, have) + } +} + +func TestOptionsGet(t *testing.T) { + resp := httptest.NewRecorder() + + cors.Middleware()(code(http.StatusNotFound)).ServeHTTP(resp, &http.Request{ + Method: "OPTIONS", + Header: map[string][]string{ + "Access-Control-Request-Method": {"GET"}, + "Origin": {"localhost"}, + }, + }) + + if want, have := http.StatusOK, resp.Code; want != have { + t.Fatalf("want %d, have %d", want, have) + } + + if want, have := "*", resp.HeaderMap.Get("Access-Control-Allow-Origin"); want != have { + t.Fatalf("want %q, have %q", want, have) + } + + for _, header := range []string{"Origin", "Accept", "Accept-Encoding", "Authorization", "Content-Type"} { + if headers := resp.HeaderMap.Get("Access-Control-Allow-Headers"); !strings.Contains(headers, header) { + t.Fatalf("looking for %q, got %v", header, headers) + } + } +} + +type code int + +func (c code) ServeHTTP(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(int(c)) } From eb649c6bd00359b8b607041b74e7be030abbf7bc Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 27 Mar 2015 15:41:11 +0100 Subject: [PATCH 14/38] addsvc: use e.g. cors and gzip middlewares directly --- addsvc/main.go | 13 +++-- transport/http/cors/cors.go | 81 -------------------------------- transport/http/cors/cors_test.go | 76 ------------------------------ 3 files changed, 8 insertions(+), 162 deletions(-) delete mode 100644 transport/http/cors/cors.go delete mode 100644 transport/http/cors/cors_test.go diff --git a/addsvc/main.go b/addsvc/main.go index 33e8992da..af344273a 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -12,6 +12,9 @@ import ( "syscall" "time" + "github.com/justinas/alice" + "github.com/streadway/handy/cors" + "github.com/streadway/handy/encoding" "golang.org/x/net/context" "google.golang.org/grpc" @@ -21,7 +24,6 @@ import ( "github.com/peterbourgon/gokit/metrics/statsd" "github.com/peterbourgon/gokit/server" "github.com/peterbourgon/gokit/server/zipkin" - "github.com/peterbourgon/gokit/transport/http/cors" ) func main() { @@ -88,10 +90,11 @@ func main() { mux := http.NewServeMux() field := metrics.Field{Key: "transport", Value: "http"} - var handler http.Handler - handler = httpBinding{ctx, jsonCodec{}, "application/json", e} - handler = httpInstrument(requests.With(field), duration.With(field))(handler) - handler = cors.Middleware(cors.MaxAge(5 * time.Minute))(handler) + handler := alice.New( + httpInstrument(requests.With(field), duration.With(field)), + encoding.Gzip, + cors.Middleware(cors.Config{}), + ).Then(httpBinding{ctx, jsonCodec{}, "application/json", e}) mux.Handle("/add", handler) log.Printf("HTTP/JSON server on %s", *httpJSONAddr) diff --git a/transport/http/cors/cors.go b/transport/http/cors/cors.go deleted file mode 100644 index ad1a64630..000000000 --- a/transport/http/cors/cors.go +++ /dev/null @@ -1,81 +0,0 @@ -package cors - -import ( - "net/http" - "strconv" - "strings" - "time" -) - -// Option changes CORS behavior. -type Option func(*options) - -// MaxAge sets the Access-Control-Max-Age header for OPTIONS requests whose -// Access-Control-Request-Method is GET. By default, max age is 10 minutes. -func MaxAge(age time.Duration) Option { - return func(o *options) { o.maxAge = age } -} - -// AllowMethods sets Access-Control-Allow-Methods. By default, only the GET -// method is allowed. -func AllowMethods(methods ...string) Option { - return func(o *options) { o.allowMethods = methods } -} - -// AllowHeaders sets Access-Control-Allow-Headers. By default, the headers -// Accept, Accept-Encoding, Authorization, Content-Type, and Origin are -// allowed. -func AllowHeaders(headers ...string) Option { - return func(o *options) { o.allowHeaders = headers } -} - -// AllowOrigin sets Access-Control-Allow-Origin. By default, * is allowed. -func AllowOrigin(origin string) Option { - return func(o *options) { o.allowOrigin = origin } -} - -type options struct { - maxAge time.Duration - allowMethods []string - allowHeaders []string - allowOrigin string -} - -// Middleware returns a chainable HTTP handler that applies headers to allow -// CORS related requests. -func Middleware(opts ...Option) func(http.Handler) http.Handler { - o := &options{ - maxAge: 10 * time.Minute, - allowMethods: []string{"GET"}, - allowHeaders: []string{"Accept", "Accept-Encoding", "Authorization", "Content-Type", "Origin"}, - allowOrigin: "*", - } - for _, opt := range opts { - opt(o) - } - - // via https://github.com/streadway/handy/blob/master/cors/cors.go - - return func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Access-Control-Allow-Methods", strings.Join(o.allowMethods, ", ")) - w.Header().Set("Access-Control-Allow-Headers", strings.Join(o.allowHeaders, ", ")) - w.Header().Set("Access-Control-Allow-Origin", o.allowOrigin) - - switch r.Method { - case "OPTIONS": - if r.Header.Get("Access-Control-Request-Method") == "GET" { - w.Header().Set("Access-Control-Max-Age", strconv.Itoa(int(o.maxAge/time.Second))) - return - } - w.WriteHeader(http.StatusUnauthorized) - - case "HEAD", "GET": - next.ServeHTTP(w, r) - - default: - w.WriteHeader(http.StatusMethodNotAllowed) - } - }) - } -} diff --git a/transport/http/cors/cors_test.go b/transport/http/cors/cors_test.go deleted file mode 100644 index 9f729d499..000000000 --- a/transport/http/cors/cors_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package cors_test - -import ( - "net/http" - "net/http/httptest" - "strings" - "testing" - - "github.com/peterbourgon/gokit/transport/http/cors" -) - -func TestProperGet(t *testing.T) { - resp := httptest.NewRecorder() - - cors.Middleware()(code(http.StatusNotFound)).ServeHTTP(resp, &http.Request{ - Method: "GET", - Header: map[string][]string{"Origin": {"localhost"}}, - }) - - if want, have := http.StatusNotFound, resp.Code; want != have { - t.Fatalf("want %d, have %d", want, have) - } - - if want, have := "*", resp.HeaderMap.Get("Access-Control-Allow-Origin"); want != have { - t.Fatalf("want %q, have %q", want, have) - } - - for _, header := range []string{"Origin", "Accept", "Accept-Encoding", "Authorization", "Content-Type"} { - if headers := resp.HeaderMap.Get("Access-Control-Allow-Headers"); !strings.Contains(headers, header) { - t.Fatalf("looking for %q, got %v", header, headers) - } - } -} - -func TestGetWithPost(t *testing.T) { - resp := httptest.NewRecorder() - - cors.Middleware()(code(http.StatusTeapot)).ServeHTTP(resp, &http.Request{ - Method: "POST", - Header: map[string][]string{"Origin": {"localhost"}}, - }) - - if want, have := http.StatusMethodNotAllowed, resp.Code; want != have { - t.Fatalf("want %d, have %d", want, have) - } -} - -func TestOptionsGet(t *testing.T) { - resp := httptest.NewRecorder() - - cors.Middleware()(code(http.StatusNotFound)).ServeHTTP(resp, &http.Request{ - Method: "OPTIONS", - Header: map[string][]string{ - "Access-Control-Request-Method": {"GET"}, - "Origin": {"localhost"}, - }, - }) - - if want, have := http.StatusOK, resp.Code; want != have { - t.Fatalf("want %d, have %d", want, have) - } - - if want, have := "*", resp.HeaderMap.Get("Access-Control-Allow-Origin"); want != have { - t.Fatalf("want %q, have %q", want, have) - } - - for _, header := range []string{"Origin", "Accept", "Accept-Encoding", "Authorization", "Content-Type"} { - if headers := resp.HeaderMap.Get("Access-Control-Allow-Headers"); !strings.Contains(headers, header) { - t.Fatalf("looking for %q, got %v", header, headers) - } - } -} - -type code int - -func (c code) ServeHTTP(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(int(c)) } From f3eb1325e731b18a3fc26cd9a492563202f9d68c Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 27 Mar 2015 15:56:22 +0100 Subject: [PATCH 15/38] addsvc: fix import order --- addsvc/grpc_binding.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addsvc/grpc_binding.go b/addsvc/grpc_binding.go index c04ef2fa7..92bea3ec5 100644 --- a/addsvc/grpc_binding.go +++ b/addsvc/grpc_binding.go @@ -3,10 +3,11 @@ package main import ( "time" + "golang.org/x/net/context" + "github.com/peterbourgon/gokit/addsvc/pb" "github.com/peterbourgon/gokit/metrics" "github.com/peterbourgon/gokit/server" - "golang.org/x/net/context" ) // A binding wraps an Endpoint so that it's usable by a transport. grpcBinding From 2ffa5ab89726e7d115f0d9436a4c62ccfd304124 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Mon, 13 Apr 2015 15:53:35 +0200 Subject: [PATCH 16/38] New protoc and gRPC --- addsvc/pb/add.pb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addsvc/pb/add.pb.go b/addsvc/pb/add.pb.go index 21791c60a..126f411b0 100644 --- a/addsvc/pb/add.pb.go +++ b/addsvc/pb/add.pb.go @@ -85,7 +85,7 @@ func RegisterAddServer(s *grpc.Server, srv AddServer) { s.RegisterService(&_Add_serviceDesc, srv) } -func _Add_Add_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) { +func _Add_Add_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { in := new(AddRequest) if err := proto.Unmarshal(buf, in); err != nil { return nil, err From 8b1f69cdfc928a4e482d94da117601dd2815066d Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 14 Apr 2015 14:05:39 +0200 Subject: [PATCH 17/38] Improvements surrounding HTTP and Zipkin - HTTP binding moved to package transport - Remove concept of Gate; not useful at the moment - Zipkin will create Span and Trace IDs, if they don't exist - Method to set Zipkin fields in HTTP header - Break out HTTP Before and After funcs --- addsvc/http_binding.go | 44 +++++++++++++++++++ addsvc/httpjson_binding.go | 80 ---------------------------------- addsvc/main.go | 34 +++++++-------- metrics/time_histogram.go | 6 +-- metrics/time_histogram_test.go | 2 +- server/gate.go | 18 -------- server/zipkin/zipkin.go | 51 ++++++++++++---------- server/zipkin/zipkin_test.go | 70 +++++++++++++++++++++++++++++ transport/http/before_after.go | 25 +++++++++++ transport/http/binding.go | 80 ++++++++++++++++++++++++++++++++++ 10 files changed, 269 insertions(+), 141 deletions(-) create mode 100644 addsvc/http_binding.go delete mode 100644 addsvc/httpjson_binding.go delete mode 100644 server/gate.go create mode 100644 server/zipkin/zipkin_test.go create mode 100644 transport/http/before_after.go create mode 100644 transport/http/binding.go diff --git a/addsvc/http_binding.go b/addsvc/http_binding.go new file mode 100644 index 000000000..0d5dff3a6 --- /dev/null +++ b/addsvc/http_binding.go @@ -0,0 +1,44 @@ +package main + +import ( + "encoding/json" + "io" + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/peterbourgon/gokit/metrics" + "github.com/peterbourgon/gokit/server" +) + +// jsonCodec implements transport/codec, decoding and encoding requests and +// responses respectively as JSON. It requires that the concrete request and +// response types support JSON de/serialization. +// +// This type is mostly boiler-plate; in theory, it could be generated. +type jsonCodec struct{} + +func (jsonCodec) Decode(ctx context.Context, r io.Reader) (server.Request, context.Context, error) { + var req request + err := json.NewDecoder(r).Decode(&req) + return &req, ctx, err +} + +func (jsonCodec) Encode(w io.Writer, resp server.Response) error { + return json.NewEncoder(w).Encode(resp) +} + +// The HTTP binding exists in the HTTP transport package, because it uses the +// codec to deserialize and serialize requests and responses, and therefore +// doesn't need to have access to the concrete request and response types. + +func httpInstrument(requests metrics.Counter, duration metrics.Histogram) func(http.Handler) http.Handler { + return func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + requests.Add(1) + defer func(begin time.Time) { duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) + next.ServeHTTP(w, r) + }) + } +} diff --git a/addsvc/httpjson_binding.go b/addsvc/httpjson_binding.go deleted file mode 100644 index 60dcab7ed..000000000 --- a/addsvc/httpjson_binding.go +++ /dev/null @@ -1,80 +0,0 @@ -package main - -import ( - "encoding/json" - "io" - "net/http" - "time" - - "golang.org/x/net/context" - - "github.com/peterbourgon/gokit/metrics" - "github.com/peterbourgon/gokit/server" - "github.com/peterbourgon/gokit/server/zipkin" - "github.com/peterbourgon/gokit/transport/codec" -) - -// jsonCodec decodes and encodes requests and responses respectively as JSON. -// It requires that the (package main) request and response structs support -// JSON de/serialization. -// -// This type is mostly boiler-plate; in theory, it could be generated. -type jsonCodec struct{} - -func (jsonCodec) Decode(ctx context.Context, r io.Reader) (server.Request, context.Context, error) { - var req request - err := json.NewDecoder(r).Decode(&req) - return &req, ctx, err -} - -func (jsonCodec) Encode(w io.Writer, resp server.Response) error { - return json.NewEncoder(w).Encode(resp) -} - -// A binding wraps an Endpoint so that it's usable by a transport. httpBinding -// makes an Endpoint usable over HTTP. It combines a parent context, a codec, -// and an endpoint to expose. It implements http.Handler by decoding a request -// from the HTTP request body, and encoding a response to the response writer. -type httpBinding struct { - context.Context // parent context - codec.Codec // how to decode requests and encode responses - contentType string // what we report as the response ContentType - server.Endpoint // the endpoint being bound -} - -func (b httpBinding) ServeHTTP(w http.ResponseWriter, r *http.Request) { - // Perform HTTP-specific context amendments. - b.Context = zipkin.GetHeaders(b.Context, r.Header) - - // Decode request. - req, ctx, err := b.Codec.Decode(b.Context, r.Body) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - b.Context = ctx - - // Execute RPC. - resp, err := b.Endpoint(b.Context, req) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - // Encode response. - w.Header().Set("Content-Type", b.contentType) - if err := b.Codec.Encode(w, resp); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } -} - -func httpInstrument(requests metrics.Counter, duration metrics.Histogram) func(http.Handler) http.Handler { - return func(next http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - requests.Add(1) - defer func(begin time.Time) { duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) - next.ServeHTTP(w, r) - }) - } -} diff --git a/addsvc/main.go b/addsvc/main.go index af344273a..3239dc38e 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -12,7 +12,6 @@ import ( "syscall" "time" - "github.com/justinas/alice" "github.com/streadway/handy/cors" "github.com/streadway/handy/encoding" "golang.org/x/net/context" @@ -24,12 +23,13 @@ import ( "github.com/peterbourgon/gokit/metrics/statsd" "github.com/peterbourgon/gokit/server" "github.com/peterbourgon/gokit/server/zipkin" + kithttp "github.com/peterbourgon/gokit/transport/http" ) func main() { var ( - httpJSONAddr = flag.String("http.json.addr", ":8001", "Address for HTTP/JSON server") - grpcTCPAddr = flag.String("grpc.tcp.addr", ":8002", "Address for gRPC (TCP) server") + httpAddr = flag.String("http.addr", ":8001", "Address for HTTP (JSON) server") + grpcAddr = flag.String("grpc.addr", ":8002", "Address for gRPC server") ) flag.Parse() @@ -41,7 +41,6 @@ func main() { // `package server` domain var e server.Endpoint e = makeEndpoint(a) - e = server.Gate(zipkin.RequireInContext)(e) // must have Zipkin headers // e = server.ChainableEnhancement(arg1, arg2, e) // `package metrics` domain @@ -64,7 +63,7 @@ func main() { // Transport: gRPC go func() { - ln, err := net.Listen("tcp", *grpcTCPAddr) + ln, err := net.Listen("tcp", *grpcAddr) if err != nil { errc <- err return @@ -75,30 +74,31 @@ func main() { var addServer pb.AddServer addServer = grpcBinding{e} addServer = grpcInstrument(requests.With(field), duration.With(field))(addServer) - // Note that this will always fail, because the Endpoint is gated on - // Zipkin headers, and we don't extract them from the gRPC request. pb.RegisterAddServer(s, addServer) - log.Printf("gRPC server on TCP %s", *grpcTCPAddr) + log.Printf("gRPC server on %s", *grpcAddr) errc <- s.Serve(ln) }() - // Transport: HTTP/JSON + // Transport: HTTP (JSON) go func() { ctx, cancel := context.WithCancel(root) defer cancel() - mux := http.NewServeMux() + field := metrics.Field{Key: "transport", Value: "http"} + before := kithttp.Before(zipkin.GetFromHTTP) + after := kithttp.After(kithttp.SetContentType("application/json")) - handler := alice.New( - httpInstrument(requests.With(field), duration.With(field)), - encoding.Gzip, - cors.Middleware(cors.Config{}), - ).Then(httpBinding{ctx, jsonCodec{}, "application/json", e}) + var handler http.Handler + handler = kithttp.NewBinding(ctx, jsonCodec{}, e, before, after) + handler = encoding.Gzip(handler) + handler = httpInstrument(requests.With(field), duration.With(field))(handler) + handler = cors.Middleware(cors.Config{})(handler) + mux := http.NewServeMux() mux.Handle("/add", handler) - log.Printf("HTTP/JSON server on %s", *httpJSONAddr) - errc <- http.ListenAndServe(*httpJSONAddr, mux) + log.Printf("HTTP server on %s", *httpAddr) + errc <- http.ListenAndServe(*httpAddr, mux) }() log.Fatal(<-errc) diff --git a/metrics/time_histogram.go b/metrics/time_histogram.go index 0a8de89ea..a8fc54c37 100644 --- a/metrics/time_histogram.go +++ b/metrics/time_histogram.go @@ -9,16 +9,16 @@ type TimeHistogram interface { } type timeHistogram struct { - Histogram unit time.Duration + Histogram } // NewTimeHistogram returns a TimeHistogram wrapper around the passed // Histogram, in units of unit. -func NewTimeHistogram(h Histogram, unit time.Duration) TimeHistogram { +func NewTimeHistogram(unit time.Duration, h Histogram) TimeHistogram { return &timeHistogram{ - Histogram: h, unit: unit, + Histogram: h, } } diff --git a/metrics/time_histogram_test.go b/metrics/time_histogram_test.go index 6ca7d347a..a704d9933 100644 --- a/metrics/time_histogram_test.go +++ b/metrics/time_histogram_test.go @@ -13,7 +13,7 @@ func TestTimeHistogram(t *testing.T) { const metricName string = "test_time_histogram" quantiles := []int{50, 90, 99} h0 := expvar.NewHistogram(metricName, 0, 200, 3, quantiles...) - h := metrics.NewTimeHistogram(h0, time.Millisecond) + h := metrics.NewTimeHistogram(time.Millisecond, h0) const seed, mean, stdev int64 = 321, 100, 20 for i := 0; i < 4321; i++ { diff --git a/server/gate.go b/server/gate.go deleted file mode 100644 index 324ea779f..000000000 --- a/server/gate.go +++ /dev/null @@ -1,18 +0,0 @@ -package server - -import ( - "golang.org/x/net/context" -) - -// Gate returns a middleware that gates requests. If the gating function -// returns an error, the request is aborted, and that error is returned. -func Gate(allow func(context.Context, Request) error) func(Endpoint) Endpoint { - return func(next Endpoint) Endpoint { - return func(ctx context.Context, req Request) (Response, error) { - if err := allow(ctx, req); err != nil { - return nil, err - } - return next(ctx, req) - } - } -} diff --git a/server/zipkin/zipkin.go b/server/zipkin/zipkin.go index 096b26a8c..98785d540 100644 --- a/server/zipkin/zipkin.go +++ b/server/zipkin/zipkin.go @@ -1,10 +1,9 @@ package zipkin import ( - "errors" + "math/rand" "net/http" - - "github.com/peterbourgon/gokit/server" + "strconv" "golang.org/x/net/context" ) @@ -15,41 +14,49 @@ const ( spanIDHTTPHeader = "X-B3-SpanId" parentSpanIDHTTPHeader = "X-B3-ParentSpanId" - // TraceIDContextKey holds the Zipkin TraceId, if available. + // TraceIDContextKey holds the Zipkin TraceId. TraceIDContextKey = "Zipkin-Trace-ID" - // SpanIDContextKey holds the Zipkin SpanId, if available. + // SpanIDContextKey holds the Zipkin SpanId. SpanIDContextKey = "Zipkin-Span-ID" // ParentSpanIDContextKey holds the Zipkin ParentSpanId, if available. ParentSpanIDContextKey = "Zipkin-Parent-Span-ID" ) -// ErrMissingZipkinHeaders is returned when a context doesn't contain Zipkin -// trace, span, or parent span IDs. -var ErrMissingZipkinHeaders = errors.New("Zipkin headers missing from request context") - -// GetHeaders extracts Zipkin headers from the HTTP request, and populates -// them into the context, if present. -func GetHeaders(ctx context.Context, header http.Header) context.Context { - if val := header.Get(traceIDHTTPHeader); val != "" { +// GetFromHTTP implements transport/http.BeforeFunc, populating Zipkin headers +// into the context from the HTTP headers. It will generate new trace and span +// IDs if none are found. +func GetFromHTTP(ctx context.Context, r *http.Request) context.Context { + if val := r.Header.Get(traceIDHTTPHeader); val != "" { ctx = context.WithValue(ctx, TraceIDContextKey, val) + } else { + ctx = context.WithValue(ctx, TraceIDContextKey, strconv.FormatInt(rand.Int63(), 16)) } - if val := header.Get(spanIDHTTPHeader); val != "" { + if val := r.Header.Get(spanIDHTTPHeader); val != "" { ctx = context.WithValue(ctx, SpanIDContextKey, val) + } else { + ctx = context.WithValue(ctx, SpanIDContextKey, strconv.FormatInt(rand.Int63(), 16)) } - if val := header.Get(parentSpanIDHTTPHeader); val != "" { + if val := r.Header.Get(parentSpanIDHTTPHeader); val != "" { ctx = context.WithValue(ctx, ParentSpanIDContextKey, val) } return ctx } -// RequireInContext implements the server.Gate allow func by checking if the -// context contains extracted Zipkin headers. Contexts without all headers -// aren't allowed to proceed. -func RequireInContext(ctx context.Context, _ server.Request) error { - if ctx.Value(TraceIDContextKey) == nil || ctx.Value(SpanIDContextKey) == nil || ctx.Value(ParentSpanIDContextKey) == nil { - return ErrMissingZipkinHeaders +// SetHTTPHeaders copies Zipkin headers from the context into the HTTP header. +func SetHTTPHeaders(ctx context.Context, h http.Header) { + for ctxKey, hdrKey := range map[string]string{ + TraceIDContextKey: traceIDHTTPHeader, + SpanIDContextKey: spanIDHTTPHeader, + ParentSpanIDContextKey: parentSpanIDHTTPHeader, + } { + if val := ctx.Value(ctxKey); val != nil { + s, ok := val.(string) + if !ok { + panic("context value for " + ctxKey + " isn't string") + } + h.Set(hdrKey, s) + } } - return nil } diff --git a/server/zipkin/zipkin_test.go b/server/zipkin/zipkin_test.go new file mode 100644 index 000000000..ca487d330 --- /dev/null +++ b/server/zipkin/zipkin_test.go @@ -0,0 +1,70 @@ +package zipkin_test + +import ( + "math/rand" + "net/http" + "testing" + + "github.com/peterbourgon/gokit/server/zipkin" + "golang.org/x/net/context" +) + +func TestGeneration(t *testing.T) { + rand.Seed(123) + + r, _ := http.NewRequest("GET", "http://cool.horse", nil) + ctx := zipkin.GetFromHTTP(context.Background(), r) + + for key, want := range map[string]string{ + zipkin.TraceIDContextKey: "4a68998bed5c40f1", + zipkin.SpanIDContextKey: "35b51599210f9ba", + } { + val := ctx.Value(key) + if val == nil { + t.Errorf("%s: no entry", key) + continue + } + have, ok := val.(string) + if !ok { + t.Errorf("%s: value not a string", key) + continue + } + if want != have { + t.Errorf("%s: want %q, have %q", key, want, have) + continue + } + } +} + +func TestHTTPHeaders(t *testing.T) { + ids := map[string]string{ + zipkin.TraceIDContextKey: "some_trace_id", + zipkin.SpanIDContextKey: "some_span_id", + zipkin.ParentSpanIDContextKey: "some_parent_span_id", + } + + ctx0 := context.Background() + for key, val := range ids { + ctx0 = context.WithValue(ctx0, key, val) + } + r, _ := http.NewRequest("GET", "http://best.horse", nil) + zipkin.SetHTTPHeaders(ctx0, r.Header) + ctx1 := zipkin.GetFromHTTP(context.Background(), r) + + for key, want := range ids { + val := ctx1.Value(key) + if val == nil { + t.Errorf("%s: no entry", key) + continue + } + have, ok := val.(string) + if !ok { + t.Errorf("%s: value not a string", key) + continue + } + if want != have { + t.Errorf("%s: want %q, have %q", key, want, have) + continue + } + } +} diff --git a/transport/http/before_after.go b/transport/http/before_after.go new file mode 100644 index 000000000..66e487090 --- /dev/null +++ b/transport/http/before_after.go @@ -0,0 +1,25 @@ +package http + +import ( + "net/http" + + "golang.org/x/net/context" +) + +// BeforeFunc may take information from a HTTP request and put it into a +// request context. BeforeFuncs are executed in HTTP bindings, prior to +// invoking the endpoint. +type BeforeFunc func(context.Context, *http.Request) context.Context + +// AfterFunc may take information from a request context and use it to +// manipulate a ResponseWriter. AfterFuncs are executed in HTTP bindings, +// after invoking the endpoint but prior to writing a response. +type AfterFunc func(context.Context, http.ResponseWriter) + +// SetContentType returns a AfterFunc that sets the HTTP Content-Type +// header to the provided value. +func SetContentType(value string) AfterFunc { + return func(_ context.Context, w http.ResponseWriter) { + w.Header().Set("Content-Type", value) + } +} diff --git a/transport/http/binding.go b/transport/http/binding.go new file mode 100644 index 000000000..c5c9991aa --- /dev/null +++ b/transport/http/binding.go @@ -0,0 +1,80 @@ +package http + +import ( + "net/http" + + "golang.org/x/net/context" + + "github.com/peterbourgon/gokit/server" + "github.com/peterbourgon/gokit/transport/codec" +) + +// BindingOption sets a parameter for the binding. +type BindingOption func(*binding) + +// Before adds pre-RPC BeforeFuncs to the binding. +func Before(funcs ...BeforeFunc) BindingOption { + return func(b *binding) { b.before = append(b.before, funcs...) } +} + +// After adds post-RPC AfterFuncs to the binding. +func After(funcs ...AfterFunc) BindingOption { + return func(b *binding) { b.after = append(b.after, funcs...) } +} + +type binding struct { + context.Context + codec.Codec + server.Endpoint + before []BeforeFunc + after []AfterFunc +} + +// NewBinding returns an HTTP handler that wraps the given endpoint. +func NewBinding(ctx context.Context, cdc codec.Codec, endpoint server.Endpoint, options ...BindingOption) http.Handler { + b := &binding{ + Context: ctx, + Codec: cdc, + Endpoint: endpoint, + } + for _, option := range options { + option(b) + } + return b +} + +func (b *binding) ServeHTTP(w http.ResponseWriter, r *http.Request) { + // Per-request context. + ctx, cancel := context.WithCancel(b.Context) + defer cancel() + + // Prepare the RPC's context with details from the request. + for _, f := range b.before { + ctx = f(ctx, r) + } + + // Decode request. + req, ctx, err := b.Codec.Decode(ctx, r.Body) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + // Execute RPC. + resp, err := b.Endpoint(ctx, req) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + // Prepare the ResponseWriter. + for _, f := range b.after { + f(ctx, w) + } + + // Encode response. + if err := b.Codec.Encode(w, resp); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } +} From 772919e4381cddd6b013b043facba5ec8a82d42a Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 14 Apr 2015 14:11:49 +0200 Subject: [PATCH 18/38] update_deps.bash helper script --- update_deps.bash | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 update_deps.bash diff --git a/update_deps.bash b/update_deps.bash new file mode 100755 index 000000000..5af470f69 --- /dev/null +++ b/update_deps.bash @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# This script updates each non-stdlib, non-gokit dependency to its most recent +# commit. It can be invoked to aid in debugging after a dependency-related +# failure on continuous integration. + +function deps { + go list -f '{{join .Deps "\n"}}' ./... +} + +function not_stdlib { + xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' +} + +function not_gokit { + grep -v 'peterbourgon/gokit' +} + +function go_get_update { + while read d ; do + echo $d + go get -u $d + done +} + +deps | not_stdlib | not_gokit | go_get_update + From 19d29d3e5c3e90a8fd1f32b6d3cf7029d08dc022 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 14 Apr 2015 18:23:36 +0200 Subject: [PATCH 19/38] Zipkin moves to new package tracing --- addsvc/add.go | 5 +++-- addsvc/grpc_binding.go | 4 ++++ addsvc/main.go | 6 ++++-- {server => tracing}/zipkin/zipkin.go | 0 {server => tracing}/zipkin/zipkin_test.go | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) rename {server => tracing}/zipkin/zipkin.go (100%) rename {server => tracing}/zipkin/zipkin_test.go (96%) diff --git a/addsvc/add.go b/addsvc/add.go index fd6fa3850..12c037b9a 100644 --- a/addsvc/add.go +++ b/addsvc/add.go @@ -1,7 +1,8 @@ package main -// Add is the abstract definition of what this service does. -// It could easily be an interface type with multiple methods. +// Add is the abstract definition of what this service does. It could easily +// be an interface type with multiple methods. Each method would be an +// endpoint. type Add func(int64, int64) int64 func pureAdd(a, b int64) int64 { return a + b } diff --git a/addsvc/grpc_binding.go b/addsvc/grpc_binding.go index 92bea3ec5..027a00c8f 100644 --- a/addsvc/grpc_binding.go +++ b/addsvc/grpc_binding.go @@ -15,6 +15,10 @@ import ( type grpcBinding struct{ server.Endpoint } // Add implements the proto3 AddServer by forwarding to the wrapped Endpoint. +// +// As far as I can tell, gRPC doesn't (currently) provide a user-accessible +// way to manipulate the RPC context, like headers for HTTP. So we don't have +// a way to transport e.g. Zipkin IDs with the request. TODO. func (b grpcBinding) Add(ctx context.Context, req *pb.AddRequest) (*pb.AddReply, error) { addReq := request{req.A, req.B} r, err := b.Endpoint(ctx, addReq) diff --git a/addsvc/main.go b/addsvc/main.go index 3239dc38e..5a059d50f 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -22,7 +22,7 @@ import ( "github.com/peterbourgon/gokit/metrics/expvar" "github.com/peterbourgon/gokit/metrics/statsd" "github.com/peterbourgon/gokit/server" - "github.com/peterbourgon/gokit/server/zipkin" + "github.com/peterbourgon/gokit/tracing/zipkin" kithttp "github.com/peterbourgon/gokit/transport/http" ) @@ -53,6 +53,8 @@ func main() { statsd.NewHistogram(ioutil.Discard, "duration_ns", time.Second), ) + // `package tracing` domain + // Mechanical stuff root := context.Background() errc := make(chan error) @@ -92,8 +94,8 @@ func main() { var handler http.Handler handler = kithttp.NewBinding(ctx, jsonCodec{}, e, before, after) handler = encoding.Gzip(handler) - handler = httpInstrument(requests.With(field), duration.With(field))(handler) handler = cors.Middleware(cors.Config{})(handler) + handler = httpInstrument(requests.With(field), duration.With(field))(handler) mux := http.NewServeMux() mux.Handle("/add", handler) diff --git a/server/zipkin/zipkin.go b/tracing/zipkin/zipkin.go similarity index 100% rename from server/zipkin/zipkin.go rename to tracing/zipkin/zipkin.go diff --git a/server/zipkin/zipkin_test.go b/tracing/zipkin/zipkin_test.go similarity index 96% rename from server/zipkin/zipkin_test.go rename to tracing/zipkin/zipkin_test.go index ca487d330..36deee96d 100644 --- a/server/zipkin/zipkin_test.go +++ b/tracing/zipkin/zipkin_test.go @@ -5,7 +5,7 @@ import ( "net/http" "testing" - "github.com/peterbourgon/gokit/server/zipkin" + "github.com/peterbourgon/gokit/tracing/zipkin" "golang.org/x/net/context" ) From a1ab6e555f4e6de40fb4f067e53ef007cc1377cf Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 15 Apr 2015 10:52:04 +0200 Subject: [PATCH 20/38] addsvc: thrift compile.sh custom thrift_import --- addsvc/thrift/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addsvc/thrift/compile.sh b/addsvc/thrift/compile.sh index 30e755438..3a8d6b702 100755 --- a/addsvc/thrift/compile.sh +++ b/addsvc/thrift/compile.sh @@ -5,4 +5,4 @@ # https://issues.apache.org/jira/browse/THRIFT-3021 # https://thrift.apache.org/tutorial/go -thrift -r --gen go add.thrift +thrift -r --gen go:thrift_import=github.com/apache/thrift add.thrift From 906bc3581a40125ff1b2aaf1b8fe2017efbedf09 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 15 Apr 2015 17:41:56 +0200 Subject: [PATCH 21/38] tracing: changes to Zipkin - Don't extract individual headers to context - Rather, build a Span object, and put that in the context - Still figuring out the best way to handle middleware... --- addsvc/main.go | 5 +- tracing/zipkin/collector.go | 13 ++++ tracing/zipkin/span.go | 85 ++++++++++++++++++++++++++ tracing/zipkin/zipkin.go | 101 +++++++++++++++++++------------ tracing/zipkin/zipkin_test.go | 108 ++++++++++++++++++---------------- 5 files changed, 225 insertions(+), 87 deletions(-) create mode 100644 tracing/zipkin/collector.go create mode 100644 tracing/zipkin/span.go diff --git a/addsvc/main.go b/addsvc/main.go index 5a059d50f..aa1167b0e 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -54,6 +54,9 @@ func main() { ) // `package tracing` domain + zipkinHost := "some-host" // TODO + zipkinCollector := zipkin.NopCollector{} // TODO + zipkinSpanFunc := zipkin.NewSpanFunc(zipkinHost, zipkinCollector) // Mechanical stuff root := context.Background() @@ -88,7 +91,7 @@ func main() { defer cancel() field := metrics.Field{Key: "transport", Value: "http"} - before := kithttp.Before(zipkin.GetFromHTTP) + before := kithttp.Before(zipkin.ToContext(zipkin.ViaHTTP(zipkinSpanFunc))) after := kithttp.After(kithttp.SetContentType("application/json")) var handler http.Handler diff --git a/tracing/zipkin/collector.go b/tracing/zipkin/collector.go new file mode 100644 index 000000000..0bbb5e8ea --- /dev/null +++ b/tracing/zipkin/collector.go @@ -0,0 +1,13 @@ +package zipkin + +// Collector represents a Zipkin trace collector, which is probably a set of +// remote endpoints. +type Collector interface { + Collect(*Span) error +} + +// NopCollector implements Collector but performs no work. +type NopCollector struct{} + +// Collect implements Collector. +func (NopCollector) Collect(*Span) error { return nil } diff --git a/tracing/zipkin/span.go b/tracing/zipkin/span.go new file mode 100644 index 000000000..e3d16ebbe --- /dev/null +++ b/tracing/zipkin/span.go @@ -0,0 +1,85 @@ +package zipkin + +import ( + "errors" + "time" +) + +var ( + // SpanContextKey represents the Span in the request context. + SpanContextKey = "Zipkin-Span" + + // ErrSpanNotFound is returned when a Span isn't found in a context. + ErrSpanNotFound = errors.New("span not found") +) + +// A Span is a named collection of annotations. It represents meaningful +// information about a single method call, i.e. a single request against a +// service. Clients should annotate the span, and submit it when the request +// that generated it is complete. +type Span struct { + host string + collector Collector + + name string + traceID int64 + spanID int64 + parentSpanID int64 + + annotations []annotation + //binaryAnnotations []BinaryAnnotation +} + +// NewSpan returns a new Span object ready for use. +func NewSpan(host string, collector Collector, name string, traceID, spanID, parentSpanID int64) *Span { + return &Span{ + host: host, + collector: collector, + name: name, + traceID: traceID, + spanID: spanID, + parentSpanID: parentSpanID, + } +} + +// NewSpanFunc returns a function that generates a new Zipkin span. +func NewSpanFunc(host string, collector Collector) func(string, int64, int64, int64) *Span { + return func(name string, traceID, spanID, parentSpanID int64) *Span { + return NewSpan(host, collector, name, traceID, spanID, parentSpanID) + } +} + +// TraceID returns the ID of the trace that this span is a member of. +func (s *Span) TraceID() int64 { return s.traceID } + +// SpanID returns the ID of this span. +func (s *Span) SpanID() int64 { return s.spanID } + +// ParentSpanID returns the ID of the span which invoked this span. +// It may be zero. +func (s *Span) ParentSpanID() int64 { return s.parentSpanID } + +// Annotate annotates the span with the given value. +func (s *Span) Annotate(value string) { + s.AnnotateDuration(value, 0) +} + +// AnnotateDuration annotates the span with the given value and duration. +func (s *Span) AnnotateDuration(value string, duration time.Duration) { + s.annotations = append(s.annotations, annotation{ + timestamp: time.Now(), + value: value, + duration: duration, + host: s.host, + }) +} + +// Submit sends the span to the collector. +func (s *Span) Submit() error { return s.collector.Collect(s) } + +type annotation struct { + timestamp time.Time + value string + duration time.Duration // optional + host string +} diff --git a/tracing/zipkin/zipkin.go b/tracing/zipkin/zipkin.go index 98785d540..e9a362275 100644 --- a/tracing/zipkin/zipkin.go +++ b/tracing/zipkin/zipkin.go @@ -8,55 +8,84 @@ import ( "golang.org/x/net/context" ) +// http://www.slideshare.net/johanoskarsson/zipkin-runtime-open-house + const ( // https://github.com/racker/tryfer#headers traceIDHTTPHeader = "X-B3-TraceId" spanIDHTTPHeader = "X-B3-SpanId" parentSpanIDHTTPHeader = "X-B3-ParentSpanId" +) - // TraceIDContextKey holds the Zipkin TraceId. - TraceIDContextKey = "Zipkin-Trace-ID" +// ViaHTTP is a helper method that allows NewSpanFunc's factory function to be +// easily invoked by passing an HTTP request. The span name is the HTTP +// method. The trace, span, and parent span IDs are taken from the request +// headers. +func ViaHTTP(f func(string, int64, int64, int64) *Span) func(*http.Request) *Span { + return func(r *http.Request) *Span { + return f( + r.Method, + getID(r.Header, traceIDHTTPHeader), + getID(r.Header, spanIDHTTPHeader), + getID(r.Header, parentSpanIDHTTPHeader), + ) + } +} - // SpanIDContextKey holds the Zipkin SpanId. - SpanIDContextKey = "Zipkin-Span-ID" +// ToContext returns a function satisfies transport/http.BeforeFunc. When +// invoked, it generates a Zipkin span from the incoming HTTP request, and +// saves it in the request context under the SpanContextKey. +func ToContext(f func(*http.Request) *Span) func(context.Context, *http.Request) context.Context { + return func(ctx context.Context, r *http.Request) context.Context { + return context.WithValue(ctx, SpanContextKey, f(r)) + } +} - // ParentSpanIDContextKey holds the Zipkin ParentSpanId, if available. - ParentSpanIDContextKey = "Zipkin-Parent-Span-ID" -) +// SetRequestHeaders sets up HTTP headers for a new outgoing request, based on +// the Span in the request context. It transparently passes through the trace +// ID, assigns a new, random span ID, and sets the parent span ID to the +// current span ID. All IDs are encoded as hex strings. +// +// This function is meant to be applied to outgoing HTTP requests. +func SetRequestHeaders(ctx context.Context, h http.Header) error { + val := ctx.Value(SpanContextKey) + if val == nil { + return ErrSpanNotFound + } -// GetFromHTTP implements transport/http.BeforeFunc, populating Zipkin headers -// into the context from the HTTP headers. It will generate new trace and span -// IDs if none are found. -func GetFromHTTP(ctx context.Context, r *http.Request) context.Context { - if val := r.Header.Get(traceIDHTTPHeader); val != "" { - ctx = context.WithValue(ctx, TraceIDContextKey, val) - } else { - ctx = context.WithValue(ctx, TraceIDContextKey, strconv.FormatInt(rand.Int63(), 16)) + span, ok := val.(*Span) + if !ok { + panic(SpanContextKey + " value isn't a span object") } - if val := r.Header.Get(spanIDHTTPHeader); val != "" { - ctx = context.WithValue(ctx, SpanIDContextKey, val) - } else { - ctx = context.WithValue(ctx, SpanIDContextKey, strconv.FormatInt(rand.Int63(), 16)) + + if id := span.TraceID(); id > 0 { + h.Set(traceIDHTTPHeader, strconv.FormatInt(id, 16)) } - if val := r.Header.Get(parentSpanIDHTTPHeader); val != "" { - ctx = context.WithValue(ctx, ParentSpanIDContextKey, val) + + h.Set(spanIDHTTPHeader, strconv.FormatInt(newID(), 16)) + + if id := span.SpanID(); id > 0 { + h.Set(parentSpanIDHTTPHeader, strconv.FormatInt(id, 16)) } - return ctx + + return nil } -// SetHTTPHeaders copies Zipkin headers from the context into the HTTP header. -func SetHTTPHeaders(ctx context.Context, h http.Header) { - for ctxKey, hdrKey := range map[string]string{ - TraceIDContextKey: traceIDHTTPHeader, - SpanIDContextKey: spanIDHTTPHeader, - ParentSpanIDContextKey: parentSpanIDHTTPHeader, - } { - if val := ctx.Value(ctxKey); val != nil { - s, ok := val.(string) - if !ok { - panic("context value for " + ctxKey + " isn't string") - } - h.Set(hdrKey, s) - } +func getID(h http.Header, key string) int64 { + val := h.Get(key) + if val == "" { + return 0 } + i, err := strconv.ParseInt(val, 16, 64) + if err != nil { + panic("invalid Zipkin ID in HTTP header: " + val) + } + return i +} + +func newID() int64 { + // https://github.com/wadey/go-zipkin/blob/46e5f01/trace.go#L183-188 + // https://github.com/twitter/zipkin/issues/199 + // :( + return rand.Int63() & 0x001fffffffffffff } diff --git a/tracing/zipkin/zipkin_test.go b/tracing/zipkin/zipkin_test.go index 36deee96d..96a7744db 100644 --- a/tracing/zipkin/zipkin_test.go +++ b/tracing/zipkin/zipkin_test.go @@ -1,70 +1,78 @@ package zipkin_test import ( - "math/rand" "net/http" + "strconv" "testing" - "github.com/peterbourgon/gokit/tracing/zipkin" "golang.org/x/net/context" + + "github.com/peterbourgon/gokit/tracing/zipkin" ) -func TestGeneration(t *testing.T) { - rand.Seed(123) +func TestContextInjection(t *testing.T) { + const ( + traceID int64 = 12 + spanID int64 = 34 + parentSpanID int64 = 56 + ) - r, _ := http.NewRequest("GET", "http://cool.horse", nil) - ctx := zipkin.GetFromHTTP(context.Background(), r) + r, _ := http.NewRequest("GET", "https://best.horse", nil) + r.Header.Set("X-B3-TraceId", strconv.FormatInt(traceID, 16)) + r.Header.Set("X-B3-SpanId", strconv.FormatInt(spanID, 16)) + r.Header.Set("X-B3-ParentSpanId", strconv.FormatInt(parentSpanID, 16)) - for key, want := range map[string]string{ - zipkin.TraceIDContextKey: "4a68998bed5c40f1", - zipkin.SpanIDContextKey: "35b51599210f9ba", - } { - val := ctx.Value(key) - if val == nil { - t.Errorf("%s: no entry", key) - continue - } - have, ok := val.(string) - if !ok { - t.Errorf("%s: value not a string", key) - continue - } - if want != have { - t.Errorf("%s: want %q, have %q", key, want, have) - continue - } + sf := zipkin.NewSpanFunc("my-host", zipkin.NopCollector{}) + hf := zipkin.ViaHTTP(sf) + cf := zipkin.ToContext(hf) + + ctx := cf(context.Background(), r) + val := ctx.Value(zipkin.SpanContextKey) + if val == nil { + t.Fatalf("%s returned no value", zipkin.SpanContextKey) + } + span, ok := val.(*zipkin.Span) + if !ok { + t.Fatalf("%s was not a Span object", zipkin.SpanContextKey) } -} -func TestHTTPHeaders(t *testing.T) { - ids := map[string]string{ - zipkin.TraceIDContextKey: "some_trace_id", - zipkin.SpanIDContextKey: "some_span_id", - zipkin.ParentSpanIDContextKey: "some_parent_span_id", + if want, have := traceID, span.TraceID(); want != have { + t.Errorf("want %d, have %d", want, have) } - ctx0 := context.Background() - for key, val := range ids { - ctx0 = context.WithValue(ctx0, key, val) + if want, have := spanID, span.SpanID(); want != have { + t.Errorf("want %d, have %d", want, have) } - r, _ := http.NewRequest("GET", "http://best.horse", nil) - zipkin.SetHTTPHeaders(ctx0, r.Header) - ctx1 := zipkin.GetFromHTTP(context.Background(), r) - for key, want := range ids { - val := ctx1.Value(key) - if val == nil { - t.Errorf("%s: no entry", key) - continue - } - have, ok := val.(string) - if !ok { - t.Errorf("%s: value not a string", key) - continue - } - if want != have { - t.Errorf("%s: want %q, have %q", key, want, have) - continue + if want, have := parentSpanID, span.ParentSpanID(); want != have { + t.Errorf("want %d, have %d", want, have) + } +} + +func TestSetRequestHeaders(t *testing.T) { + const ( + host = "my-host" + name = "my-name" + traceID int64 = 123 + spanID int64 = 456 + parentSpanID int64 = 789 + ) + + span := zipkin.NewSpan(host, zipkin.NopCollector{}, name, traceID, spanID, parentSpanID) + ctx := context.WithValue(context.Background(), zipkin.SpanContextKey, span) + + r, _ := http.NewRequest("POST", "http://destroy.horse", nil) + if err := zipkin.SetRequestHeaders(ctx, r.Header); err != nil { + t.Fatal(err) + } + + for h, want := range map[string]string{ + "X-B3-TraceId": strconv.FormatInt(traceID, 16), + // span ID is now random + "X-B3-ParentSpanId": strconv.FormatInt(spanID, 16), + } { + if have := r.Header.Get(h); want != have { + t.Errorf("%s: want %s, have %s", h, want, have) } } } From f4b7976ed5633eac46e672ceba171457cde0d9e2 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 15 Apr 2015 18:05:17 +0200 Subject: [PATCH 22/38] tracing: name symmetry: FromHTTP, ToContext --- addsvc/main.go | 2 +- tracing/zipkin/zipkin.go | 8 ++++---- tracing/zipkin/zipkin_test.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addsvc/main.go b/addsvc/main.go index aa1167b0e..58e6fbef8 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -91,7 +91,7 @@ func main() { defer cancel() field := metrics.Field{Key: "transport", Value: "http"} - before := kithttp.Before(zipkin.ToContext(zipkin.ViaHTTP(zipkinSpanFunc))) + before := kithttp.Before(zipkin.ToContext(zipkin.FromHTTP(zipkinSpanFunc))) after := kithttp.After(kithttp.SetContentType("application/json")) var handler http.Handler diff --git a/tracing/zipkin/zipkin.go b/tracing/zipkin/zipkin.go index e9a362275..19b7d5318 100644 --- a/tracing/zipkin/zipkin.go +++ b/tracing/zipkin/zipkin.go @@ -17,11 +17,11 @@ const ( parentSpanIDHTTPHeader = "X-B3-ParentSpanId" ) -// ViaHTTP is a helper method that allows NewSpanFunc's factory function to be -// easily invoked by passing an HTTP request. The span name is the HTTP -// method. The trace, span, and parent span IDs are taken from the request +// FromHTTP is a helper method that allows NewSpanFunc's factory function to +// be easily invoked by passing an HTTP request. The span name is the HTTP +// method, The trace, span, and parent span IDs are taken from the request // headers. -func ViaHTTP(f func(string, int64, int64, int64) *Span) func(*http.Request) *Span { +func FromHTTP(f func(string, int64, int64, int64) *Span) func(*http.Request) *Span { return func(r *http.Request) *Span { return f( r.Method, diff --git a/tracing/zipkin/zipkin_test.go b/tracing/zipkin/zipkin_test.go index 96a7744db..223febbae 100644 --- a/tracing/zipkin/zipkin_test.go +++ b/tracing/zipkin/zipkin_test.go @@ -23,7 +23,7 @@ func TestContextInjection(t *testing.T) { r.Header.Set("X-B3-ParentSpanId", strconv.FormatInt(parentSpanID, 16)) sf := zipkin.NewSpanFunc("my-host", zipkin.NopCollector{}) - hf := zipkin.ViaHTTP(sf) + hf := zipkin.FromHTTP(sf) cf := zipkin.ToContext(hf) ctx := cf(context.Background(), r) From 7f0951756483f894b555169a9a0e266f5a678fd3 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 17 Apr 2015 15:55:36 +0200 Subject: [PATCH 23/38] addsvc: Thrift compile.sh: fix thrift_import --- addsvc/thrift/compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addsvc/thrift/compile.sh b/addsvc/thrift/compile.sh index 3a8d6b702..a8c311992 100755 --- a/addsvc/thrift/compile.sh +++ b/addsvc/thrift/compile.sh @@ -5,4 +5,4 @@ # https://issues.apache.org/jira/browse/THRIFT-3021 # https://thrift.apache.org/tutorial/go -thrift -r --gen go:thrift_import=github.com/apache/thrift add.thrift +thrift -r --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift add.thrift From 0483d05e5359666edc1c370cf6271ff12b7dc80e Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 17 Apr 2015 16:33:45 +0200 Subject: [PATCH 24/38] zipkin: (Scribe) collector --- tracing/zipkin/collector.go | 132 + tracing/zipkin/collector_test.go | 233 + tracing/zipkin/span.go | 33 + tracing/zipkin/thrift/compile.sh | 11 + .../zipkin/thrift/gen-go/scribe/constants.go | 18 + .../scribe/scribe-remote/scribe-remote.go | 150 + tracing/zipkin/thrift/gen-go/scribe/scribe.go | 418 + tracing/zipkin/thrift/gen-go/scribe/ttypes.go | 168 + .../gen-go/zipkincollector/constants.go | 23 + .../thrift/gen-go/zipkincollector/ttypes.go | 205 + .../zipkin_collector-remote.go | 234 + .../gen-go/zipkincollector/zipkincollector.go | 1112 +++ .../thrift/gen-go/zipkincore/constants.go | 23 + .../zipkin/thrift/gen-go/zipkincore/ttypes.go | 990 ++ .../gen-go/zipkindependencies/constants.go | 18 + .../gen-go/zipkindependencies/ttypes.go | 580 ++ .../thrift/gen-go/zipkinquery/constants.go | 23 + .../thrift/gen-go/zipkinquery/ttypes.go | 2085 +++++ .../zipkin_query-remote.go | 602 ++ .../thrift/gen-go/zipkinquery/zipkinquery.go | 8183 +++++++++++++++++ tracing/zipkin/thrift/scribe.thrift | 32 + tracing/zipkin/thrift/zipkinCollector.thrift | 35 + tracing/zipkin/thrift/zipkinCore.thrift | 59 + .../zipkin/thrift/zipkinDependencies.thrift | 43 + tracing/zipkin/thrift/zipkinQuery.thrift | 252 + 25 files changed, 15662 insertions(+) create mode 100644 tracing/zipkin/collector_test.go create mode 100755 tracing/zipkin/thrift/compile.sh create mode 100644 tracing/zipkin/thrift/gen-go/scribe/constants.go create mode 100755 tracing/zipkin/thrift/gen-go/scribe/scribe-remote/scribe-remote.go create mode 100644 tracing/zipkin/thrift/gen-go/scribe/scribe.go create mode 100644 tracing/zipkin/thrift/gen-go/scribe/ttypes.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkincollector/constants.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkincollector/ttypes.go create mode 100755 tracing/zipkin/thrift/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkincollector/zipkincollector.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkincore/constants.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkincore/ttypes.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkindependencies/constants.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkindependencies/ttypes.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkinquery/constants.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkinquery/ttypes.go create mode 100755 tracing/zipkin/thrift/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go create mode 100644 tracing/zipkin/thrift/gen-go/zipkinquery/zipkinquery.go create mode 100644 tracing/zipkin/thrift/scribe.thrift create mode 100644 tracing/zipkin/thrift/zipkinCollector.thrift create mode 100644 tracing/zipkin/thrift/zipkinCore.thrift create mode 100644 tracing/zipkin/thrift/zipkinDependencies.thrift create mode 100644 tracing/zipkin/thrift/zipkinQuery.thrift diff --git a/tracing/zipkin/collector.go b/tracing/zipkin/collector.go index 0bbb5e8ea..05ac01d31 100644 --- a/tracing/zipkin/collector.go +++ b/tracing/zipkin/collector.go @@ -1,13 +1,145 @@ package zipkin +import ( + "encoding/base64" + "errors" + "fmt" + "net" + "strings" + "time" + + "github.com/apache/thrift/lib/go/thrift" + + "github.com/peterbourgon/gokit/tracing/zipkin/thrift/gen-go/scribe" +) + // Collector represents a Zipkin trace collector, which is probably a set of // remote endpoints. type Collector interface { Collect(*Span) error } +// ScribeCollector implements Collector by forwarding spans to a Scribe +// service in batches. +type ScribeCollector struct { + spanc chan spanTuple +} + +// NewScribeCollector returns a new Scribe-backed Collector, ready for use. +func NewScribeCollector(addr string, timeout time.Duration, batchSize int, batchTime time.Duration) (Collector, error) { + factory := func() (scribe.Scribe, error) { + return newScribeClient(addr, timeout) + } + client, err := factory() + if err != nil { + return nil, err + } + c := &ScribeCollector{ + spanc: make(chan spanTuple), + } + go c.loop(client, factory, batchSize, batchTime) + return c, nil +} + +// Collect implements Collector. +func (c *ScribeCollector) Collect(s *Span) error { + e := make(chan error) + c.spanc <- spanTuple{s, e} + return <-e +} + +func (c *ScribeCollector) loop(client scribe.Scribe, factory func() (scribe.Scribe, error), batchSize int, batchTime time.Duration) { + batch := make([]*scribe.LogEntry, 0, batchSize) + nextPublish := time.Now().Add(batchTime) + publish := func() error { + if client == nil { + var err error + if client, err = factory(); err != nil { + return fmt.Errorf("during reconnect: %v", err) + } + } + if rc, err := client.Log(batch); err != nil { + client = nil + return fmt.Errorf("during Log: %v", err) + } else if rc != scribe.ResultCode_OK { + // probably transient error; don't reset client + return fmt.Errorf("remote returned %s", rc) + } + batch = batch[:0] + return nil + } + + for t := range c.spanc { + message, err := encode(t.Span) + if err != nil { + t.errc <- err + continue + } + + batch = append(batch, &scribe.LogEntry{ + Category: "zipkin", // TODO parmeterize? + Message: message, + }) + + if len(batch) >= batchSize || time.Now().After(nextPublish) { + t.errc <- publish() + nextPublish = time.Now().Add(batchTime) + continue + } + + t.errc <- nil + } +} + +type spanTuple struct { + *Span + errc chan error +} + +func newScribeClient(addr string, timeout time.Duration) (scribe.Scribe, error) { + a, err := net.ResolveTCPAddr("tcp", addr) + if err != nil { + return nil, err + } + socket := thrift.NewTSocketFromAddrTimeout(a, timeout) + transport := thrift.NewTFramedTransport(socket) + if err := transport.Open(); err != nil { + socket.Close() + return nil, err + } + proto := thrift.NewTBinaryProtocolTransport(transport) + client := scribe.NewScribeClientProtocol(transport, proto, proto) + return client, nil +} + +func encode(s *Span) (string, error) { + t := thrift.NewTMemoryBuffer() + p := thrift.NewTBinaryProtocolTransport(t) + if err := s.Encode().Write(p); err != nil { + return "", err + } + return base64.StdEncoding.EncodeToString(t.Buffer.Bytes()), nil +} + // NopCollector implements Collector but performs no work. type NopCollector struct{} // Collect implements Collector. func (NopCollector) Collect(*Span) error { return nil } + +// MultiCollector implements Collector by sending spans to all collectors. +type MultiCollector []Collector + +// Collect implements Collector. +func (c MultiCollector) Collect(s *Span) error { + errs := []string{} + for _, collector := range c { + if err := collector.Collect(s); err != nil { + errs = append(errs, err.Error()) + } + } + if len(errs) > 0 { + return errors.New(strings.Join(errs, "; ")) + } + return nil +} diff --git a/tracing/zipkin/collector_test.go b/tracing/zipkin/collector_test.go new file mode 100644 index 000000000..ec71af561 --- /dev/null +++ b/tracing/zipkin/collector_test.go @@ -0,0 +1,233 @@ +package zipkin_test + +import ( + "encoding/base64" + "sync" + "testing" + "time" + + "github.com/peterbourgon/gokit/tracing/zipkin/thrift/gen-go/zipkincore" + + "github.com/apache/thrift/lib/go/thrift" + + "github.com/peterbourgon/gokit/tracing/zipkin" + "github.com/peterbourgon/gokit/tracing/zipkin/thrift/gen-go/scribe" +) + +func TestScribeCollector(t *testing.T) { + s := newScribeServer(t) + defer s.close() + + c, err := zipkin.NewScribeCollector(s.addr(), 100*time.Millisecond, 0, 10*time.Millisecond) + if err != nil { + t.Fatal(err) + } + + var ( + name = "span-name" + traceID = int64(123) + spanID = int64(456) + parentSpanID = int64(0) + value = "foo" + duration = 42 * time.Millisecond + ) + + span := zipkin.NewSpan("some-host", c, name, traceID, spanID, parentSpanID) + span.AnnotateDuration("foo", 42*time.Millisecond) + if err := span.Submit(); err != nil { + t.Errorf("error during submit: %v", err) + } + + if want, have := 1, len(s.spans()); want != have { + t.Fatalf("want %d, have %d", want, have) + } + + gotSpan := s.spans()[0] + if want, have := name, gotSpan.GetName(); want != have { + t.Errorf("want %q, have %q", want, have) + } + if want, have := traceID, gotSpan.GetTraceId(); want != have { + t.Errorf("want %d, have %d", want, have) + } + if want, have := spanID, gotSpan.GetId(); want != have { + t.Errorf("want %d, have %d", want, have) + } + if want, have := parentSpanID, gotSpan.GetParentId(); want != have { + t.Errorf("want %d, have %d", want, have) + } + + if want, have := 1, len(gotSpan.GetAnnotations()); want != have { + t.Fatalf("want %d, have %d", want, have) + } + + gotAnnotation := gotSpan.GetAnnotations()[0] + if want, have := value, gotAnnotation.GetValue(); want != have { + t.Errorf("want %q, have %q", want, have) + } + if want, have := duration, time.Duration(gotAnnotation.GetDuration())*time.Microsecond; want != have { + t.Errorf("want %s, have %s", want, have) + } +} + +type scribeServer struct { + t *testing.T + transport *thrift.TServerSocket + address string + server *thrift.TSimpleServer + handler *scribeHandler + wg sync.WaitGroup +} + +func newScribeServer(t *testing.T) *scribeServer { + protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() + transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) + transport, err := thrift.NewTServerSocket(":0") + if err != nil { + t.Fatal(err) + } + handler := &scribeHandler{} + server := thrift.NewTSimpleServer4( + scribe.NewScribeProcessor(handler), + transport, + transportFactory, + protocolFactory, + ) + + s := &scribeServer{t: t} + s.wg.Add(1) + go func() { defer s.wg.Done(); server.Serve() }() + tickc := time.Tick(10 * time.Millisecond) + donec := time.After(1 * time.Second) + for !transport.IsListening() { + select { + case <-tickc: + continue + case <-donec: + t.Fatal("server never started listening") + } + } + + s.transport = transport + s.address = transport.Addr().String() + s.server = server + s.handler = handler + return s +} + +func (s *scribeServer) addr() string { + return s.address +} + +func (s *scribeServer) spans() []*zipkincore.Span { + spans := []*zipkincore.Span{} + for _, m := range *s.handler { + decoded, err := base64.StdEncoding.DecodeString(m.GetMessage()) + if err != nil { + s.t.Error(err) + continue + } + buffer := thrift.NewTMemoryBuffer() + if _, err := buffer.Write(decoded); err != nil { + s.t.Error(err) + continue + } + transport := thrift.NewTBinaryProtocolTransport(buffer) + zs := &zipkincore.Span{} + if err := zs.Read(transport); err != nil { + s.t.Error(err) + continue + } + spans = append(spans, zs) + } + return spans +} + +func (s *scribeServer) reset() { + s.handler.reset() +} + +func (s *scribeServer) close() { + s.transport.Close() + s.server.Stop() + s.wg.Wait() +} + +type scribeHandler []*scribe.LogEntry + +func (h *scribeHandler) Log(messages []*scribe.LogEntry) (scribe.ResultCode, error) { + for _, m := range messages { + (*h) = append(*h, m) + } + return scribe.ResultCode_OK, nil +} + +func (h *scribeHandler) reset() { + (*h) = (*h)[:0] +} + +/* +type server struct { + t *testing.T + wg sync.WaitGroup + listener net.Listener + + mu sync.Mutex + buffer bytes.Buffer +} + +func newServer(t *testing.T) *server { + listener, err := net.Listen("tcp", ":0") + if err != nil { + t.Fatal(err) + } + + wg := sync.WaitGroup{} + wg.Add(1) + + s := &server{ + t: t, + wg: wg, + listener: listener, + buffer: bytes.Buffer{}, + } + go s.loop() + return s +} + +func (s *server) loop() { + defer s.wg.Done() + for { + conn, err := s.listener.Accept() + s.t.Logf("Accept %v %v", conn.LocalAddr(), conn.RemoteAddr()) + if err != nil { + s.t.Log(err) // closing the listener triggers an error + return + } + buf := make([]byte, 8192) + for { + n, err := conn.Read(buf) + if err != nil { + s.t.Log(err) // also OK + break + } + s.buffer.Write(buf[:n]) + } + s.t.Logf("done") + } +} + +func (s *server) addr() string { + return s.listener.Addr().String() +} + +func (s *server) buf() []byte { + s.mu.Lock() + defer s.mu.Unlock() + return s.buffer.Bytes() // better not mutate! +} + +func (s *server) close() { + s.listener.Close() + //s.wg.Wait() +} +*/ diff --git a/tracing/zipkin/span.go b/tracing/zipkin/span.go index e3d16ebbe..cee5d253b 100644 --- a/tracing/zipkin/span.go +++ b/tracing/zipkin/span.go @@ -3,6 +3,8 @@ package zipkin import ( "errors" "time" + + "github.com/peterbourgon/gokit/tracing/zipkin/thrift/gen-go/zipkincore" ) var ( @@ -77,6 +79,37 @@ func (s *Span) AnnotateDuration(value string, duration time.Duration) { // Submit sends the span to the collector. func (s *Span) Submit() error { return s.collector.Collect(s) } +// Encode creates a Thrift Span from the gokit Span. +func (s *Span) Encode() *zipkincore.Span { + // TODO lots of garbage here. We can improve by preallocating e.g. the + // Thrift stuff into an encoder struct, owned by the ScribeCollector. + zs := zipkincore.Span{ + TraceId: s.traceID, + Name: s.name, + Id: s.spanID, + BinaryAnnotations: []*zipkincore.BinaryAnnotation{}, // TODO + Debug: false, // TODO + } + if s.parentSpanID != 0 { + (*zs.ParentId) = s.parentSpanID + } + zs.Annotations = make([]*zipkincore.Annotation, len(s.annotations)) + for i, a := range s.annotations { + zs.Annotations[i] = &zipkincore.Annotation{ + Timestamp: a.timestamp.UnixNano() / 1e3, + Value: a.value, + } + if a.host != "" { + // zs.Annotations[i].Host = TODO + } + if a.duration > 0 { + zs.Annotations[i].Duration = new(int32) + (*zs.Annotations[i].Duration) = int32(a.duration / time.Microsecond) + } + } + return &zs +} + type annotation struct { timestamp time.Time value string diff --git a/tracing/zipkin/thrift/compile.sh b/tracing/zipkin/thrift/compile.sh new file mode 100755 index 000000000..5b88bbfb3 --- /dev/null +++ b/tracing/zipkin/thrift/compile.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# Thrift code generation for Go is broken in the current stable (0.9.2) +# release. Leaving this stubbed out until the fix is released. +# https://issues.apache.org/jira/browse/THRIFT-3021 + +# https://thrift.apache.org/tutorial/go +for f in *.thrift ; do + thrift -r --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift $f +done + diff --git a/tracing/zipkin/thrift/gen-go/scribe/constants.go b/tracing/zipkin/thrift/gen-go/scribe/constants.go new file mode 100644 index 000000000..d814d4dd0 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/scribe/constants.go @@ -0,0 +1,18 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package scribe + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +func init() { +} diff --git a/tracing/zipkin/thrift/gen-go/scribe/scribe-remote/scribe-remote.go b/tracing/zipkin/thrift/gen-go/scribe/scribe-remote/scribe-remote.go new file mode 100755 index 000000000..dc4eafe3b --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/scribe/scribe-remote/scribe-remote.go @@ -0,0 +1,150 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package main + +import ( + "flag" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "math" + "net" + "net/url" + "os" + "scribe" + "strconv" + "strings" +) + +func Usage() { + fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") + flag.PrintDefaults() + fmt.Fprintln(os.Stderr, "\nFunctions:") + fmt.Fprintln(os.Stderr, " ResultCode Log( messages)") + fmt.Fprintln(os.Stderr) + os.Exit(0) +} + +func main() { + flag.Usage = Usage + var host string + var port int + var protocol string + var urlString string + var framed bool + var useHttp bool + var parsedUrl url.URL + var trans thrift.TTransport + _ = strconv.Atoi + _ = math.Abs + flag.Usage = Usage + flag.StringVar(&host, "h", "localhost", "Specify host and port") + flag.IntVar(&port, "p", 9090, "Specify port") + flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") + flag.StringVar(&urlString, "u", "", "Specify the url") + flag.BoolVar(&framed, "framed", false, "Use framed transport") + flag.BoolVar(&useHttp, "http", false, "Use http") + flag.Parse() + + if len(urlString) > 0 { + parsedUrl, err := url.Parse(urlString) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + host = parsedUrl.Host + useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" + } else if useHttp { + _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + } + + cmd := flag.Arg(0) + var err error + if useHttp { + trans, err = thrift.NewTHttpClient(parsedUrl.String()) + } else { + portStr := fmt.Sprint(port) + if strings.Contains(host, ":") { + host, portStr, err = net.SplitHostPort(host) + if err != nil { + fmt.Fprintln(os.Stderr, "error with host:", err) + os.Exit(1) + } + } + trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) + if err != nil { + fmt.Fprintln(os.Stderr, "error resolving address:", err) + os.Exit(1) + } + if framed { + trans = thrift.NewTFramedTransport(trans) + } + } + if err != nil { + fmt.Fprintln(os.Stderr, "Error creating transport", err) + os.Exit(1) + } + defer trans.Close() + var protocolFactory thrift.TProtocolFactory + switch protocol { + case "compact": + protocolFactory = thrift.NewTCompactProtocolFactory() + break + case "simplejson": + protocolFactory = thrift.NewTSimpleJSONProtocolFactory() + break + case "json": + protocolFactory = thrift.NewTJSONProtocolFactory() + break + case "binary", "": + protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() + break + default: + fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) + Usage() + os.Exit(1) + } + client := scribe.NewScribeClientFactory(trans, protocolFactory) + if err := trans.Open(); err != nil { + fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) + os.Exit(1) + } + + switch cmd { + case "Log": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "Log requires 1 args") + flag.Usage() + } + arg5 := flag.Arg(1) + mbTrans6 := thrift.NewTMemoryBufferLen(len(arg5)) + defer mbTrans6.Close() + _, err7 := mbTrans6.WriteString(arg5) + if err7 != nil { + Usage() + return + } + factory8 := thrift.NewTSimpleJSONProtocolFactory() + jsProt9 := factory8.GetProtocol(mbTrans6) + containerStruct0 := scribe.NewLogArgs() + err10 := containerStruct0.ReadField1(jsProt9) + if err10 != nil { + Usage() + return + } + argvalue0 := containerStruct0.Messages + value0 := argvalue0 + fmt.Print(client.Log(value0)) + fmt.Print("\n") + break + case "": + Usage() + break + default: + fmt.Fprintln(os.Stderr, "Invalid function ", cmd) + } +} diff --git a/tracing/zipkin/thrift/gen-go/scribe/scribe.go b/tracing/zipkin/thrift/gen-go/scribe/scribe.go new file mode 100644 index 000000000..44f60367c --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/scribe/scribe.go @@ -0,0 +1,418 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package scribe + +import ( + "bytes" + "fmt" + + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +type Scribe interface { + // Parameters: + // - Messages + Log(messages []*LogEntry) (r ResultCode, err error) +} + +type ScribeClient struct { + Transport thrift.TTransport + ProtocolFactory thrift.TProtocolFactory + InputProtocol thrift.TProtocol + OutputProtocol thrift.TProtocol + SeqId int32 +} + +func NewScribeClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *ScribeClient { + return &ScribeClient{Transport: t, + ProtocolFactory: f, + InputProtocol: f.GetProtocol(t), + OutputProtocol: f.GetProtocol(t), + SeqId: 0, + } +} + +func NewScribeClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *ScribeClient { + return &ScribeClient{Transport: t, + ProtocolFactory: nil, + InputProtocol: iprot, + OutputProtocol: oprot, + SeqId: 0, + } +} + +// Parameters: +// - Messages +func (p *ScribeClient) Log(messages []*LogEntry) (r ResultCode, err error) { + if err = p.sendLog(messages); err != nil { + return + } + return p.recvLog() +} + +func (p *ScribeClient) sendLog(messages []*LogEntry) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("Log", thrift.CALL, p.SeqId); err != nil { + return + } + args := LogArgs{ + Messages: messages, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ScribeClient) recvLog() (value ResultCode, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error1 error + error1, err = error0.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error1 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Log failed: out of sequence response") + return + } + result := LogResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +type ScribeProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler Scribe +} + +func (p *ScribeProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *ScribeProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *ScribeProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewScribeProcessor(handler Scribe) *ScribeProcessor { + + self2 := &ScribeProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self2.processorMap["Log"] = &scribeProcessorLog{handler: handler} + return self2 +} + +func (p *ScribeProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x3 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x3.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, x3 + +} + +type scribeProcessorLog struct { + handler Scribe +} + +func (p *scribeProcessorLog) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := LogArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("Log", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := LogResult{} + var retval ResultCode + var err2 error + if retval, err2 = p.handler.Log(args.Messages); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Log: "+err2.Error()) + oprot.WriteMessageBegin("Log", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } else { + result.Success = &retval + } + if err2 = oprot.WriteMessageBegin("Log", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +// HELPER FUNCTIONS AND STRUCTURES + +type LogArgs struct { + Messages []*LogEntry `thrift:"messages,1" json:"messages"` +} + +func NewLogArgs() *LogArgs { + return &LogArgs{} +} + +func (p *LogArgs) GetMessages() []*LogEntry { + return p.Messages +} +func (p *LogArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *LogArgs) ReadField1(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*LogEntry, 0, size) + p.Messages = tSlice + for i := 0; i < size; i++ { + _elem4 := &LogEntry{} + if err := _elem4.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem4, err) + } + p.Messages = append(p.Messages, _elem4) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *LogArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Log_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *LogArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("messages", thrift.LIST, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:messages: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Messages)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Messages { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:messages: %s", p, err) + } + return err +} + +func (p *LogArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("LogArgs(%+v)", *p) +} + +type LogResult struct { + Success *ResultCode `thrift:"success,0" json:"success"` +} + +func NewLogResult() *LogResult { + return &LogResult{} +} + +var LogResult_Success_DEFAULT ResultCode + +func (p *LogResult) GetSuccess() ResultCode { + if !p.IsSetSuccess() { + return LogResult_Success_DEFAULT + } + return *p.Success +} +func (p *LogResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *LogResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *LogResult) ReadField0(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + temp := ResultCode(v) + p.Success = &temp + } + return nil +} + +func (p *LogResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Log_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *LogResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.I32, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteI32(int32(*p.Success)); err != nil { + return fmt.Errorf("%T.success (0) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *LogResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("LogResult(%+v)", *p) +} diff --git a/tracing/zipkin/thrift/gen-go/scribe/ttypes.go b/tracing/zipkin/thrift/gen-go/scribe/ttypes.go new file mode 100644 index 000000000..269989176 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/scribe/ttypes.go @@ -0,0 +1,168 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package scribe + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var GoUnusedProtection__ int + +type ResultCode int64 + +const ( + ResultCode_OK ResultCode = 0 + ResultCode_TRY_LATER ResultCode = 1 +) + +func (p ResultCode) String() string { + switch p { + case ResultCode_OK: + return "ResultCode_OK" + case ResultCode_TRY_LATER: + return "ResultCode_TRY_LATER" + } + return "" +} + +func ResultCodeFromString(s string) (ResultCode, error) { + switch s { + case "ResultCode_OK": + return ResultCode_OK, nil + case "ResultCode_TRY_LATER": + return ResultCode_TRY_LATER, nil + } + return ResultCode(0), fmt.Errorf("not a valid ResultCode string") +} + +func ResultCodePtr(v ResultCode) *ResultCode { return &v } + +type LogEntry struct { + Category string `thrift:"category,1" json:"category"` + Message string `thrift:"message,2" json:"message"` +} + +func NewLogEntry() *LogEntry { + return &LogEntry{} +} + +func (p *LogEntry) GetCategory() string { + return p.Category +} + +func (p *LogEntry) GetMessage() string { + return p.Message +} +func (p *LogEntry) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *LogEntry) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Category = v + } + return nil +} + +func (p *LogEntry) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.Message = v + } + return nil +} + +func (p *LogEntry) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("LogEntry"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *LogEntry) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("category", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:category: %s", p, err) + } + if err := oprot.WriteString(string(p.Category)); err != nil { + return fmt.Errorf("%T.category (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:category: %s", p, err) + } + return err +} + +func (p *LogEntry) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("message", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:message: %s", p, err) + } + if err := oprot.WriteString(string(p.Message)); err != nil { + return fmt.Errorf("%T.message (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:message: %s", p, err) + } + return err +} + +func (p *LogEntry) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("LogEntry(%+v)", *p) +} diff --git a/tracing/zipkin/thrift/gen-go/zipkincollector/constants.go b/tracing/zipkin/thrift/gen-go/zipkincollector/constants.go new file mode 100644 index 000000000..4dddb68b9 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkincollector/constants.go @@ -0,0 +1,23 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkincollector + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "scribe" + "zipkindependencies" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var _ = scribe.GoUnusedProtection__ +var _ = zipkindependencies.GoUnusedProtection__ + +func init() { +} diff --git a/tracing/zipkin/thrift/gen-go/zipkincollector/ttypes.go b/tracing/zipkin/thrift/gen-go/zipkincollector/ttypes.go new file mode 100644 index 000000000..931d4c480 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkincollector/ttypes.go @@ -0,0 +1,205 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkincollector + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "scribe" + "zipkindependencies" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var _ = scribe.GoUnusedProtection__ +var _ = zipkindependencies.GoUnusedProtection__ +var GoUnusedProtection__ int + +type AdjustableRateException struct { + Msg string `thrift:"msg,1" json:"msg"` +} + +func NewAdjustableRateException() *AdjustableRateException { + return &AdjustableRateException{} +} + +func (p *AdjustableRateException) GetMsg() string { + return p.Msg +} +func (p *AdjustableRateException) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *AdjustableRateException) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Msg = v + } + return nil +} + +func (p *AdjustableRateException) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("AdjustableRateException"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *AdjustableRateException) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("msg", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:msg: %s", p, err) + } + if err := oprot.WriteString(string(p.Msg)); err != nil { + return fmt.Errorf("%T.msg (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:msg: %s", p, err) + } + return err +} + +func (p *AdjustableRateException) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AdjustableRateException(%+v)", *p) +} + +func (p *AdjustableRateException) Error() string { + return p.String() +} + +type StoreAggregatesException struct { + Msg string `thrift:"msg,1" json:"msg"` +} + +func NewStoreAggregatesException() *StoreAggregatesException { + return &StoreAggregatesException{} +} + +func (p *StoreAggregatesException) GetMsg() string { + return p.Msg +} +func (p *StoreAggregatesException) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *StoreAggregatesException) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Msg = v + } + return nil +} + +func (p *StoreAggregatesException) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("StoreAggregatesException"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *StoreAggregatesException) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("msg", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:msg: %s", p, err) + } + if err := oprot.WriteString(string(p.Msg)); err != nil { + return fmt.Errorf("%T.msg (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:msg: %s", p, err) + } + return err +} + +func (p *StoreAggregatesException) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("StoreAggregatesException(%+v)", *p) +} + +func (p *StoreAggregatesException) Error() string { + return p.String() +} diff --git a/tracing/zipkin/thrift/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go b/tracing/zipkin/thrift/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go new file mode 100755 index 000000000..4602235a8 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go @@ -0,0 +1,234 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package main + +import ( + "flag" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "math" + "net" + "net/url" + "os" + "strconv" + "strings" + "zipkincollector" +) + +func Usage() { + fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") + flag.PrintDefaults() + fmt.Fprintln(os.Stderr, "\nFunctions:") + fmt.Fprintln(os.Stderr, " void storeTopAnnotations(string service_name, annotations)") + fmt.Fprintln(os.Stderr, " void storeTopKeyValueAnnotations(string service_name, annotations)") + fmt.Fprintln(os.Stderr, " void storeDependencies(Dependencies dependencies)") + fmt.Fprintln(os.Stderr, " ResultCode Log( messages)") + fmt.Fprintln(os.Stderr) + os.Exit(0) +} + +func main() { + flag.Usage = Usage + var host string + var port int + var protocol string + var urlString string + var framed bool + var useHttp bool + var parsedUrl url.URL + var trans thrift.TTransport + _ = strconv.Atoi + _ = math.Abs + flag.Usage = Usage + flag.StringVar(&host, "h", "localhost", "Specify host and port") + flag.IntVar(&port, "p", 9090, "Specify port") + flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") + flag.StringVar(&urlString, "u", "", "Specify the url") + flag.BoolVar(&framed, "framed", false, "Use framed transport") + flag.BoolVar(&useHttp, "http", false, "Use http") + flag.Parse() + + if len(urlString) > 0 { + parsedUrl, err := url.Parse(urlString) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + host = parsedUrl.Host + useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" + } else if useHttp { + _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + } + + cmd := flag.Arg(0) + var err error + if useHttp { + trans, err = thrift.NewTHttpClient(parsedUrl.String()) + } else { + portStr := fmt.Sprint(port) + if strings.Contains(host, ":") { + host, portStr, err = net.SplitHostPort(host) + if err != nil { + fmt.Fprintln(os.Stderr, "error with host:", err) + os.Exit(1) + } + } + trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) + if err != nil { + fmt.Fprintln(os.Stderr, "error resolving address:", err) + os.Exit(1) + } + if framed { + trans = thrift.NewTFramedTransport(trans) + } + } + if err != nil { + fmt.Fprintln(os.Stderr, "Error creating transport", err) + os.Exit(1) + } + defer trans.Close() + var protocolFactory thrift.TProtocolFactory + switch protocol { + case "compact": + protocolFactory = thrift.NewTCompactProtocolFactory() + break + case "simplejson": + protocolFactory = thrift.NewTSimpleJSONProtocolFactory() + break + case "json": + protocolFactory = thrift.NewTJSONProtocolFactory() + break + case "binary", "": + protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() + break + default: + fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) + Usage() + os.Exit(1) + } + client := zipkincollector.NewZipkinCollectorClientFactory(trans, protocolFactory) + if err := trans.Open(); err != nil { + fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) + os.Exit(1) + } + + switch cmd { + case "storeTopAnnotations": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "StoreTopAnnotations requires 2 args") + flag.Usage() + } + argvalue0 := flag.Arg(1) + value0 := argvalue0 + arg10 := flag.Arg(2) + mbTrans11 := thrift.NewTMemoryBufferLen(len(arg10)) + defer mbTrans11.Close() + _, err12 := mbTrans11.WriteString(arg10) + if err12 != nil { + Usage() + return + } + factory13 := thrift.NewTSimpleJSONProtocolFactory() + jsProt14 := factory13.GetProtocol(mbTrans11) + containerStruct1 := zipkincollector.NewStoreTopAnnotationsArgs() + err15 := containerStruct1.ReadField2(jsProt14) + if err15 != nil { + Usage() + return + } + argvalue1 := containerStruct1.Annotations + value1 := argvalue1 + fmt.Print(client.StoreTopAnnotations(value0, value1)) + fmt.Print("\n") + break + case "storeTopKeyValueAnnotations": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "StoreTopKeyValueAnnotations requires 2 args") + flag.Usage() + } + argvalue0 := flag.Arg(1) + value0 := argvalue0 + arg17 := flag.Arg(2) + mbTrans18 := thrift.NewTMemoryBufferLen(len(arg17)) + defer mbTrans18.Close() + _, err19 := mbTrans18.WriteString(arg17) + if err19 != nil { + Usage() + return + } + factory20 := thrift.NewTSimpleJSONProtocolFactory() + jsProt21 := factory20.GetProtocol(mbTrans18) + containerStruct1 := zipkincollector.NewStoreTopKeyValueAnnotationsArgs() + err22 := containerStruct1.ReadField2(jsProt21) + if err22 != nil { + Usage() + return + } + argvalue1 := containerStruct1.Annotations + value1 := argvalue1 + fmt.Print(client.StoreTopKeyValueAnnotations(value0, value1)) + fmt.Print("\n") + break + case "storeDependencies": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "StoreDependencies requires 1 args") + flag.Usage() + } + arg23 := flag.Arg(1) + mbTrans24 := thrift.NewTMemoryBufferLen(len(arg23)) + defer mbTrans24.Close() + _, err25 := mbTrans24.WriteString(arg23) + if err25 != nil { + Usage() + return + } + factory26 := thrift.NewTSimpleJSONProtocolFactory() + jsProt27 := factory26.GetProtocol(mbTrans24) + argvalue0 := zipkincollector.NewDependencies() + err28 := argvalue0.Read(jsProt27) + if err28 != nil { + Usage() + return + } + value0 := argvalue0 + fmt.Print(client.StoreDependencies(value0)) + fmt.Print("\n") + break + case "Log": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "Log requires 1 args") + flag.Usage() + } + arg29 := flag.Arg(1) + mbTrans30 := thrift.NewTMemoryBufferLen(len(arg29)) + defer mbTrans30.Close() + _, err31 := mbTrans30.WriteString(arg29) + if err31 != nil { + Usage() + return + } + factory32 := thrift.NewTSimpleJSONProtocolFactory() + jsProt33 := factory32.GetProtocol(mbTrans30) + containerStruct0 := zipkincollector.NewLogArgs() + err34 := containerStruct0.ReadField1(jsProt33) + if err34 != nil { + Usage() + return + } + argvalue0 := containerStruct0.Messages + value0 := argvalue0 + fmt.Print(client.Log(value0)) + fmt.Print("\n") + break + case "": + Usage() + break + default: + fmt.Fprintln(os.Stderr, "Invalid function ", cmd) + } +} diff --git a/tracing/zipkin/thrift/gen-go/zipkincollector/zipkincollector.go b/tracing/zipkin/thrift/gen-go/zipkincollector/zipkincollector.go new file mode 100644 index 000000000..1724abea4 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkincollector/zipkincollector.go @@ -0,0 +1,1112 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkincollector + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "scribe" + "zipkindependencies" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var _ = scribe.GoUnusedProtection__ +var _ = zipkindependencies.GoUnusedProtection__ + +type ZipkinCollector interface { + scribe.Scribe + + // Aggregates methods + // + // Parameters: + // - ServiceName + // - Annotations + StoreTopAnnotations(service_name string, annotations []string) (err error) + // Parameters: + // - ServiceName + // - Annotations + StoreTopKeyValueAnnotations(service_name string, annotations []string) (err error) + // Parameters: + // - Dependencies + StoreDependencies(dependencies *zipkindependencies.Dependencies) (err error) +} + +type ZipkinCollectorClient struct { + *scribe.ScribeClient +} + +func NewZipkinCollectorClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *ZipkinCollectorClient { + return &ZipkinCollectorClient{ScribeClient: scribe.NewScribeClientFactory(t, f)} +} + +func NewZipkinCollectorClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *ZipkinCollectorClient { + return &ZipkinCollectorClient{ScribeClient: scribe.NewScribeClientProtocol(t, iprot, oprot)} +} + +// Aggregates methods +// +// Parameters: +// - ServiceName +// - Annotations +func (p *ZipkinCollectorClient) StoreTopAnnotations(service_name string, annotations []string) (err error) { + if err = p.sendStoreTopAnnotations(service_name, annotations); err != nil { + return + } + return p.recvStoreTopAnnotations() +} + +func (p *ZipkinCollectorClient) sendStoreTopAnnotations(service_name string, annotations []string) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("storeTopAnnotations", thrift.CALL, p.SeqId); err != nil { + return + } + args := StoreTopAnnotationsArgs{ + ServiceName: service_name, + Annotations: annotations, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinCollectorClient) recvStoreTopAnnotations() (err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error1 error + error1, err = error0.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error1 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "storeTopAnnotations failed: out of sequence response") + return + } + result := StoreTopAnnotationsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.E != nil { + err = result.E + return + } + return +} + +// Parameters: +// - ServiceName +// - Annotations +func (p *ZipkinCollectorClient) StoreTopKeyValueAnnotations(service_name string, annotations []string) (err error) { + if err = p.sendStoreTopKeyValueAnnotations(service_name, annotations); err != nil { + return + } + return p.recvStoreTopKeyValueAnnotations() +} + +func (p *ZipkinCollectorClient) sendStoreTopKeyValueAnnotations(service_name string, annotations []string) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("storeTopKeyValueAnnotations", thrift.CALL, p.SeqId); err != nil { + return + } + args := StoreTopKeyValueAnnotationsArgs{ + ServiceName: service_name, + Annotations: annotations, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinCollectorClient) recvStoreTopKeyValueAnnotations() (err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error2 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error3 error + error3, err = error2.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error3 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "storeTopKeyValueAnnotations failed: out of sequence response") + return + } + result := StoreTopKeyValueAnnotationsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.E != nil { + err = result.E + return + } + return +} + +// Parameters: +// - Dependencies +func (p *ZipkinCollectorClient) StoreDependencies(dependencies *zipkindependencies.Dependencies) (err error) { + if err = p.sendStoreDependencies(dependencies); err != nil { + return + } + return p.recvStoreDependencies() +} + +func (p *ZipkinCollectorClient) sendStoreDependencies(dependencies *zipkindependencies.Dependencies) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("storeDependencies", thrift.CALL, p.SeqId); err != nil { + return + } + args := StoreDependenciesArgs{ + Dependencies: dependencies, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinCollectorClient) recvStoreDependencies() (err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error4 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error5 error + error5, err = error4.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error5 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "storeDependencies failed: out of sequence response") + return + } + result := StoreDependenciesResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.E != nil { + err = result.E + return + } + return +} + +type ZipkinCollectorProcessor struct { + *scribe.ScribeProcessor +} + +func NewZipkinCollectorProcessor(handler ZipkinCollector) *ZipkinCollectorProcessor { + self6 := &ZipkinCollectorProcessor{scribe.NewScribeProcessor(handler)} + self6.AddToProcessorMap("storeTopAnnotations", &zipkinCollectorProcessorStoreTopAnnotations{handler: handler}) + self6.AddToProcessorMap("storeTopKeyValueAnnotations", &zipkinCollectorProcessorStoreTopKeyValueAnnotations{handler: handler}) + self6.AddToProcessorMap("storeDependencies", &zipkinCollectorProcessorStoreDependencies{handler: handler}) + return self6 +} + +type zipkinCollectorProcessorStoreTopAnnotations struct { + handler ZipkinCollector +} + +func (p *zipkinCollectorProcessorStoreTopAnnotations) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := StoreTopAnnotationsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("storeTopAnnotations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := StoreTopAnnotationsResult{} + var err2 error + if err2 = p.handler.StoreTopAnnotations(args.ServiceName, args.Annotations); err2 != nil { + switch v := err2.(type) { + case *StoreAggregatesException: + result.E = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing storeTopAnnotations: "+err2.Error()) + oprot.WriteMessageBegin("storeTopAnnotations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } + if err2 = oprot.WriteMessageBegin("storeTopAnnotations", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinCollectorProcessorStoreTopKeyValueAnnotations struct { + handler ZipkinCollector +} + +func (p *zipkinCollectorProcessorStoreTopKeyValueAnnotations) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := StoreTopKeyValueAnnotationsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("storeTopKeyValueAnnotations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := StoreTopKeyValueAnnotationsResult{} + var err2 error + if err2 = p.handler.StoreTopKeyValueAnnotations(args.ServiceName, args.Annotations); err2 != nil { + switch v := err2.(type) { + case *StoreAggregatesException: + result.E = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing storeTopKeyValueAnnotations: "+err2.Error()) + oprot.WriteMessageBegin("storeTopKeyValueAnnotations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } + if err2 = oprot.WriteMessageBegin("storeTopKeyValueAnnotations", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinCollectorProcessorStoreDependencies struct { + handler ZipkinCollector +} + +func (p *zipkinCollectorProcessorStoreDependencies) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := StoreDependenciesArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("storeDependencies", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := StoreDependenciesResult{} + var err2 error + if err2 = p.handler.StoreDependencies(args.Dependencies); err2 != nil { + switch v := err2.(type) { + case *StoreAggregatesException: + result.E = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing storeDependencies: "+err2.Error()) + oprot.WriteMessageBegin("storeDependencies", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } + if err2 = oprot.WriteMessageBegin("storeDependencies", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +// HELPER FUNCTIONS AND STRUCTURES + +type StoreTopAnnotationsArgs struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` + Annotations []string `thrift:"annotations,2" json:"annotations"` +} + +func NewStoreTopAnnotationsArgs() *StoreTopAnnotationsArgs { + return &StoreTopAnnotationsArgs{} +} + +func (p *StoreTopAnnotationsArgs) GetServiceName() string { + return p.ServiceName +} + +func (p *StoreTopAnnotationsArgs) GetAnnotations() []string { + return p.Annotations +} +func (p *StoreTopAnnotationsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *StoreTopAnnotationsArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *StoreTopAnnotationsArgs) ReadField2(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]string, 0, size) + p.Annotations = tSlice + for i := 0; i < size; i++ { + var _elem7 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem7 = v + } + p.Annotations = append(p.Annotations, _elem7) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *StoreTopAnnotationsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("storeTopAnnotations_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *StoreTopAnnotationsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *StoreTopAnnotationsArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("annotations", thrift.LIST, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:annotations: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRING, len(p.Annotations)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Annotations { + if err := oprot.WriteString(string(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:annotations: %s", p, err) + } + return err +} + +func (p *StoreTopAnnotationsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("StoreTopAnnotationsArgs(%+v)", *p) +} + +type StoreTopAnnotationsResult struct { + E *StoreAggregatesException `thrift:"e,1" json:"e"` +} + +func NewStoreTopAnnotationsResult() *StoreTopAnnotationsResult { + return &StoreTopAnnotationsResult{} +} + +var StoreTopAnnotationsResult_E_DEFAULT *StoreAggregatesException + +func (p *StoreTopAnnotationsResult) GetE() *StoreAggregatesException { + if !p.IsSetE() { + return StoreTopAnnotationsResult_E_DEFAULT + } + return p.E +} +func (p *StoreTopAnnotationsResult) IsSetE() bool { + return p.E != nil +} + +func (p *StoreTopAnnotationsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *StoreTopAnnotationsResult) ReadField1(iprot thrift.TProtocol) error { + p.E = &StoreAggregatesException{} + if err := p.E.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.E, err) + } + return nil +} + +func (p *StoreTopAnnotationsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("storeTopAnnotations_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *StoreTopAnnotationsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetE() { + if err := oprot.WriteFieldBegin("e", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:e: %s", p, err) + } + if err := p.E.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.E, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:e: %s", p, err) + } + } + return err +} + +func (p *StoreTopAnnotationsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("StoreTopAnnotationsResult(%+v)", *p) +} + +type StoreTopKeyValueAnnotationsArgs struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` + Annotations []string `thrift:"annotations,2" json:"annotations"` +} + +func NewStoreTopKeyValueAnnotationsArgs() *StoreTopKeyValueAnnotationsArgs { + return &StoreTopKeyValueAnnotationsArgs{} +} + +func (p *StoreTopKeyValueAnnotationsArgs) GetServiceName() string { + return p.ServiceName +} + +func (p *StoreTopKeyValueAnnotationsArgs) GetAnnotations() []string { + return p.Annotations +} +func (p *StoreTopKeyValueAnnotationsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *StoreTopKeyValueAnnotationsArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *StoreTopKeyValueAnnotationsArgs) ReadField2(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]string, 0, size) + p.Annotations = tSlice + for i := 0; i < size; i++ { + var _elem8 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem8 = v + } + p.Annotations = append(p.Annotations, _elem8) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *StoreTopKeyValueAnnotationsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("storeTopKeyValueAnnotations_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *StoreTopKeyValueAnnotationsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *StoreTopKeyValueAnnotationsArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("annotations", thrift.LIST, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:annotations: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRING, len(p.Annotations)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Annotations { + if err := oprot.WriteString(string(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:annotations: %s", p, err) + } + return err +} + +func (p *StoreTopKeyValueAnnotationsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("StoreTopKeyValueAnnotationsArgs(%+v)", *p) +} + +type StoreTopKeyValueAnnotationsResult struct { + E *StoreAggregatesException `thrift:"e,1" json:"e"` +} + +func NewStoreTopKeyValueAnnotationsResult() *StoreTopKeyValueAnnotationsResult { + return &StoreTopKeyValueAnnotationsResult{} +} + +var StoreTopKeyValueAnnotationsResult_E_DEFAULT *StoreAggregatesException + +func (p *StoreTopKeyValueAnnotationsResult) GetE() *StoreAggregatesException { + if !p.IsSetE() { + return StoreTopKeyValueAnnotationsResult_E_DEFAULT + } + return p.E +} +func (p *StoreTopKeyValueAnnotationsResult) IsSetE() bool { + return p.E != nil +} + +func (p *StoreTopKeyValueAnnotationsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *StoreTopKeyValueAnnotationsResult) ReadField1(iprot thrift.TProtocol) error { + p.E = &StoreAggregatesException{} + if err := p.E.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.E, err) + } + return nil +} + +func (p *StoreTopKeyValueAnnotationsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("storeTopKeyValueAnnotations_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *StoreTopKeyValueAnnotationsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetE() { + if err := oprot.WriteFieldBegin("e", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:e: %s", p, err) + } + if err := p.E.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.E, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:e: %s", p, err) + } + } + return err +} + +func (p *StoreTopKeyValueAnnotationsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("StoreTopKeyValueAnnotationsResult(%+v)", *p) +} + +type StoreDependenciesArgs struct { + Dependencies *zipkindependencies.Dependencies `thrift:"dependencies,1" json:"dependencies"` +} + +func NewStoreDependenciesArgs() *StoreDependenciesArgs { + return &StoreDependenciesArgs{} +} + +var StoreDependenciesArgs_Dependencies_DEFAULT *zipkindependencies.Dependencies + +func (p *StoreDependenciesArgs) GetDependencies() *zipkindependencies.Dependencies { + if !p.IsSetDependencies() { + return StoreDependenciesArgs_Dependencies_DEFAULT + } + return p.Dependencies +} +func (p *StoreDependenciesArgs) IsSetDependencies() bool { + return p.Dependencies != nil +} + +func (p *StoreDependenciesArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *StoreDependenciesArgs) ReadField1(iprot thrift.TProtocol) error { + p.Dependencies = &zipkindependencies.Dependencies{} + if err := p.Dependencies.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Dependencies, err) + } + return nil +} + +func (p *StoreDependenciesArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("storeDependencies_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *StoreDependenciesArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("dependencies", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:dependencies: %s", p, err) + } + if err := p.Dependencies.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Dependencies, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:dependencies: %s", p, err) + } + return err +} + +func (p *StoreDependenciesArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("StoreDependenciesArgs(%+v)", *p) +} + +type StoreDependenciesResult struct { + E *StoreAggregatesException `thrift:"e,1" json:"e"` +} + +func NewStoreDependenciesResult() *StoreDependenciesResult { + return &StoreDependenciesResult{} +} + +var StoreDependenciesResult_E_DEFAULT *StoreAggregatesException + +func (p *StoreDependenciesResult) GetE() *StoreAggregatesException { + if !p.IsSetE() { + return StoreDependenciesResult_E_DEFAULT + } + return p.E +} +func (p *StoreDependenciesResult) IsSetE() bool { + return p.E != nil +} + +func (p *StoreDependenciesResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *StoreDependenciesResult) ReadField1(iprot thrift.TProtocol) error { + p.E = &StoreAggregatesException{} + if err := p.E.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.E, err) + } + return nil +} + +func (p *StoreDependenciesResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("storeDependencies_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *StoreDependenciesResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetE() { + if err := oprot.WriteFieldBegin("e", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:e: %s", p, err) + } + if err := p.E.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.E, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:e: %s", p, err) + } + } + return err +} + +func (p *StoreDependenciesResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("StoreDependenciesResult(%+v)", *p) +} diff --git a/tracing/zipkin/thrift/gen-go/zipkincore/constants.go b/tracing/zipkin/thrift/gen-go/zipkincore/constants.go new file mode 100644 index 000000000..5808fdf45 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkincore/constants.go @@ -0,0 +1,23 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkincore + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +const CLIENT_SEND = "cs" +const CLIENT_RECV = "cr" +const SERVER_SEND = "ss" +const SERVER_RECV = "sr" + +func init() { +} diff --git a/tracing/zipkin/thrift/gen-go/zipkincore/ttypes.go b/tracing/zipkin/thrift/gen-go/zipkincore/ttypes.go new file mode 100644 index 000000000..365ed8ba0 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkincore/ttypes.go @@ -0,0 +1,990 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkincore + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var GoUnusedProtection__ int + +type AnnotationType int64 + +const ( + AnnotationType_BOOL AnnotationType = 0 + AnnotationType_BYTES AnnotationType = 1 + AnnotationType_I16 AnnotationType = 2 + AnnotationType_I32 AnnotationType = 3 + AnnotationType_I64 AnnotationType = 4 + AnnotationType_DOUBLE AnnotationType = 5 + AnnotationType_STRING AnnotationType = 6 +) + +func (p AnnotationType) String() string { + switch p { + case AnnotationType_BOOL: + return "AnnotationType_BOOL" + case AnnotationType_BYTES: + return "AnnotationType_BYTES" + case AnnotationType_I16: + return "AnnotationType_I16" + case AnnotationType_I32: + return "AnnotationType_I32" + case AnnotationType_I64: + return "AnnotationType_I64" + case AnnotationType_DOUBLE: + return "AnnotationType_DOUBLE" + case AnnotationType_STRING: + return "AnnotationType_STRING" + } + return "" +} + +func AnnotationTypeFromString(s string) (AnnotationType, error) { + switch s { + case "AnnotationType_BOOL": + return AnnotationType_BOOL, nil + case "AnnotationType_BYTES": + return AnnotationType_BYTES, nil + case "AnnotationType_I16": + return AnnotationType_I16, nil + case "AnnotationType_I32": + return AnnotationType_I32, nil + case "AnnotationType_I64": + return AnnotationType_I64, nil + case "AnnotationType_DOUBLE": + return AnnotationType_DOUBLE, nil + case "AnnotationType_STRING": + return AnnotationType_STRING, nil + } + return AnnotationType(0), fmt.Errorf("not a valid AnnotationType string") +} + +func AnnotationTypePtr(v AnnotationType) *AnnotationType { return &v } + +type Endpoint struct { + Ipv4 int32 `thrift:"ipv4,1" json:"ipv4"` + Port int16 `thrift:"port,2" json:"port"` + ServiceName string `thrift:"service_name,3" json:"service_name"` +} + +func NewEndpoint() *Endpoint { + return &Endpoint{} +} + +func (p *Endpoint) GetIpv4() int32 { + return p.Ipv4 +} + +func (p *Endpoint) GetPort() int16 { + return p.Port +} + +func (p *Endpoint) GetServiceName() string { + return p.ServiceName +} +func (p *Endpoint) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *Endpoint) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Ipv4 = v + } + return nil +} + +func (p *Endpoint) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI16(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.Port = v + } + return nil +} + +func (p *Endpoint) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *Endpoint) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Endpoint"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *Endpoint) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("ipv4", thrift.I32, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:ipv4: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Ipv4)); err != nil { + return fmt.Errorf("%T.ipv4 (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:ipv4: %s", p, err) + } + return err +} + +func (p *Endpoint) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("port", thrift.I16, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:port: %s", p, err) + } + if err := oprot.WriteI16(int16(p.Port)); err != nil { + return fmt.Errorf("%T.port (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:port: %s", p, err) + } + return err +} + +func (p *Endpoint) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:service_name: %s", p, err) + } + return err +} + +func (p *Endpoint) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Endpoint(%+v)", *p) +} + +type Annotation struct { + Timestamp int64 `thrift:"timestamp,1" json:"timestamp"` + Value string `thrift:"value,2" json:"value"` + Host *Endpoint `thrift:"host,3" json:"host"` + Duration *int32 `thrift:"duration,4" json:"duration"` +} + +func NewAnnotation() *Annotation { + return &Annotation{} +} + +func (p *Annotation) GetTimestamp() int64 { + return p.Timestamp +} + +func (p *Annotation) GetValue() string { + return p.Value +} + +var Annotation_Host_DEFAULT *Endpoint + +func (p *Annotation) GetHost() *Endpoint { + if !p.IsSetHost() { + return Annotation_Host_DEFAULT + } + return p.Host +} + +var Annotation_Duration_DEFAULT int32 + +func (p *Annotation) GetDuration() int32 { + if !p.IsSetDuration() { + return Annotation_Duration_DEFAULT + } + return *p.Duration +} +func (p *Annotation) IsSetHost() bool { + return p.Host != nil +} + +func (p *Annotation) IsSetDuration() bool { + return p.Duration != nil +} + +func (p *Annotation) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *Annotation) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Timestamp = v + } + return nil +} + +func (p *Annotation) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.Value = v + } + return nil +} + +func (p *Annotation) ReadField3(iprot thrift.TProtocol) error { + p.Host = &Endpoint{} + if err := p.Host.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Host, err) + } + return nil +} + +func (p *Annotation) ReadField4(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 4: %s", err) + } else { + p.Duration = &v + } + return nil +} + +func (p *Annotation) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Annotation"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *Annotation) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("timestamp", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:timestamp: %s", p, err) + } + if err := oprot.WriteI64(int64(p.Timestamp)); err != nil { + return fmt.Errorf("%T.timestamp (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:timestamp: %s", p, err) + } + return err +} + +func (p *Annotation) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("value", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:value: %s", p, err) + } + if err := oprot.WriteString(string(p.Value)); err != nil { + return fmt.Errorf("%T.value (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:value: %s", p, err) + } + return err +} + +func (p *Annotation) writeField3(oprot thrift.TProtocol) (err error) { + if p.IsSetHost() { + if err := oprot.WriteFieldBegin("host", thrift.STRUCT, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:host: %s", p, err) + } + if err := p.Host.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Host, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:host: %s", p, err) + } + } + return err +} + +func (p *Annotation) writeField4(oprot thrift.TProtocol) (err error) { + if p.IsSetDuration() { + if err := oprot.WriteFieldBegin("duration", thrift.I32, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:duration: %s", p, err) + } + if err := oprot.WriteI32(int32(*p.Duration)); err != nil { + return fmt.Errorf("%T.duration (4) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:duration: %s", p, err) + } + } + return err +} + +func (p *Annotation) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Annotation(%+v)", *p) +} + +type BinaryAnnotation struct { + Key string `thrift:"key,1" json:"key"` + Value []byte `thrift:"value,2" json:"value"` + AnnotationType AnnotationType `thrift:"annotation_type,3" json:"annotation_type"` + Host *Endpoint `thrift:"host,4" json:"host"` +} + +func NewBinaryAnnotation() *BinaryAnnotation { + return &BinaryAnnotation{} +} + +func (p *BinaryAnnotation) GetKey() string { + return p.Key +} + +func (p *BinaryAnnotation) GetValue() []byte { + return p.Value +} + +func (p *BinaryAnnotation) GetAnnotationType() AnnotationType { + return p.AnnotationType +} + +var BinaryAnnotation_Host_DEFAULT *Endpoint + +func (p *BinaryAnnotation) GetHost() *Endpoint { + if !p.IsSetHost() { + return BinaryAnnotation_Host_DEFAULT + } + return p.Host +} +func (p *BinaryAnnotation) IsSetHost() bool { + return p.Host != nil +} + +func (p *BinaryAnnotation) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *BinaryAnnotation) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Key = v + } + return nil +} + +func (p *BinaryAnnotation) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.Value = v + } + return nil +} + +func (p *BinaryAnnotation) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + temp := AnnotationType(v) + p.AnnotationType = temp + } + return nil +} + +func (p *BinaryAnnotation) ReadField4(iprot thrift.TProtocol) error { + p.Host = &Endpoint{} + if err := p.Host.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Host, err) + } + return nil +} + +func (p *BinaryAnnotation) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("BinaryAnnotation"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *BinaryAnnotation) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("key", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:key: %s", p, err) + } + if err := oprot.WriteString(string(p.Key)); err != nil { + return fmt.Errorf("%T.key (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:key: %s", p, err) + } + return err +} + +func (p *BinaryAnnotation) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("value", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:value: %s", p, err) + } + if err := oprot.WriteBinary(p.Value); err != nil { + return fmt.Errorf("%T.value (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:value: %s", p, err) + } + return err +} + +func (p *BinaryAnnotation) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("annotation_type", thrift.I32, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:annotation_type: %s", p, err) + } + if err := oprot.WriteI32(int32(p.AnnotationType)); err != nil { + return fmt.Errorf("%T.annotation_type (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:annotation_type: %s", p, err) + } + return err +} + +func (p *BinaryAnnotation) writeField4(oprot thrift.TProtocol) (err error) { + if p.IsSetHost() { + if err := oprot.WriteFieldBegin("host", thrift.STRUCT, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:host: %s", p, err) + } + if err := p.Host.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Host, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:host: %s", p, err) + } + } + return err +} + +func (p *BinaryAnnotation) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("BinaryAnnotation(%+v)", *p) +} + +type Span struct { + TraceId int64 `thrift:"trace_id,1" json:"trace_id"` + // unused field # 2 + Name string `thrift:"name,3" json:"name"` + Id int64 `thrift:"id,4" json:"id"` + ParentId *int64 `thrift:"parent_id,5" json:"parent_id"` + Annotations []*Annotation `thrift:"annotations,6" json:"annotations"` + // unused field # 7 + BinaryAnnotations []*BinaryAnnotation `thrift:"binary_annotations,8" json:"binary_annotations"` + Debug bool `thrift:"debug,9" json:"debug"` +} + +func NewSpan() *Span { + return &Span{} +} + +func (p *Span) GetTraceId() int64 { + return p.TraceId +} + +func (p *Span) GetName() string { + return p.Name +} + +func (p *Span) GetId() int64 { + return p.Id +} + +var Span_ParentId_DEFAULT int64 + +func (p *Span) GetParentId() int64 { + if !p.IsSetParentId() { + return Span_ParentId_DEFAULT + } + return *p.ParentId +} + +func (p *Span) GetAnnotations() []*Annotation { + return p.Annotations +} + +func (p *Span) GetBinaryAnnotations() []*BinaryAnnotation { + return p.BinaryAnnotations +} + +var Span_Debug_DEFAULT bool = false + +func (p *Span) GetDebug() bool { + return p.Debug +} +func (p *Span) IsSetParentId() bool { + return p.ParentId != nil +} + +func (p *Span) IsSetDebug() bool { + return p.Debug != Span_Debug_DEFAULT +} + +func (p *Span) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 8: + if err := p.ReadField8(iprot); err != nil { + return err + } + case 9: + if err := p.ReadField9(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *Span) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.TraceId = v + } + return nil +} + +func (p *Span) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.Name = v + } + return nil +} + +func (p *Span) ReadField4(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 4: %s", err) + } else { + p.Id = v + } + return nil +} + +func (p *Span) ReadField5(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 5: %s", err) + } else { + p.ParentId = &v + } + return nil +} + +func (p *Span) ReadField6(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*Annotation, 0, size) + p.Annotations = tSlice + for i := 0; i < size; i++ { + _elem0 := &Annotation{} + if err := _elem0.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem0, err) + } + p.Annotations = append(p.Annotations, _elem0) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *Span) ReadField8(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*BinaryAnnotation, 0, size) + p.BinaryAnnotations = tSlice + for i := 0; i < size; i++ { + _elem1 := &BinaryAnnotation{} + if err := _elem1.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem1, err) + } + p.BinaryAnnotations = append(p.BinaryAnnotations, _elem1) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *Span) ReadField9(iprot thrift.TProtocol) error { + if v, err := iprot.ReadBool(); err != nil { + return fmt.Errorf("error reading field 9: %s", err) + } else { + p.Debug = v + } + return nil +} + +func (p *Span) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Span"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := p.writeField5(oprot); err != nil { + return err + } + if err := p.writeField6(oprot); err != nil { + return err + } + if err := p.writeField8(oprot); err != nil { + return err + } + if err := p.writeField9(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *Span) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_id", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_id: %s", p, err) + } + if err := oprot.WriteI64(int64(p.TraceId)); err != nil { + return fmt.Errorf("%T.trace_id (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_id: %s", p, err) + } + return err +} + +func (p *Span) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("name", thrift.STRING, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:name: %s", p, err) + } + if err := oprot.WriteString(string(p.Name)); err != nil { + return fmt.Errorf("%T.name (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:name: %s", p, err) + } + return err +} + +func (p *Span) writeField4(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("id", thrift.I64, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:id: %s", p, err) + } + if err := oprot.WriteI64(int64(p.Id)); err != nil { + return fmt.Errorf("%T.id (4) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:id: %s", p, err) + } + return err +} + +func (p *Span) writeField5(oprot thrift.TProtocol) (err error) { + if p.IsSetParentId() { + if err := oprot.WriteFieldBegin("parent_id", thrift.I64, 5); err != nil { + return fmt.Errorf("%T write field begin error 5:parent_id: %s", p, err) + } + if err := oprot.WriteI64(int64(*p.ParentId)); err != nil { + return fmt.Errorf("%T.parent_id (5) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 5:parent_id: %s", p, err) + } + } + return err +} + +func (p *Span) writeField6(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("annotations", thrift.LIST, 6); err != nil { + return fmt.Errorf("%T write field begin error 6:annotations: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Annotations)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Annotations { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 6:annotations: %s", p, err) + } + return err +} + +func (p *Span) writeField8(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("binary_annotations", thrift.LIST, 8); err != nil { + return fmt.Errorf("%T write field begin error 8:binary_annotations: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.BinaryAnnotations)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.BinaryAnnotations { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 8:binary_annotations: %s", p, err) + } + return err +} + +func (p *Span) writeField9(oprot thrift.TProtocol) (err error) { + if p.IsSetDebug() { + if err := oprot.WriteFieldBegin("debug", thrift.BOOL, 9); err != nil { + return fmt.Errorf("%T write field begin error 9:debug: %s", p, err) + } + if err := oprot.WriteBool(bool(p.Debug)); err != nil { + return fmt.Errorf("%T.debug (9) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 9:debug: %s", p, err) + } + } + return err +} + +func (p *Span) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Span(%+v)", *p) +} diff --git a/tracing/zipkin/thrift/gen-go/zipkindependencies/constants.go b/tracing/zipkin/thrift/gen-go/zipkindependencies/constants.go new file mode 100644 index 000000000..16d060abb --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkindependencies/constants.go @@ -0,0 +1,18 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkindependencies + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +func init() { +} diff --git a/tracing/zipkin/thrift/gen-go/zipkindependencies/ttypes.go b/tracing/zipkin/thrift/gen-go/zipkindependencies/ttypes.go new file mode 100644 index 000000000..b4de42e51 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkindependencies/ttypes.go @@ -0,0 +1,580 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkindependencies + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var GoUnusedProtection__ int + +type Moments struct { + M0 int64 `thrift:"m0,1" json:"m0"` + M1 float64 `thrift:"m1,2" json:"m1"` + M2 float64 `thrift:"m2,3" json:"m2"` + M3 float64 `thrift:"m3,4" json:"m3"` + M4 float64 `thrift:"m4,5" json:"m4"` +} + +func NewMoments() *Moments { + return &Moments{} +} + +func (p *Moments) GetM0() int64 { + return p.M0 +} + +func (p *Moments) GetM1() float64 { + return p.M1 +} + +func (p *Moments) GetM2() float64 { + return p.M2 +} + +func (p *Moments) GetM3() float64 { + return p.M3 +} + +func (p *Moments) GetM4() float64 { + return p.M4 +} +func (p *Moments) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *Moments) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.M0 = v + } + return nil +} + +func (p *Moments) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadDouble(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.M1 = v + } + return nil +} + +func (p *Moments) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadDouble(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.M2 = v + } + return nil +} + +func (p *Moments) ReadField4(iprot thrift.TProtocol) error { + if v, err := iprot.ReadDouble(); err != nil { + return fmt.Errorf("error reading field 4: %s", err) + } else { + p.M3 = v + } + return nil +} + +func (p *Moments) ReadField5(iprot thrift.TProtocol) error { + if v, err := iprot.ReadDouble(); err != nil { + return fmt.Errorf("error reading field 5: %s", err) + } else { + p.M4 = v + } + return nil +} + +func (p *Moments) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Moments"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := p.writeField5(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *Moments) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("m0", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:m0: %s", p, err) + } + if err := oprot.WriteI64(int64(p.M0)); err != nil { + return fmt.Errorf("%T.m0 (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:m0: %s", p, err) + } + return err +} + +func (p *Moments) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("m1", thrift.DOUBLE, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:m1: %s", p, err) + } + if err := oprot.WriteDouble(float64(p.M1)); err != nil { + return fmt.Errorf("%T.m1 (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:m1: %s", p, err) + } + return err +} + +func (p *Moments) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("m2", thrift.DOUBLE, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:m2: %s", p, err) + } + if err := oprot.WriteDouble(float64(p.M2)); err != nil { + return fmt.Errorf("%T.m2 (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:m2: %s", p, err) + } + return err +} + +func (p *Moments) writeField4(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("m3", thrift.DOUBLE, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:m3: %s", p, err) + } + if err := oprot.WriteDouble(float64(p.M3)); err != nil { + return fmt.Errorf("%T.m3 (4) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:m3: %s", p, err) + } + return err +} + +func (p *Moments) writeField5(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("m4", thrift.DOUBLE, 5); err != nil { + return fmt.Errorf("%T write field begin error 5:m4: %s", p, err) + } + if err := oprot.WriteDouble(float64(p.M4)); err != nil { + return fmt.Errorf("%T.m4 (5) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 5:m4: %s", p, err) + } + return err +} + +func (p *Moments) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Moments(%+v)", *p) +} + +type DependencyLink struct { + Parent string `thrift:"parent,1" json:"parent"` + Child string `thrift:"child,2" json:"child"` + DurationMoments *Moments `thrift:"duration_moments,3" json:"duration_moments"` +} + +func NewDependencyLink() *DependencyLink { + return &DependencyLink{} +} + +func (p *DependencyLink) GetParent() string { + return p.Parent +} + +func (p *DependencyLink) GetChild() string { + return p.Child +} + +var DependencyLink_DurationMoments_DEFAULT *Moments + +func (p *DependencyLink) GetDurationMoments() *Moments { + if !p.IsSetDurationMoments() { + return DependencyLink_DurationMoments_DEFAULT + } + return p.DurationMoments +} +func (p *DependencyLink) IsSetDurationMoments() bool { + return p.DurationMoments != nil +} + +func (p *DependencyLink) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *DependencyLink) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Parent = v + } + return nil +} + +func (p *DependencyLink) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.Child = v + } + return nil +} + +func (p *DependencyLink) ReadField3(iprot thrift.TProtocol) error { + p.DurationMoments = &Moments{} + if err := p.DurationMoments.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.DurationMoments, err) + } + return nil +} + +func (p *DependencyLink) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("DependencyLink"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *DependencyLink) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("parent", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:parent: %s", p, err) + } + if err := oprot.WriteString(string(p.Parent)); err != nil { + return fmt.Errorf("%T.parent (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:parent: %s", p, err) + } + return err +} + +func (p *DependencyLink) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("child", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:child: %s", p, err) + } + if err := oprot.WriteString(string(p.Child)); err != nil { + return fmt.Errorf("%T.child (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:child: %s", p, err) + } + return err +} + +func (p *DependencyLink) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("duration_moments", thrift.STRUCT, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:duration_moments: %s", p, err) + } + if err := p.DurationMoments.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.DurationMoments, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:duration_moments: %s", p, err) + } + return err +} + +func (p *DependencyLink) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("DependencyLink(%+v)", *p) +} + +type Dependencies struct { + StartTime int64 `thrift:"start_time,1" json:"start_time"` + EndTime int64 `thrift:"end_time,2" json:"end_time"` + Links []*DependencyLink `thrift:"links,3" json:"links"` +} + +func NewDependencies() *Dependencies { + return &Dependencies{} +} + +func (p *Dependencies) GetStartTime() int64 { + return p.StartTime +} + +func (p *Dependencies) GetEndTime() int64 { + return p.EndTime +} + +func (p *Dependencies) GetLinks() []*DependencyLink { + return p.Links +} +func (p *Dependencies) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *Dependencies) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.StartTime = v + } + return nil +} + +func (p *Dependencies) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.EndTime = v + } + return nil +} + +func (p *Dependencies) ReadField3(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*DependencyLink, 0, size) + p.Links = tSlice + for i := 0; i < size; i++ { + _elem0 := &DependencyLink{} + if err := _elem0.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem0, err) + } + p.Links = append(p.Links, _elem0) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *Dependencies) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Dependencies"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *Dependencies) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("start_time", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:start_time: %s", p, err) + } + if err := oprot.WriteI64(int64(p.StartTime)); err != nil { + return fmt.Errorf("%T.start_time (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:start_time: %s", p, err) + } + return err +} + +func (p *Dependencies) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_time", thrift.I64, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:end_time: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTime)); err != nil { + return fmt.Errorf("%T.end_time (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:end_time: %s", p, err) + } + return err +} + +func (p *Dependencies) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("links", thrift.LIST, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:links: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Links)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Links { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:links: %s", p, err) + } + return err +} + +func (p *Dependencies) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Dependencies(%+v)", *p) +} diff --git a/tracing/zipkin/thrift/gen-go/zipkinquery/constants.go b/tracing/zipkin/thrift/gen-go/zipkinquery/constants.go new file mode 100644 index 000000000..5c176e66f --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkinquery/constants.go @@ -0,0 +1,23 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkinquery + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "zipkincore" + "zipkindependencies" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var _ = zipkincore.GoUnusedProtection__ +var _ = zipkindependencies.GoUnusedProtection__ + +func init() { +} diff --git a/tracing/zipkin/thrift/gen-go/zipkinquery/ttypes.go b/tracing/zipkin/thrift/gen-go/zipkinquery/ttypes.go new file mode 100644 index 000000000..1fedbd6e7 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkinquery/ttypes.go @@ -0,0 +1,2085 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkinquery + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "zipkincore" + "zipkindependencies" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var _ = zipkincore.GoUnusedProtection__ +var _ = zipkindependencies.GoUnusedProtection__ +var GoUnusedProtection__ int + +type Order int64 + +const ( + Order_TIMESTAMP_DESC Order = 0 + Order_TIMESTAMP_ASC Order = 1 + Order_DURATION_ASC Order = 2 + Order_DURATION_DESC Order = 3 + Order_NONE Order = 4 +) + +func (p Order) String() string { + switch p { + case Order_TIMESTAMP_DESC: + return "Order_TIMESTAMP_DESC" + case Order_TIMESTAMP_ASC: + return "Order_TIMESTAMP_ASC" + case Order_DURATION_ASC: + return "Order_DURATION_ASC" + case Order_DURATION_DESC: + return "Order_DURATION_DESC" + case Order_NONE: + return "Order_NONE" + } + return "" +} + +func OrderFromString(s string) (Order, error) { + switch s { + case "Order_TIMESTAMP_DESC": + return Order_TIMESTAMP_DESC, nil + case "Order_TIMESTAMP_ASC": + return Order_TIMESTAMP_ASC, nil + case "Order_DURATION_ASC": + return Order_DURATION_ASC, nil + case "Order_DURATION_DESC": + return Order_DURATION_DESC, nil + case "Order_NONE": + return Order_NONE, nil + } + return Order(0), fmt.Errorf("not a valid Order string") +} + +func OrderPtr(v Order) *Order { return &v } + +//The raw data in our storage might have various problems. How should we adjust it before +//returning it to the user? +// +//Time skew adjuster tries to make sure that even though servers might have slightly +//different clocks the annotations in the returned data are adjusted so that they are +//in the correct order. +type Adjust int64 + +const ( + Adjust_NOTHING Adjust = 0 + Adjust_TIME_SKEW Adjust = 1 +) + +func (p Adjust) String() string { + switch p { + case Adjust_NOTHING: + return "Adjust_NOTHING" + case Adjust_TIME_SKEW: + return "Adjust_TIME_SKEW" + } + return "" +} + +func AdjustFromString(s string) (Adjust, error) { + switch s { + case "Adjust_NOTHING": + return Adjust_NOTHING, nil + case "Adjust_TIME_SKEW": + return Adjust_TIME_SKEW, nil + } + return Adjust(0), fmt.Errorf("not a valid Adjust string") +} + +func AdjustPtr(v Adjust) *Adjust { return &v } + +type Trace struct { + Spans []*zipkincore.Span `thrift:"spans,1" json:"spans"` +} + +func NewTrace() *Trace { + return &Trace{} +} + +func (p *Trace) GetSpans() []*zipkincore.Span { + return p.Spans +} +func (p *Trace) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *Trace) ReadField1(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*zipkincore.Span, 0, size) + p.Spans = tSlice + for i := 0; i < size; i++ { + _elem0 := &zipkincore.Span{} + if err := _elem0.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem0, err) + } + p.Spans = append(p.Spans, _elem0) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *Trace) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Trace"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *Trace) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("spans", thrift.LIST, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:spans: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Spans)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Spans { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:spans: %s", p, err) + } + return err +} + +func (p *Trace) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("Trace(%+v)", *p) +} + +type QueryException struct { + Msg string `thrift:"msg,1" json:"msg"` +} + +func NewQueryException() *QueryException { + return &QueryException{} +} + +func (p *QueryException) GetMsg() string { + return p.Msg +} +func (p *QueryException) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *QueryException) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Msg = v + } + return nil +} + +func (p *QueryException) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("QueryException"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *QueryException) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("msg", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:msg: %s", p, err) + } + if err := oprot.WriteString(string(p.Msg)); err != nil { + return fmt.Errorf("%T.msg (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:msg: %s", p, err) + } + return err +} + +func (p *QueryException) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("QueryException(%+v)", *p) +} + +func (p *QueryException) Error() string { + return p.String() +} + +type SpanTimestamp struct { + Name string `thrift:"name,1" json:"name"` + StartTimestamp int64 `thrift:"start_timestamp,2" json:"start_timestamp"` + EndTimestamp int64 `thrift:"end_timestamp,3" json:"end_timestamp"` +} + +func NewSpanTimestamp() *SpanTimestamp { + return &SpanTimestamp{} +} + +func (p *SpanTimestamp) GetName() string { + return p.Name +} + +func (p *SpanTimestamp) GetStartTimestamp() int64 { + return p.StartTimestamp +} + +func (p *SpanTimestamp) GetEndTimestamp() int64 { + return p.EndTimestamp +} +func (p *SpanTimestamp) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *SpanTimestamp) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Name = v + } + return nil +} + +func (p *SpanTimestamp) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.StartTimestamp = v + } + return nil +} + +func (p *SpanTimestamp) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.EndTimestamp = v + } + return nil +} + +func (p *SpanTimestamp) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("SpanTimestamp"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *SpanTimestamp) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:name: %s", p, err) + } + if err := oprot.WriteString(string(p.Name)); err != nil { + return fmt.Errorf("%T.name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:name: %s", p, err) + } + return err +} + +func (p *SpanTimestamp) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("start_timestamp", thrift.I64, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:start_timestamp: %s", p, err) + } + if err := oprot.WriteI64(int64(p.StartTimestamp)); err != nil { + return fmt.Errorf("%T.start_timestamp (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:start_timestamp: %s", p, err) + } + return err +} + +func (p *SpanTimestamp) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_timestamp", thrift.I64, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:end_timestamp: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTimestamp)); err != nil { + return fmt.Errorf("%T.end_timestamp (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:end_timestamp: %s", p, err) + } + return err +} + +func (p *SpanTimestamp) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("SpanTimestamp(%+v)", *p) +} + +type TraceSummary struct { + TraceId int64 `thrift:"trace_id,1" json:"trace_id"` + StartTimestamp int64 `thrift:"start_timestamp,2" json:"start_timestamp"` + EndTimestamp int64 `thrift:"end_timestamp,3" json:"end_timestamp"` + DurationMicro int32 `thrift:"duration_micro,4" json:"duration_micro"` + // unused field # 5 + Endpoints []*zipkincore.Endpoint `thrift:"endpoints,6" json:"endpoints"` + SpanTimestamps []*SpanTimestamp `thrift:"span_timestamps,7" json:"span_timestamps"` +} + +func NewTraceSummary() *TraceSummary { + return &TraceSummary{} +} + +func (p *TraceSummary) GetTraceId() int64 { + return p.TraceId +} + +func (p *TraceSummary) GetStartTimestamp() int64 { + return p.StartTimestamp +} + +func (p *TraceSummary) GetEndTimestamp() int64 { + return p.EndTimestamp +} + +func (p *TraceSummary) GetDurationMicro() int32 { + return p.DurationMicro +} + +func (p *TraceSummary) GetEndpoints() []*zipkincore.Endpoint { + return p.Endpoints +} + +func (p *TraceSummary) GetSpanTimestamps() []*SpanTimestamp { + return p.SpanTimestamps +} +func (p *TraceSummary) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *TraceSummary) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.TraceId = v + } + return nil +} + +func (p *TraceSummary) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.StartTimestamp = v + } + return nil +} + +func (p *TraceSummary) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.EndTimestamp = v + } + return nil +} + +func (p *TraceSummary) ReadField4(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 4: %s", err) + } else { + p.DurationMicro = v + } + return nil +} + +func (p *TraceSummary) ReadField6(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*zipkincore.Endpoint, 0, size) + p.Endpoints = tSlice + for i := 0; i < size; i++ { + _elem1 := &zipkincore.Endpoint{} + if err := _elem1.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem1, err) + } + p.Endpoints = append(p.Endpoints, _elem1) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *TraceSummary) ReadField7(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*SpanTimestamp, 0, size) + p.SpanTimestamps = tSlice + for i := 0; i < size; i++ { + _elem2 := &SpanTimestamp{} + if err := _elem2.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem2, err) + } + p.SpanTimestamps = append(p.SpanTimestamps, _elem2) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *TraceSummary) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("TraceSummary"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := p.writeField6(oprot); err != nil { + return err + } + if err := p.writeField7(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *TraceSummary) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_id", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_id: %s", p, err) + } + if err := oprot.WriteI64(int64(p.TraceId)); err != nil { + return fmt.Errorf("%T.trace_id (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_id: %s", p, err) + } + return err +} + +func (p *TraceSummary) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("start_timestamp", thrift.I64, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:start_timestamp: %s", p, err) + } + if err := oprot.WriteI64(int64(p.StartTimestamp)); err != nil { + return fmt.Errorf("%T.start_timestamp (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:start_timestamp: %s", p, err) + } + return err +} + +func (p *TraceSummary) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_timestamp", thrift.I64, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:end_timestamp: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTimestamp)); err != nil { + return fmt.Errorf("%T.end_timestamp (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:end_timestamp: %s", p, err) + } + return err +} + +func (p *TraceSummary) writeField4(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("duration_micro", thrift.I32, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:duration_micro: %s", p, err) + } + if err := oprot.WriteI32(int32(p.DurationMicro)); err != nil { + return fmt.Errorf("%T.duration_micro (4) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:duration_micro: %s", p, err) + } + return err +} + +func (p *TraceSummary) writeField6(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("endpoints", thrift.LIST, 6); err != nil { + return fmt.Errorf("%T write field begin error 6:endpoints: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Endpoints)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Endpoints { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 6:endpoints: %s", p, err) + } + return err +} + +func (p *TraceSummary) writeField7(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("span_timestamps", thrift.LIST, 7); err != nil { + return fmt.Errorf("%T write field begin error 7:span_timestamps: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.SpanTimestamps)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.SpanTimestamps { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 7:span_timestamps: %s", p, err) + } + return err +} + +func (p *TraceSummary) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("TraceSummary(%+v)", *p) +} + +type TimelineAnnotation struct { + Timestamp int64 `thrift:"timestamp,1" json:"timestamp"` + Value string `thrift:"value,2" json:"value"` + Host *zipkincore.Endpoint `thrift:"host,3" json:"host"` + SpanId int64 `thrift:"span_id,4" json:"span_id"` + ParentId *int64 `thrift:"parent_id,5" json:"parent_id"` + ServiceName string `thrift:"service_name,6" json:"service_name"` + SpanName string `thrift:"span_name,7" json:"span_name"` +} + +func NewTimelineAnnotation() *TimelineAnnotation { + return &TimelineAnnotation{} +} + +func (p *TimelineAnnotation) GetTimestamp() int64 { + return p.Timestamp +} + +func (p *TimelineAnnotation) GetValue() string { + return p.Value +} + +var TimelineAnnotation_Host_DEFAULT *zipkincore.Endpoint + +func (p *TimelineAnnotation) GetHost() *zipkincore.Endpoint { + if !p.IsSetHost() { + return TimelineAnnotation_Host_DEFAULT + } + return p.Host +} + +func (p *TimelineAnnotation) GetSpanId() int64 { + return p.SpanId +} + +var TimelineAnnotation_ParentId_DEFAULT int64 + +func (p *TimelineAnnotation) GetParentId() int64 { + if !p.IsSetParentId() { + return TimelineAnnotation_ParentId_DEFAULT + } + return *p.ParentId +} + +func (p *TimelineAnnotation) GetServiceName() string { + return p.ServiceName +} + +func (p *TimelineAnnotation) GetSpanName() string { + return p.SpanName +} +func (p *TimelineAnnotation) IsSetHost() bool { + return p.Host != nil +} + +func (p *TimelineAnnotation) IsSetParentId() bool { + return p.ParentId != nil +} + +func (p *TimelineAnnotation) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *TimelineAnnotation) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Timestamp = v + } + return nil +} + +func (p *TimelineAnnotation) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.Value = v + } + return nil +} + +func (p *TimelineAnnotation) ReadField3(iprot thrift.TProtocol) error { + p.Host = &zipkincore.Endpoint{} + if err := p.Host.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Host, err) + } + return nil +} + +func (p *TimelineAnnotation) ReadField4(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 4: %s", err) + } else { + p.SpanId = v + } + return nil +} + +func (p *TimelineAnnotation) ReadField5(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 5: %s", err) + } else { + p.ParentId = &v + } + return nil +} + +func (p *TimelineAnnotation) ReadField6(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 6: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *TimelineAnnotation) ReadField7(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 7: %s", err) + } else { + p.SpanName = v + } + return nil +} + +func (p *TimelineAnnotation) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("TimelineAnnotation"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := p.writeField5(oprot); err != nil { + return err + } + if err := p.writeField6(oprot); err != nil { + return err + } + if err := p.writeField7(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *TimelineAnnotation) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("timestamp", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:timestamp: %s", p, err) + } + if err := oprot.WriteI64(int64(p.Timestamp)); err != nil { + return fmt.Errorf("%T.timestamp (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:timestamp: %s", p, err) + } + return err +} + +func (p *TimelineAnnotation) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("value", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:value: %s", p, err) + } + if err := oprot.WriteString(string(p.Value)); err != nil { + return fmt.Errorf("%T.value (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:value: %s", p, err) + } + return err +} + +func (p *TimelineAnnotation) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("host", thrift.STRUCT, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:host: %s", p, err) + } + if err := p.Host.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Host, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:host: %s", p, err) + } + return err +} + +func (p *TimelineAnnotation) writeField4(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("span_id", thrift.I64, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:span_id: %s", p, err) + } + if err := oprot.WriteI64(int64(p.SpanId)); err != nil { + return fmt.Errorf("%T.span_id (4) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:span_id: %s", p, err) + } + return err +} + +func (p *TimelineAnnotation) writeField5(oprot thrift.TProtocol) (err error) { + if p.IsSetParentId() { + if err := oprot.WriteFieldBegin("parent_id", thrift.I64, 5); err != nil { + return fmt.Errorf("%T write field begin error 5:parent_id: %s", p, err) + } + if err := oprot.WriteI64(int64(*p.ParentId)); err != nil { + return fmt.Errorf("%T.parent_id (5) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 5:parent_id: %s", p, err) + } + } + return err +} + +func (p *TimelineAnnotation) writeField6(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 6); err != nil { + return fmt.Errorf("%T write field begin error 6:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (6) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 6:service_name: %s", p, err) + } + return err +} + +func (p *TimelineAnnotation) writeField7(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("span_name", thrift.STRING, 7); err != nil { + return fmt.Errorf("%T write field begin error 7:span_name: %s", p, err) + } + if err := oprot.WriteString(string(p.SpanName)); err != nil { + return fmt.Errorf("%T.span_name (7) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 7:span_name: %s", p, err) + } + return err +} + +func (p *TimelineAnnotation) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("TimelineAnnotation(%+v)", *p) +} + +type TraceTimeline struct { + TraceId int64 `thrift:"trace_id,1" json:"trace_id"` + RootMostSpanId int64 `thrift:"root_most_span_id,2" json:"root_most_span_id"` + // unused fields # 3 to 5 + Annotations []*TimelineAnnotation `thrift:"annotations,6" json:"annotations"` + BinaryAnnotations []*zipkincore.BinaryAnnotation `thrift:"binary_annotations,7" json:"binary_annotations"` +} + +func NewTraceTimeline() *TraceTimeline { + return &TraceTimeline{} +} + +func (p *TraceTimeline) GetTraceId() int64 { + return p.TraceId +} + +func (p *TraceTimeline) GetRootMostSpanId() int64 { + return p.RootMostSpanId +} + +func (p *TraceTimeline) GetAnnotations() []*TimelineAnnotation { + return p.Annotations +} + +func (p *TraceTimeline) GetBinaryAnnotations() []*zipkincore.BinaryAnnotation { + return p.BinaryAnnotations +} +func (p *TraceTimeline) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *TraceTimeline) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.TraceId = v + } + return nil +} + +func (p *TraceTimeline) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.RootMostSpanId = v + } + return nil +} + +func (p *TraceTimeline) ReadField6(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*TimelineAnnotation, 0, size) + p.Annotations = tSlice + for i := 0; i < size; i++ { + _elem3 := &TimelineAnnotation{} + if err := _elem3.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem3, err) + } + p.Annotations = append(p.Annotations, _elem3) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *TraceTimeline) ReadField7(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*zipkincore.BinaryAnnotation, 0, size) + p.BinaryAnnotations = tSlice + for i := 0; i < size; i++ { + _elem4 := &zipkincore.BinaryAnnotation{} + if err := _elem4.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem4, err) + } + p.BinaryAnnotations = append(p.BinaryAnnotations, _elem4) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *TraceTimeline) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("TraceTimeline"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField6(oprot); err != nil { + return err + } + if err := p.writeField7(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *TraceTimeline) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_id", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_id: %s", p, err) + } + if err := oprot.WriteI64(int64(p.TraceId)); err != nil { + return fmt.Errorf("%T.trace_id (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_id: %s", p, err) + } + return err +} + +func (p *TraceTimeline) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("root_most_span_id", thrift.I64, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:root_most_span_id: %s", p, err) + } + if err := oprot.WriteI64(int64(p.RootMostSpanId)); err != nil { + return fmt.Errorf("%T.root_most_span_id (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:root_most_span_id: %s", p, err) + } + return err +} + +func (p *TraceTimeline) writeField6(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("annotations", thrift.LIST, 6); err != nil { + return fmt.Errorf("%T write field begin error 6:annotations: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Annotations)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Annotations { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 6:annotations: %s", p, err) + } + return err +} + +func (p *TraceTimeline) writeField7(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("binary_annotations", thrift.LIST, 7); err != nil { + return fmt.Errorf("%T write field begin error 7:binary_annotations: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.BinaryAnnotations)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.BinaryAnnotations { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 7:binary_annotations: %s", p, err) + } + return err +} + +func (p *TraceTimeline) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("TraceTimeline(%+v)", *p) +} + +type TraceCombo struct { + Trace *Trace `thrift:"trace,1" json:"trace"` + Summary *TraceSummary `thrift:"summary,2" json:"summary"` + Timeline *TraceTimeline `thrift:"timeline,3" json:"timeline"` + SpanDepths map[int64]int32 `thrift:"span_depths,4" json:"span_depths"` +} + +func NewTraceCombo() *TraceCombo { + return &TraceCombo{} +} + +var TraceCombo_Trace_DEFAULT *Trace + +func (p *TraceCombo) GetTrace() *Trace { + if !p.IsSetTrace() { + return TraceCombo_Trace_DEFAULT + } + return p.Trace +} + +var TraceCombo_Summary_DEFAULT *TraceSummary + +func (p *TraceCombo) GetSummary() *TraceSummary { + if !p.IsSetSummary() { + return TraceCombo_Summary_DEFAULT + } + return p.Summary +} + +var TraceCombo_Timeline_DEFAULT *TraceTimeline + +func (p *TraceCombo) GetTimeline() *TraceTimeline { + if !p.IsSetTimeline() { + return TraceCombo_Timeline_DEFAULT + } + return p.Timeline +} + +var TraceCombo_SpanDepths_DEFAULT map[int64]int32 + +func (p *TraceCombo) GetSpanDepths() map[int64]int32 { + return p.SpanDepths +} +func (p *TraceCombo) IsSetTrace() bool { + return p.Trace != nil +} + +func (p *TraceCombo) IsSetSummary() bool { + return p.Summary != nil +} + +func (p *TraceCombo) IsSetTimeline() bool { + return p.Timeline != nil +} + +func (p *TraceCombo) IsSetSpanDepths() bool { + return p.SpanDepths != nil +} + +func (p *TraceCombo) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *TraceCombo) ReadField1(iprot thrift.TProtocol) error { + p.Trace = &Trace{} + if err := p.Trace.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Trace, err) + } + return nil +} + +func (p *TraceCombo) ReadField2(iprot thrift.TProtocol) error { + p.Summary = &TraceSummary{} + if err := p.Summary.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Summary, err) + } + return nil +} + +func (p *TraceCombo) ReadField3(iprot thrift.TProtocol) error { + p.Timeline = &TraceTimeline{} + if err := p.Timeline.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Timeline, err) + } + return nil +} + +func (p *TraceCombo) ReadField4(iprot thrift.TProtocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return fmt.Errorf("error reading map begin: %s", err) + } + tMap := make(map[int64]int32, size) + p.SpanDepths = tMap + for i := 0; i < size; i++ { + var _key5 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _key5 = v + } + var _val6 int32 + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _val6 = v + } + p.SpanDepths[_key5] = _val6 + } + if err := iprot.ReadMapEnd(); err != nil { + return fmt.Errorf("error reading map end: %s", err) + } + return nil +} + +func (p *TraceCombo) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("TraceCombo"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *TraceCombo) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace: %s", p, err) + } + if err := p.Trace.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Trace, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace: %s", p, err) + } + return err +} + +func (p *TraceCombo) writeField2(oprot thrift.TProtocol) (err error) { + if p.IsSetSummary() { + if err := oprot.WriteFieldBegin("summary", thrift.STRUCT, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:summary: %s", p, err) + } + if err := p.Summary.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Summary, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:summary: %s", p, err) + } + } + return err +} + +func (p *TraceCombo) writeField3(oprot thrift.TProtocol) (err error) { + if p.IsSetTimeline() { + if err := oprot.WriteFieldBegin("timeline", thrift.STRUCT, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:timeline: %s", p, err) + } + if err := p.Timeline.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Timeline, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:timeline: %s", p, err) + } + } + return err +} + +func (p *TraceCombo) writeField4(oprot thrift.TProtocol) (err error) { + if p.IsSetSpanDepths() { + if err := oprot.WriteFieldBegin("span_depths", thrift.MAP, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:span_depths: %s", p, err) + } + if err := oprot.WriteMapBegin(thrift.I64, thrift.I32, len(p.SpanDepths)); err != nil { + return fmt.Errorf("error writing map begin: %s", err) + } + for k, v := range p.SpanDepths { + if err := oprot.WriteI64(int64(k)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + if err := oprot.WriteI32(int32(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteMapEnd(); err != nil { + return fmt.Errorf("error writing map end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:span_depths: %s", p, err) + } + } + return err +} + +func (p *TraceCombo) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("TraceCombo(%+v)", *p) +} + +type QueryRequest struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` + SpanName *string `thrift:"span_name,2" json:"span_name"` + Annotations []string `thrift:"annotations,3" json:"annotations"` + BinaryAnnotations []*zipkincore.BinaryAnnotation `thrift:"binary_annotations,4" json:"binary_annotations"` + EndTs int64 `thrift:"end_ts,5" json:"end_ts"` + Limit int32 `thrift:"limit,6" json:"limit"` + Order Order `thrift:"order,7" json:"order"` +} + +func NewQueryRequest() *QueryRequest { + return &QueryRequest{} +} + +func (p *QueryRequest) GetServiceName() string { + return p.ServiceName +} + +var QueryRequest_SpanName_DEFAULT string + +func (p *QueryRequest) GetSpanName() string { + if !p.IsSetSpanName() { + return QueryRequest_SpanName_DEFAULT + } + return *p.SpanName +} + +var QueryRequest_Annotations_DEFAULT []string + +func (p *QueryRequest) GetAnnotations() []string { + return p.Annotations +} + +var QueryRequest_BinaryAnnotations_DEFAULT []*zipkincore.BinaryAnnotation + +func (p *QueryRequest) GetBinaryAnnotations() []*zipkincore.BinaryAnnotation { + return p.BinaryAnnotations +} + +func (p *QueryRequest) GetEndTs() int64 { + return p.EndTs +} + +func (p *QueryRequest) GetLimit() int32 { + return p.Limit +} + +func (p *QueryRequest) GetOrder() Order { + return p.Order +} +func (p *QueryRequest) IsSetSpanName() bool { + return p.SpanName != nil +} + +func (p *QueryRequest) IsSetAnnotations() bool { + return p.Annotations != nil +} + +func (p *QueryRequest) IsSetBinaryAnnotations() bool { + return p.BinaryAnnotations != nil +} + +func (p *QueryRequest) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *QueryRequest) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *QueryRequest) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.SpanName = &v + } + return nil +} + +func (p *QueryRequest) ReadField3(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]string, 0, size) + p.Annotations = tSlice + for i := 0; i < size; i++ { + var _elem7 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem7 = v + } + p.Annotations = append(p.Annotations, _elem7) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *QueryRequest) ReadField4(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*zipkincore.BinaryAnnotation, 0, size) + p.BinaryAnnotations = tSlice + for i := 0; i < size; i++ { + _elem8 := &zipkincore.BinaryAnnotation{} + if err := _elem8.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem8, err) + } + p.BinaryAnnotations = append(p.BinaryAnnotations, _elem8) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *QueryRequest) ReadField5(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 5: %s", err) + } else { + p.EndTs = v + } + return nil +} + +func (p *QueryRequest) ReadField6(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 6: %s", err) + } else { + p.Limit = v + } + return nil +} + +func (p *QueryRequest) ReadField7(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 7: %s", err) + } else { + temp := Order(v) + p.Order = temp + } + return nil +} + +func (p *QueryRequest) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("QueryRequest"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := p.writeField5(oprot); err != nil { + return err + } + if err := p.writeField6(oprot); err != nil { + return err + } + if err := p.writeField7(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *QueryRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *QueryRequest) writeField2(oprot thrift.TProtocol) (err error) { + if p.IsSetSpanName() { + if err := oprot.WriteFieldBegin("span_name", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:span_name: %s", p, err) + } + if err := oprot.WriteString(string(*p.SpanName)); err != nil { + return fmt.Errorf("%T.span_name (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:span_name: %s", p, err) + } + } + return err +} + +func (p *QueryRequest) writeField3(oprot thrift.TProtocol) (err error) { + if p.IsSetAnnotations() { + if err := oprot.WriteFieldBegin("annotations", thrift.LIST, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:annotations: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRING, len(p.Annotations)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Annotations { + if err := oprot.WriteString(string(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:annotations: %s", p, err) + } + } + return err +} + +func (p *QueryRequest) writeField4(oprot thrift.TProtocol) (err error) { + if p.IsSetBinaryAnnotations() { + if err := oprot.WriteFieldBegin("binary_annotations", thrift.LIST, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:binary_annotations: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.BinaryAnnotations)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.BinaryAnnotations { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:binary_annotations: %s", p, err) + } + } + return err +} + +func (p *QueryRequest) writeField5(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_ts", thrift.I64, 5); err != nil { + return fmt.Errorf("%T write field begin error 5:end_ts: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTs)); err != nil { + return fmt.Errorf("%T.end_ts (5) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 5:end_ts: %s", p, err) + } + return err +} + +func (p *QueryRequest) writeField6(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("limit", thrift.I32, 6); err != nil { + return fmt.Errorf("%T write field begin error 6:limit: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Limit)); err != nil { + return fmt.Errorf("%T.limit (6) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 6:limit: %s", p, err) + } + return err +} + +func (p *QueryRequest) writeField7(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("order", thrift.I32, 7); err != nil { + return fmt.Errorf("%T write field begin error 7:order: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Order)); err != nil { + return fmt.Errorf("%T.order (7) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 7:order: %s", p, err) + } + return err +} + +func (p *QueryRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("QueryRequest(%+v)", *p) +} + +type QueryResponse struct { + TraceIds []int64 `thrift:"trace_ids,1" json:"trace_ids"` + StartTs int64 `thrift:"start_ts,2" json:"start_ts"` + EndTs int64 `thrift:"end_ts,3" json:"end_ts"` +} + +func NewQueryResponse() *QueryResponse { + return &QueryResponse{} +} + +func (p *QueryResponse) GetTraceIds() []int64 { + return p.TraceIds +} + +func (p *QueryResponse) GetStartTs() int64 { + return p.StartTs +} + +func (p *QueryResponse) GetEndTs() int64 { + return p.EndTs +} +func (p *QueryResponse) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *QueryResponse) ReadField1(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.TraceIds = tSlice + for i := 0; i < size; i++ { + var _elem9 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem9 = v + } + p.TraceIds = append(p.TraceIds, _elem9) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *QueryResponse) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.StartTs = v + } + return nil +} + +func (p *QueryResponse) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.EndTs = v + } + return nil +} + +func (p *QueryResponse) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("QueryResponse"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *QueryResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_ids", thrift.LIST, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_ids: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.TraceIds)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.TraceIds { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_ids: %s", p, err) + } + return err +} + +func (p *QueryResponse) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("start_ts", thrift.I64, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:start_ts: %s", p, err) + } + if err := oprot.WriteI64(int64(p.StartTs)); err != nil { + return fmt.Errorf("%T.start_ts (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:start_ts: %s", p, err) + } + return err +} + +func (p *QueryResponse) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_ts", thrift.I64, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:end_ts: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTs)); err != nil { + return fmt.Errorf("%T.end_ts (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:end_ts: %s", p, err) + } + return err +} + +func (p *QueryResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("QueryResponse(%+v)", *p) +} diff --git a/tracing/zipkin/thrift/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go b/tracing/zipkin/thrift/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go new file mode 100755 index 000000000..332a2f0f4 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go @@ -0,0 +1,602 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package main + +import ( + "flag" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "math" + "net" + "net/url" + "os" + "strconv" + "strings" + "zipkinquery" +) + +func Usage() { + fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") + flag.PrintDefaults() + fmt.Fprintln(os.Stderr, "\nFunctions:") + fmt.Fprintln(os.Stderr, " QueryResponse getTraceIds(QueryRequest request)") + fmt.Fprintln(os.Stderr, " getTraceIdsBySpanName(string service_name, string span_name, i64 end_ts, i32 limit, Order order)") + fmt.Fprintln(os.Stderr, " getTraceIdsByServiceName(string service_name, i64 end_ts, i32 limit, Order order)") + fmt.Fprintln(os.Stderr, " getTraceIdsByAnnotation(string service_name, string annotation, string value, i64 end_ts, i32 limit, Order order)") + fmt.Fprintln(os.Stderr, " tracesExist( trace_ids)") + fmt.Fprintln(os.Stderr, " getTracesByIds( trace_ids, adjust)") + fmt.Fprintln(os.Stderr, " getTraceTimelinesByIds( trace_ids, adjust)") + fmt.Fprintln(os.Stderr, " getTraceSummariesByIds( trace_ids, adjust)") + fmt.Fprintln(os.Stderr, " getTraceCombosByIds( trace_ids, adjust)") + fmt.Fprintln(os.Stderr, " getServiceNames()") + fmt.Fprintln(os.Stderr, " getSpanNames(string service_name)") + fmt.Fprintln(os.Stderr, " void setTraceTimeToLive(i64 trace_id, i32 ttl_seconds)") + fmt.Fprintln(os.Stderr, " i32 getTraceTimeToLive(i64 trace_id)") + fmt.Fprintln(os.Stderr, " i32 getDataTimeToLive()") + fmt.Fprintln(os.Stderr, " Dependencies getDependencies(i64 start_time, i64 end_time)") + fmt.Fprintln(os.Stderr, " getTopAnnotations(string service_name)") + fmt.Fprintln(os.Stderr, " getTopKeyValueAnnotations(string service_name)") + fmt.Fprintln(os.Stderr, " getSpanDurations(i64 time_stamp, string service_name, string rpc_name)") + fmt.Fprintln(os.Stderr, " getServiceNamesToTraceIds(i64 time_stamp, string service_name, string rpc_name)") + fmt.Fprintln(os.Stderr) + os.Exit(0) +} + +func main() { + flag.Usage = Usage + var host string + var port int + var protocol string + var urlString string + var framed bool + var useHttp bool + var parsedUrl url.URL + var trans thrift.TTransport + _ = strconv.Atoi + _ = math.Abs + flag.Usage = Usage + flag.StringVar(&host, "h", "localhost", "Specify host and port") + flag.IntVar(&port, "p", 9090, "Specify port") + flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") + flag.StringVar(&urlString, "u", "", "Specify the url") + flag.BoolVar(&framed, "framed", false, "Use framed transport") + flag.BoolVar(&useHttp, "http", false, "Use http") + flag.Parse() + + if len(urlString) > 0 { + parsedUrl, err := url.Parse(urlString) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + host = parsedUrl.Host + useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" + } else if useHttp { + _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + } + + cmd := flag.Arg(0) + var err error + if useHttp { + trans, err = thrift.NewTHttpClient(parsedUrl.String()) + } else { + portStr := fmt.Sprint(port) + if strings.Contains(host, ":") { + host, portStr, err = net.SplitHostPort(host) + if err != nil { + fmt.Fprintln(os.Stderr, "error with host:", err) + os.Exit(1) + } + } + trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) + if err != nil { + fmt.Fprintln(os.Stderr, "error resolving address:", err) + os.Exit(1) + } + if framed { + trans = thrift.NewTFramedTransport(trans) + } + } + if err != nil { + fmt.Fprintln(os.Stderr, "Error creating transport", err) + os.Exit(1) + } + defer trans.Close() + var protocolFactory thrift.TProtocolFactory + switch protocol { + case "compact": + protocolFactory = thrift.NewTCompactProtocolFactory() + break + case "simplejson": + protocolFactory = thrift.NewTSimpleJSONProtocolFactory() + break + case "json": + protocolFactory = thrift.NewTJSONProtocolFactory() + break + case "binary", "": + protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() + break + default: + fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) + Usage() + os.Exit(1) + } + client := zipkinquery.NewZipkinQueryClientFactory(trans, protocolFactory) + if err := trans.Open(); err != nil { + fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) + os.Exit(1) + } + + switch cmd { + case "getTraceIds": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "GetTraceIds requires 1 args") + flag.Usage() + } + arg77 := flag.Arg(1) + mbTrans78 := thrift.NewTMemoryBufferLen(len(arg77)) + defer mbTrans78.Close() + _, err79 := mbTrans78.WriteString(arg77) + if err79 != nil { + Usage() + return + } + factory80 := thrift.NewTSimpleJSONProtocolFactory() + jsProt81 := factory80.GetProtocol(mbTrans78) + argvalue0 := zipkinquery.NewQueryRequest() + err82 := argvalue0.Read(jsProt81) + if err82 != nil { + Usage() + return + } + value0 := argvalue0 + fmt.Print(client.GetTraceIds(value0)) + fmt.Print("\n") + break + case "getTraceIdsBySpanName": + if flag.NArg()-1 != 5 { + fmt.Fprintln(os.Stderr, "GetTraceIdsBySpanName requires 5 args") + flag.Usage() + } + argvalue0 := flag.Arg(1) + value0 := argvalue0 + argvalue1 := flag.Arg(2) + value1 := argvalue1 + argvalue2, err85 := (strconv.ParseInt(flag.Arg(3), 10, 64)) + if err85 != nil { + Usage() + return + } + value2 := argvalue2 + tmp3, err86 := (strconv.Atoi(flag.Arg(4))) + if err86 != nil { + Usage() + return + } + argvalue3 := int32(tmp3) + value3 := argvalue3 + tmp4, err := (strconv.Atoi(flag.Arg(5))) + if err != nil { + Usage() + return + } + argvalue4 := zipkinquery.Order(tmp4) + value4 := argvalue4 + fmt.Print(client.GetTraceIdsBySpanName(value0, value1, value2, value3, value4)) + fmt.Print("\n") + break + case "getTraceIdsByServiceName": + if flag.NArg()-1 != 4 { + fmt.Fprintln(os.Stderr, "GetTraceIdsByServiceName requires 4 args") + flag.Usage() + } + argvalue0 := flag.Arg(1) + value0 := argvalue0 + argvalue1, err88 := (strconv.ParseInt(flag.Arg(2), 10, 64)) + if err88 != nil { + Usage() + return + } + value1 := argvalue1 + tmp2, err89 := (strconv.Atoi(flag.Arg(3))) + if err89 != nil { + Usage() + return + } + argvalue2 := int32(tmp2) + value2 := argvalue2 + tmp3, err := (strconv.Atoi(flag.Arg(4))) + if err != nil { + Usage() + return + } + argvalue3 := zipkinquery.Order(tmp3) + value3 := argvalue3 + fmt.Print(client.GetTraceIdsByServiceName(value0, value1, value2, value3)) + fmt.Print("\n") + break + case "getTraceIdsByAnnotation": + if flag.NArg()-1 != 6 { + fmt.Fprintln(os.Stderr, "GetTraceIdsByAnnotation requires 6 args") + flag.Usage() + } + argvalue0 := flag.Arg(1) + value0 := argvalue0 + argvalue1 := flag.Arg(2) + value1 := argvalue1 + argvalue2 := []byte(flag.Arg(3)) + value2 := argvalue2 + argvalue3, err93 := (strconv.ParseInt(flag.Arg(4), 10, 64)) + if err93 != nil { + Usage() + return + } + value3 := argvalue3 + tmp4, err94 := (strconv.Atoi(flag.Arg(5))) + if err94 != nil { + Usage() + return + } + argvalue4 := int32(tmp4) + value4 := argvalue4 + tmp5, err := (strconv.Atoi(flag.Arg(6))) + if err != nil { + Usage() + return + } + argvalue5 := zipkinquery.Order(tmp5) + value5 := argvalue5 + fmt.Print(client.GetTraceIdsByAnnotation(value0, value1, value2, value3, value4, value5)) + fmt.Print("\n") + break + case "tracesExist": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "TracesExist requires 1 args") + flag.Usage() + } + arg95 := flag.Arg(1) + mbTrans96 := thrift.NewTMemoryBufferLen(len(arg95)) + defer mbTrans96.Close() + _, err97 := mbTrans96.WriteString(arg95) + if err97 != nil { + Usage() + return + } + factory98 := thrift.NewTSimpleJSONProtocolFactory() + jsProt99 := factory98.GetProtocol(mbTrans96) + containerStruct0 := zipkinquery.NewTracesExistArgs() + err100 := containerStruct0.ReadField1(jsProt99) + if err100 != nil { + Usage() + return + } + argvalue0 := containerStruct0.TraceIds + value0 := argvalue0 + fmt.Print(client.TracesExist(value0)) + fmt.Print("\n") + break + case "getTracesByIds": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "GetTracesByIds requires 2 args") + flag.Usage() + } + arg101 := flag.Arg(1) + mbTrans102 := thrift.NewTMemoryBufferLen(len(arg101)) + defer mbTrans102.Close() + _, err103 := mbTrans102.WriteString(arg101) + if err103 != nil { + Usage() + return + } + factory104 := thrift.NewTSimpleJSONProtocolFactory() + jsProt105 := factory104.GetProtocol(mbTrans102) + containerStruct0 := zipkinquery.NewGetTracesByIdsArgs() + err106 := containerStruct0.ReadField1(jsProt105) + if err106 != nil { + Usage() + return + } + argvalue0 := containerStruct0.TraceIds + value0 := argvalue0 + arg107 := flag.Arg(2) + mbTrans108 := thrift.NewTMemoryBufferLen(len(arg107)) + defer mbTrans108.Close() + _, err109 := mbTrans108.WriteString(arg107) + if err109 != nil { + Usage() + return + } + factory110 := thrift.NewTSimpleJSONProtocolFactory() + jsProt111 := factory110.GetProtocol(mbTrans108) + containerStruct1 := zipkinquery.NewGetTracesByIdsArgs() + err112 := containerStruct1.ReadField2(jsProt111) + if err112 != nil { + Usage() + return + } + argvalue1 := containerStruct1.Adjust + value1 := argvalue1 + fmt.Print(client.GetTracesByIds(value0, value1)) + fmt.Print("\n") + break + case "getTraceTimelinesByIds": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "GetTraceTimelinesByIds requires 2 args") + flag.Usage() + } + arg113 := flag.Arg(1) + mbTrans114 := thrift.NewTMemoryBufferLen(len(arg113)) + defer mbTrans114.Close() + _, err115 := mbTrans114.WriteString(arg113) + if err115 != nil { + Usage() + return + } + factory116 := thrift.NewTSimpleJSONProtocolFactory() + jsProt117 := factory116.GetProtocol(mbTrans114) + containerStruct0 := zipkinquery.NewGetTraceTimelinesByIdsArgs() + err118 := containerStruct0.ReadField1(jsProt117) + if err118 != nil { + Usage() + return + } + argvalue0 := containerStruct0.TraceIds + value0 := argvalue0 + arg119 := flag.Arg(2) + mbTrans120 := thrift.NewTMemoryBufferLen(len(arg119)) + defer mbTrans120.Close() + _, err121 := mbTrans120.WriteString(arg119) + if err121 != nil { + Usage() + return + } + factory122 := thrift.NewTSimpleJSONProtocolFactory() + jsProt123 := factory122.GetProtocol(mbTrans120) + containerStruct1 := zipkinquery.NewGetTraceTimelinesByIdsArgs() + err124 := containerStruct1.ReadField2(jsProt123) + if err124 != nil { + Usage() + return + } + argvalue1 := containerStruct1.Adjust + value1 := argvalue1 + fmt.Print(client.GetTraceTimelinesByIds(value0, value1)) + fmt.Print("\n") + break + case "getTraceSummariesByIds": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "GetTraceSummariesByIds requires 2 args") + flag.Usage() + } + arg125 := flag.Arg(1) + mbTrans126 := thrift.NewTMemoryBufferLen(len(arg125)) + defer mbTrans126.Close() + _, err127 := mbTrans126.WriteString(arg125) + if err127 != nil { + Usage() + return + } + factory128 := thrift.NewTSimpleJSONProtocolFactory() + jsProt129 := factory128.GetProtocol(mbTrans126) + containerStruct0 := zipkinquery.NewGetTraceSummariesByIdsArgs() + err130 := containerStruct0.ReadField1(jsProt129) + if err130 != nil { + Usage() + return + } + argvalue0 := containerStruct0.TraceIds + value0 := argvalue0 + arg131 := flag.Arg(2) + mbTrans132 := thrift.NewTMemoryBufferLen(len(arg131)) + defer mbTrans132.Close() + _, err133 := mbTrans132.WriteString(arg131) + if err133 != nil { + Usage() + return + } + factory134 := thrift.NewTSimpleJSONProtocolFactory() + jsProt135 := factory134.GetProtocol(mbTrans132) + containerStruct1 := zipkinquery.NewGetTraceSummariesByIdsArgs() + err136 := containerStruct1.ReadField2(jsProt135) + if err136 != nil { + Usage() + return + } + argvalue1 := containerStruct1.Adjust + value1 := argvalue1 + fmt.Print(client.GetTraceSummariesByIds(value0, value1)) + fmt.Print("\n") + break + case "getTraceCombosByIds": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "GetTraceCombosByIds requires 2 args") + flag.Usage() + } + arg137 := flag.Arg(1) + mbTrans138 := thrift.NewTMemoryBufferLen(len(arg137)) + defer mbTrans138.Close() + _, err139 := mbTrans138.WriteString(arg137) + if err139 != nil { + Usage() + return + } + factory140 := thrift.NewTSimpleJSONProtocolFactory() + jsProt141 := factory140.GetProtocol(mbTrans138) + containerStruct0 := zipkinquery.NewGetTraceCombosByIdsArgs() + err142 := containerStruct0.ReadField1(jsProt141) + if err142 != nil { + Usage() + return + } + argvalue0 := containerStruct0.TraceIds + value0 := argvalue0 + arg143 := flag.Arg(2) + mbTrans144 := thrift.NewTMemoryBufferLen(len(arg143)) + defer mbTrans144.Close() + _, err145 := mbTrans144.WriteString(arg143) + if err145 != nil { + Usage() + return + } + factory146 := thrift.NewTSimpleJSONProtocolFactory() + jsProt147 := factory146.GetProtocol(mbTrans144) + containerStruct1 := zipkinquery.NewGetTraceCombosByIdsArgs() + err148 := containerStruct1.ReadField2(jsProt147) + if err148 != nil { + Usage() + return + } + argvalue1 := containerStruct1.Adjust + value1 := argvalue1 + fmt.Print(client.GetTraceCombosByIds(value0, value1)) + fmt.Print("\n") + break + case "getServiceNames": + if flag.NArg()-1 != 0 { + fmt.Fprintln(os.Stderr, "GetServiceNames requires 0 args") + flag.Usage() + } + fmt.Print(client.GetServiceNames()) + fmt.Print("\n") + break + case "getSpanNames": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "GetSpanNames requires 1 args") + flag.Usage() + } + argvalue0 := flag.Arg(1) + value0 := argvalue0 + fmt.Print(client.GetSpanNames(value0)) + fmt.Print("\n") + break + case "setTraceTimeToLive": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "SetTraceTimeToLive requires 2 args") + flag.Usage() + } + argvalue0, err150 := (strconv.ParseInt(flag.Arg(1), 10, 64)) + if err150 != nil { + Usage() + return + } + value0 := argvalue0 + tmp1, err151 := (strconv.Atoi(flag.Arg(2))) + if err151 != nil { + Usage() + return + } + argvalue1 := int32(tmp1) + value1 := argvalue1 + fmt.Print(client.SetTraceTimeToLive(value0, value1)) + fmt.Print("\n") + break + case "getTraceTimeToLive": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "GetTraceTimeToLive requires 1 args") + flag.Usage() + } + argvalue0, err152 := (strconv.ParseInt(flag.Arg(1), 10, 64)) + if err152 != nil { + Usage() + return + } + value0 := argvalue0 + fmt.Print(client.GetTraceTimeToLive(value0)) + fmt.Print("\n") + break + case "getDataTimeToLive": + if flag.NArg()-1 != 0 { + fmt.Fprintln(os.Stderr, "GetDataTimeToLive requires 0 args") + flag.Usage() + } + fmt.Print(client.GetDataTimeToLive()) + fmt.Print("\n") + break + case "getDependencies": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "GetDependencies requires 2 args") + flag.Usage() + } + argvalue0, err153 := (strconv.ParseInt(flag.Arg(1), 10, 64)) + if err153 != nil { + Usage() + return + } + value0 := argvalue0 + argvalue1, err154 := (strconv.ParseInt(flag.Arg(2), 10, 64)) + if err154 != nil { + Usage() + return + } + value1 := argvalue1 + fmt.Print(client.GetDependencies(value0, value1)) + fmt.Print("\n") + break + case "getTopAnnotations": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "GetTopAnnotations requires 1 args") + flag.Usage() + } + argvalue0 := flag.Arg(1) + value0 := argvalue0 + fmt.Print(client.GetTopAnnotations(value0)) + fmt.Print("\n") + break + case "getTopKeyValueAnnotations": + if flag.NArg()-1 != 1 { + fmt.Fprintln(os.Stderr, "GetTopKeyValueAnnotations requires 1 args") + flag.Usage() + } + argvalue0 := flag.Arg(1) + value0 := argvalue0 + fmt.Print(client.GetTopKeyValueAnnotations(value0)) + fmt.Print("\n") + break + case "getSpanDurations": + if flag.NArg()-1 != 3 { + fmt.Fprintln(os.Stderr, "GetSpanDurations requires 3 args") + flag.Usage() + } + argvalue0, err157 := (strconv.ParseInt(flag.Arg(1), 10, 64)) + if err157 != nil { + Usage() + return + } + value0 := argvalue0 + argvalue1 := flag.Arg(2) + value1 := argvalue1 + argvalue2 := flag.Arg(3) + value2 := argvalue2 + fmt.Print(client.GetSpanDurations(value0, value1, value2)) + fmt.Print("\n") + break + case "getServiceNamesToTraceIds": + if flag.NArg()-1 != 3 { + fmt.Fprintln(os.Stderr, "GetServiceNamesToTraceIds requires 3 args") + flag.Usage() + } + argvalue0, err160 := (strconv.ParseInt(flag.Arg(1), 10, 64)) + if err160 != nil { + Usage() + return + } + value0 := argvalue0 + argvalue1 := flag.Arg(2) + value1 := argvalue1 + argvalue2 := flag.Arg(3) + value2 := argvalue2 + fmt.Print(client.GetServiceNamesToTraceIds(value0, value1, value2)) + fmt.Print("\n") + break + case "": + Usage() + break + default: + fmt.Fprintln(os.Stderr, "Invalid function ", cmd) + } +} diff --git a/tracing/zipkin/thrift/gen-go/zipkinquery/zipkinquery.go b/tracing/zipkin/thrift/gen-go/zipkinquery/zipkinquery.go new file mode 100644 index 000000000..6fbd56052 --- /dev/null +++ b/tracing/zipkin/thrift/gen-go/zipkinquery/zipkinquery.go @@ -0,0 +1,8183 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package zipkinquery + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "zipkincore" + "zipkindependencies" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var _ = zipkincore.GoUnusedProtection__ +var _ = zipkindependencies.GoUnusedProtection__ + +type ZipkinQuery interface { + // Parameters: + // - Request + GetTraceIds(request *QueryRequest) (r *QueryResponse, err error) + // Fetch trace ids by service and span name. + // Gets "limit" number of entries from before the "end_ts". + // + // Span name is optional. + // Timestamps are in microseconds. + // + // Parameters: + // - ServiceName + // - SpanName + // - EndTs + // - Limit + // - Order + GetTraceIdsBySpanName(service_name string, span_name string, end_ts int64, limit int32, order Order) (r []int64, err error) + // Fetch trace ids by service name. + // Gets "limit" number of entries from before the "end_ts". + // + // Timestamps are in microseconds. + // + // Parameters: + // - ServiceName + // - EndTs + // - Limit + // - Order + GetTraceIdsByServiceName(service_name string, end_ts int64, limit int32, order Order) (r []int64, err error) + // Fetch trace ids with a particular annotation. + // Gets "limit" number of entries from before the "end_ts". + // + // When requesting based on time based annotations only pass in the first parameter, "annotation" and leave out + // the second "value". If looking for a key-value binary annotation provide both, "annotation" is then the + // key in the key-value. + // + // Timestamps are in microseconds. + // + // Parameters: + // - ServiceName + // - Annotation + // - Value + // - EndTs + // - Limit + // - Order + GetTraceIdsByAnnotation(service_name string, annotation string, value []byte, end_ts int64, limit int32, order Order) (r []int64, err error) + // Get the traces that are in the database from the given list of trace ids. + // + // Parameters: + // - TraceIds + TracesExist(trace_ids []int64) (r map[int64]bool, err error) + // Get the full traces associated with the given trace ids. + // + // Second argument is a list of methods of adjusting the trace + // data before returning it. Can be empty. + // + // Parameters: + // - TraceIds + // - Adjust + GetTracesByIds(trace_ids []int64, adjust []Adjust) (r []*Trace, err error) + // Get the trace timelines associated with the given trace ids. + // This is a convenience method for users that just want to know + // the annotations and the (assumed) order they happened in. + // + // Second argument is a list of methods of adjusting the trace + // data before returning it. Can be empty. + // + // Note that if one of the trace ids does not have any data associated with it, it will not be + // represented in the output list. + // + // Parameters: + // - TraceIds + // - Adjust + GetTraceTimelinesByIds(trace_ids []int64, adjust []Adjust) (r []*TraceTimeline, err error) + // Fetch trace summaries for the given trace ids. + // + // Second argument is a list of methods of adjusting the trace + // data before returning it. Can be empty. + // + // Note that if one of the trace ids does not have any data associated with it, it will not be + // represented in the output list. + // + // Parameters: + // - TraceIds + // - Adjust + GetTraceSummariesByIds(trace_ids []int64, adjust []Adjust) (r []*TraceSummary, err error) + // Not content with just one of traces, summaries or timelines? Want it all? This is the method for you. + // + // Parameters: + // - TraceIds + // - Adjust + GetTraceCombosByIds(trace_ids []int64, adjust []Adjust) (r []*TraceCombo, err error) + // Fetch all the service names we have seen from now all the way back to the set ttl. + GetServiceNames() (r map[string]bool, err error) + // Get all the seen span names for a particular service, from now back until the set ttl. + // + // Parameters: + // - ServiceName + GetSpanNames(service_name string) (r map[string]bool, err error) + // Change the TTL of a trace. If we find an interesting trace we want to keep around for further + // investigation. + // + // Parameters: + // - TraceId + // - TtlSeconds + SetTraceTimeToLive(trace_id int64, ttl_seconds int32) (err error) + // Get the TTL in seconds of a specific trace. + // + // Parameters: + // - TraceId + GetTraceTimeToLive(trace_id int64) (r int32, err error) + // Get the data ttl. This is the number of seconds we keep the data around before deleting it. + GetDataTimeToLive() (r int32, err error) + // Get an aggregate representation of all services paired with every service they call in to. + // This includes information on call counts and mean/stdDev/etc of call durations. The two arguments + // specify epoch time in microseconds. The end time is optional and defaults to one day after the + // start time. + // + // Parameters: + // - StartTime + // - EndTime + GetDependencies(start_time int64, end_time int64) (r *zipkindependencies.Dependencies, err error) + // Parameters: + // - ServiceName + GetTopAnnotations(service_name string) (r []string, err error) + // Parameters: + // - ServiceName + GetTopKeyValueAnnotations(service_name string) (r []string, err error) + // Given a time stamp, server service name, and rpc name, fetch all of the client services calling in paired + // with the lists of every span duration (list) from the server to client. The lists of span durations + // include information on call counts and mean/stdDev/etc of call durations. + // + // The three arguments specify epoch time in microseconds, server side service name and rpc name. The return maps + // contains the key - client_service_name and value - list. + // + // Parameters: + // - TimeStamp + // - ServiceName + // - RpcName + GetSpanDurations(time_stamp int64, service_name string, rpc_name string) (r map[string][]int64, err error) + // Given a time stamp, server service name, and rpc name, fetch all of the client services calling in paired + // with the lists of every trace Ids (list) from the server to client. + // + // The three arguments specify epoch time in microseconds, server side service name and rpc name. The return maps + // contains the key - client_service_name and value - list. + // + // Parameters: + // - TimeStamp + // - ServiceName + // - RpcName + GetServiceNamesToTraceIds(time_stamp int64, service_name string, rpc_name string) (r map[string][]int64, err error) +} + +type ZipkinQueryClient struct { + Transport thrift.TTransport + ProtocolFactory thrift.TProtocolFactory + InputProtocol thrift.TProtocol + OutputProtocol thrift.TProtocol + SeqId int32 +} + +func NewZipkinQueryClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *ZipkinQueryClient { + return &ZipkinQueryClient{Transport: t, + ProtocolFactory: f, + InputProtocol: f.GetProtocol(t), + OutputProtocol: f.GetProtocol(t), + SeqId: 0, + } +} + +func NewZipkinQueryClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *ZipkinQueryClient { + return &ZipkinQueryClient{Transport: t, + ProtocolFactory: nil, + InputProtocol: iprot, + OutputProtocol: oprot, + SeqId: 0, + } +} + +// Parameters: +// - Request +func (p *ZipkinQueryClient) GetTraceIds(request *QueryRequest) (r *QueryResponse, err error) { + if err = p.sendGetTraceIds(request); err != nil { + return + } + return p.recvGetTraceIds() +} + +func (p *ZipkinQueryClient) sendGetTraceIds(request *QueryRequest) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTraceIds", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTraceIdsArgs{ + Request: request, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTraceIds() (value *QueryResponse, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error10 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error11 error + error11, err = error10.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error11 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTraceIds failed: out of sequence response") + return + } + result := GetTraceIdsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Fetch trace ids by service and span name. +// Gets "limit" number of entries from before the "end_ts". +// +// Span name is optional. +// Timestamps are in microseconds. +// +// Parameters: +// - ServiceName +// - SpanName +// - EndTs +// - Limit +// - Order +func (p *ZipkinQueryClient) GetTraceIdsBySpanName(service_name string, span_name string, end_ts int64, limit int32, order Order) (r []int64, err error) { + if err = p.sendGetTraceIdsBySpanName(service_name, span_name, end_ts, limit, order); err != nil { + return + } + return p.recvGetTraceIdsBySpanName() +} + +func (p *ZipkinQueryClient) sendGetTraceIdsBySpanName(service_name string, span_name string, end_ts int64, limit int32, order Order) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTraceIdsBySpanName", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTraceIdsBySpanNameArgs{ + ServiceName: service_name, + SpanName: span_name, + EndTs: end_ts, + Limit: limit, + Order: order, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTraceIdsBySpanName() (value []int64, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error12 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error13 error + error13, err = error12.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error13 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTraceIdsBySpanName failed: out of sequence response") + return + } + result := GetTraceIdsBySpanNameResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Fetch trace ids by service name. +// Gets "limit" number of entries from before the "end_ts". +// +// Timestamps are in microseconds. +// +// Parameters: +// - ServiceName +// - EndTs +// - Limit +// - Order +func (p *ZipkinQueryClient) GetTraceIdsByServiceName(service_name string, end_ts int64, limit int32, order Order) (r []int64, err error) { + if err = p.sendGetTraceIdsByServiceName(service_name, end_ts, limit, order); err != nil { + return + } + return p.recvGetTraceIdsByServiceName() +} + +func (p *ZipkinQueryClient) sendGetTraceIdsByServiceName(service_name string, end_ts int64, limit int32, order Order) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTraceIdsByServiceName", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTraceIdsByServiceNameArgs{ + ServiceName: service_name, + EndTs: end_ts, + Limit: limit, + Order: order, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTraceIdsByServiceName() (value []int64, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error14 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error15 error + error15, err = error14.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error15 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTraceIdsByServiceName failed: out of sequence response") + return + } + result := GetTraceIdsByServiceNameResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Fetch trace ids with a particular annotation. +// Gets "limit" number of entries from before the "end_ts". +// +// When requesting based on time based annotations only pass in the first parameter, "annotation" and leave out +// the second "value". If looking for a key-value binary annotation provide both, "annotation" is then the +// key in the key-value. +// +// Timestamps are in microseconds. +// +// Parameters: +// - ServiceName +// - Annotation +// - Value +// - EndTs +// - Limit +// - Order +func (p *ZipkinQueryClient) GetTraceIdsByAnnotation(service_name string, annotation string, value []byte, end_ts int64, limit int32, order Order) (r []int64, err error) { + if err = p.sendGetTraceIdsByAnnotation(service_name, annotation, value, end_ts, limit, order); err != nil { + return + } + return p.recvGetTraceIdsByAnnotation() +} + +func (p *ZipkinQueryClient) sendGetTraceIdsByAnnotation(service_name string, annotation string, value []byte, end_ts int64, limit int32, order Order) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTraceIdsByAnnotation", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTraceIdsByAnnotationArgs{ + ServiceName: service_name, + Annotation: annotation, + Value: value, + EndTs: end_ts, + Limit: limit, + Order: order, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTraceIdsByAnnotation() (value []int64, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error16 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error17 error + error17, err = error16.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error17 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTraceIdsByAnnotation failed: out of sequence response") + return + } + result := GetTraceIdsByAnnotationResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Get the traces that are in the database from the given list of trace ids. +// +// Parameters: +// - TraceIds +func (p *ZipkinQueryClient) TracesExist(trace_ids []int64) (r map[int64]bool, err error) { + if err = p.sendTracesExist(trace_ids); err != nil { + return + } + return p.recvTracesExist() +} + +func (p *ZipkinQueryClient) sendTracesExist(trace_ids []int64) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("tracesExist", thrift.CALL, p.SeqId); err != nil { + return + } + args := TracesExistArgs{ + TraceIds: trace_ids, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvTracesExist() (value map[int64]bool, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error18 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error19 error + error19, err = error18.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error19 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "tracesExist failed: out of sequence response") + return + } + result := TracesExistResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Get the full traces associated with the given trace ids. +// +// Second argument is a list of methods of adjusting the trace +// data before returning it. Can be empty. +// +// Parameters: +// - TraceIds +// - Adjust +func (p *ZipkinQueryClient) GetTracesByIds(trace_ids []int64, adjust []Adjust) (r []*Trace, err error) { + if err = p.sendGetTracesByIds(trace_ids, adjust); err != nil { + return + } + return p.recvGetTracesByIds() +} + +func (p *ZipkinQueryClient) sendGetTracesByIds(trace_ids []int64, adjust []Adjust) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTracesByIds", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTracesByIdsArgs{ + TraceIds: trace_ids, + Adjust: adjust, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTracesByIds() (value []*Trace, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error20 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error21 error + error21, err = error20.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error21 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTracesByIds failed: out of sequence response") + return + } + result := GetTracesByIdsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Get the trace timelines associated with the given trace ids. +// This is a convenience method for users that just want to know +// the annotations and the (assumed) order they happened in. +// +// Second argument is a list of methods of adjusting the trace +// data before returning it. Can be empty. +// +// Note that if one of the trace ids does not have any data associated with it, it will not be +// represented in the output list. +// +// Parameters: +// - TraceIds +// - Adjust +func (p *ZipkinQueryClient) GetTraceTimelinesByIds(trace_ids []int64, adjust []Adjust) (r []*TraceTimeline, err error) { + if err = p.sendGetTraceTimelinesByIds(trace_ids, adjust); err != nil { + return + } + return p.recvGetTraceTimelinesByIds() +} + +func (p *ZipkinQueryClient) sendGetTraceTimelinesByIds(trace_ids []int64, adjust []Adjust) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTraceTimelinesByIds", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTraceTimelinesByIdsArgs{ + TraceIds: trace_ids, + Adjust: adjust, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTraceTimelinesByIds() (value []*TraceTimeline, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error22 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error23 error + error23, err = error22.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error23 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTraceTimelinesByIds failed: out of sequence response") + return + } + result := GetTraceTimelinesByIdsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Fetch trace summaries for the given trace ids. +// +// Second argument is a list of methods of adjusting the trace +// data before returning it. Can be empty. +// +// Note that if one of the trace ids does not have any data associated with it, it will not be +// represented in the output list. +// +// Parameters: +// - TraceIds +// - Adjust +func (p *ZipkinQueryClient) GetTraceSummariesByIds(trace_ids []int64, adjust []Adjust) (r []*TraceSummary, err error) { + if err = p.sendGetTraceSummariesByIds(trace_ids, adjust); err != nil { + return + } + return p.recvGetTraceSummariesByIds() +} + +func (p *ZipkinQueryClient) sendGetTraceSummariesByIds(trace_ids []int64, adjust []Adjust) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTraceSummariesByIds", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTraceSummariesByIdsArgs{ + TraceIds: trace_ids, + Adjust: adjust, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTraceSummariesByIds() (value []*TraceSummary, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error24 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error25 error + error25, err = error24.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error25 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTraceSummariesByIds failed: out of sequence response") + return + } + result := GetTraceSummariesByIdsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Not content with just one of traces, summaries or timelines? Want it all? This is the method for you. +// +// Parameters: +// - TraceIds +// - Adjust +func (p *ZipkinQueryClient) GetTraceCombosByIds(trace_ids []int64, adjust []Adjust) (r []*TraceCombo, err error) { + if err = p.sendGetTraceCombosByIds(trace_ids, adjust); err != nil { + return + } + return p.recvGetTraceCombosByIds() +} + +func (p *ZipkinQueryClient) sendGetTraceCombosByIds(trace_ids []int64, adjust []Adjust) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTraceCombosByIds", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTraceCombosByIdsArgs{ + TraceIds: trace_ids, + Adjust: adjust, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTraceCombosByIds() (value []*TraceCombo, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error26 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error27 error + error27, err = error26.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error27 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTraceCombosByIds failed: out of sequence response") + return + } + result := GetTraceCombosByIdsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Fetch all the service names we have seen from now all the way back to the set ttl. +func (p *ZipkinQueryClient) GetServiceNames() (r map[string]bool, err error) { + if err = p.sendGetServiceNames(); err != nil { + return + } + return p.recvGetServiceNames() +} + +func (p *ZipkinQueryClient) sendGetServiceNames() (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getServiceNames", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetServiceNamesArgs{} + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetServiceNames() (value map[string]bool, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error28 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error29 error + error29, err = error28.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error29 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getServiceNames failed: out of sequence response") + return + } + result := GetServiceNamesResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Get all the seen span names for a particular service, from now back until the set ttl. +// +// Parameters: +// - ServiceName +func (p *ZipkinQueryClient) GetSpanNames(service_name string) (r map[string]bool, err error) { + if err = p.sendGetSpanNames(service_name); err != nil { + return + } + return p.recvGetSpanNames() +} + +func (p *ZipkinQueryClient) sendGetSpanNames(service_name string) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getSpanNames", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetSpanNamesArgs{ + ServiceName: service_name, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetSpanNames() (value map[string]bool, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error30 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error31 error + error31, err = error30.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error31 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getSpanNames failed: out of sequence response") + return + } + result := GetSpanNamesResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Change the TTL of a trace. If we find an interesting trace we want to keep around for further +// investigation. +// +// Parameters: +// - TraceId +// - TtlSeconds +func (p *ZipkinQueryClient) SetTraceTimeToLive(trace_id int64, ttl_seconds int32) (err error) { + if err = p.sendSetTraceTimeToLive(trace_id, ttl_seconds); err != nil { + return + } + return p.recvSetTraceTimeToLive() +} + +func (p *ZipkinQueryClient) sendSetTraceTimeToLive(trace_id int64, ttl_seconds int32) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("setTraceTimeToLive", thrift.CALL, p.SeqId); err != nil { + return + } + args := SetTraceTimeToLiveArgs{ + TraceId: trace_id, + TtlSeconds: ttl_seconds, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvSetTraceTimeToLive() (err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error32 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error33 error + error33, err = error32.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error33 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "setTraceTimeToLive failed: out of sequence response") + return + } + result := SetTraceTimeToLiveResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + return +} + +// Get the TTL in seconds of a specific trace. +// +// Parameters: +// - TraceId +func (p *ZipkinQueryClient) GetTraceTimeToLive(trace_id int64) (r int32, err error) { + if err = p.sendGetTraceTimeToLive(trace_id); err != nil { + return + } + return p.recvGetTraceTimeToLive() +} + +func (p *ZipkinQueryClient) sendGetTraceTimeToLive(trace_id int64) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTraceTimeToLive", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTraceTimeToLiveArgs{ + TraceId: trace_id, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTraceTimeToLive() (value int32, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error34 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error35 error + error35, err = error34.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error35 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTraceTimeToLive failed: out of sequence response") + return + } + result := GetTraceTimeToLiveResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Get the data ttl. This is the number of seconds we keep the data around before deleting it. +func (p *ZipkinQueryClient) GetDataTimeToLive() (r int32, err error) { + if err = p.sendGetDataTimeToLive(); err != nil { + return + } + return p.recvGetDataTimeToLive() +} + +func (p *ZipkinQueryClient) sendGetDataTimeToLive() (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getDataTimeToLive", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetDataTimeToLiveArgs{} + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetDataTimeToLive() (value int32, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error36 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error37 error + error37, err = error36.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error37 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getDataTimeToLive failed: out of sequence response") + return + } + result := GetDataTimeToLiveResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Get an aggregate representation of all services paired with every service they call in to. +// This includes information on call counts and mean/stdDev/etc of call durations. The two arguments +// specify epoch time in microseconds. The end time is optional and defaults to one day after the +// start time. +// +// Parameters: +// - StartTime +// - EndTime +func (p *ZipkinQueryClient) GetDependencies(start_time int64, end_time int64) (r *zipkindependencies.Dependencies, err error) { + if err = p.sendGetDependencies(start_time, end_time); err != nil { + return + } + return p.recvGetDependencies() +} + +func (p *ZipkinQueryClient) sendGetDependencies(start_time int64, end_time int64) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getDependencies", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetDependenciesArgs{ + StartTime: start_time, + EndTime: end_time, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetDependencies() (value *zipkindependencies.Dependencies, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error38 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error39 error + error39, err = error38.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error39 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getDependencies failed: out of sequence response") + return + } + result := GetDependenciesResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Parameters: +// - ServiceName +func (p *ZipkinQueryClient) GetTopAnnotations(service_name string) (r []string, err error) { + if err = p.sendGetTopAnnotations(service_name); err != nil { + return + } + return p.recvGetTopAnnotations() +} + +func (p *ZipkinQueryClient) sendGetTopAnnotations(service_name string) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTopAnnotations", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTopAnnotationsArgs{ + ServiceName: service_name, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTopAnnotations() (value []string, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error40 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error41 error + error41, err = error40.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error41 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTopAnnotations failed: out of sequence response") + return + } + result := GetTopAnnotationsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Parameters: +// - ServiceName +func (p *ZipkinQueryClient) GetTopKeyValueAnnotations(service_name string) (r []string, err error) { + if err = p.sendGetTopKeyValueAnnotations(service_name); err != nil { + return + } + return p.recvGetTopKeyValueAnnotations() +} + +func (p *ZipkinQueryClient) sendGetTopKeyValueAnnotations(service_name string) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getTopKeyValueAnnotations", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetTopKeyValueAnnotationsArgs{ + ServiceName: service_name, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetTopKeyValueAnnotations() (value []string, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error42 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error43 error + error43, err = error42.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error43 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getTopKeyValueAnnotations failed: out of sequence response") + return + } + result := GetTopKeyValueAnnotationsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + if result.Qe != nil { + err = result.Qe + return + } + value = result.GetSuccess() + return +} + +// Given a time stamp, server service name, and rpc name, fetch all of the client services calling in paired +// with the lists of every span duration (list) from the server to client. The lists of span durations +// include information on call counts and mean/stdDev/etc of call durations. +// +// The three arguments specify epoch time in microseconds, server side service name and rpc name. The return maps +// contains the key - client_service_name and value - list. +// +// Parameters: +// - TimeStamp +// - ServiceName +// - RpcName +func (p *ZipkinQueryClient) GetSpanDurations(time_stamp int64, service_name string, rpc_name string) (r map[string][]int64, err error) { + if err = p.sendGetSpanDurations(time_stamp, service_name, rpc_name); err != nil { + return + } + return p.recvGetSpanDurations() +} + +func (p *ZipkinQueryClient) sendGetSpanDurations(time_stamp int64, service_name string, rpc_name string) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getSpanDurations", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetSpanDurationsArgs{ + TimeStamp: time_stamp, + ServiceName: service_name, + RpcName: rpc_name, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetSpanDurations() (value map[string][]int64, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error44 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error45 error + error45, err = error44.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error45 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getSpanDurations failed: out of sequence response") + return + } + result := GetSpanDurationsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +// Given a time stamp, server service name, and rpc name, fetch all of the client services calling in paired +// with the lists of every trace Ids (list) from the server to client. +// +// The three arguments specify epoch time in microseconds, server side service name and rpc name. The return maps +// contains the key - client_service_name and value - list. +// +// Parameters: +// - TimeStamp +// - ServiceName +// - RpcName +func (p *ZipkinQueryClient) GetServiceNamesToTraceIds(time_stamp int64, service_name string, rpc_name string) (r map[string][]int64, err error) { + if err = p.sendGetServiceNamesToTraceIds(time_stamp, service_name, rpc_name); err != nil { + return + } + return p.recvGetServiceNamesToTraceIds() +} + +func (p *ZipkinQueryClient) sendGetServiceNamesToTraceIds(time_stamp int64, service_name string, rpc_name string) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("getServiceNamesToTraceIds", thrift.CALL, p.SeqId); err != nil { + return + } + args := GetServiceNamesToTraceIdsArgs{ + TimeStamp: time_stamp, + ServiceName: service_name, + RpcName: rpc_name, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *ZipkinQueryClient) recvGetServiceNamesToTraceIds() (value map[string][]int64, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error46 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error47 error + error47, err = error46.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error47 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "getServiceNamesToTraceIds failed: out of sequence response") + return + } + result := GetServiceNamesToTraceIdsResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +type ZipkinQueryProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler ZipkinQuery +} + +func (p *ZipkinQueryProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *ZipkinQueryProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *ZipkinQueryProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewZipkinQueryProcessor(handler ZipkinQuery) *ZipkinQueryProcessor { + + self48 := &ZipkinQueryProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self48.processorMap["getTraceIds"] = &zipkinQueryProcessorGetTraceIds{handler: handler} + self48.processorMap["getTraceIdsBySpanName"] = &zipkinQueryProcessorGetTraceIdsBySpanName{handler: handler} + self48.processorMap["getTraceIdsByServiceName"] = &zipkinQueryProcessorGetTraceIdsByServiceName{handler: handler} + self48.processorMap["getTraceIdsByAnnotation"] = &zipkinQueryProcessorGetTraceIdsByAnnotation{handler: handler} + self48.processorMap["tracesExist"] = &zipkinQueryProcessorTracesExist{handler: handler} + self48.processorMap["getTracesByIds"] = &zipkinQueryProcessorGetTracesByIds{handler: handler} + self48.processorMap["getTraceTimelinesByIds"] = &zipkinQueryProcessorGetTraceTimelinesByIds{handler: handler} + self48.processorMap["getTraceSummariesByIds"] = &zipkinQueryProcessorGetTraceSummariesByIds{handler: handler} + self48.processorMap["getTraceCombosByIds"] = &zipkinQueryProcessorGetTraceCombosByIds{handler: handler} + self48.processorMap["getServiceNames"] = &zipkinQueryProcessorGetServiceNames{handler: handler} + self48.processorMap["getSpanNames"] = &zipkinQueryProcessorGetSpanNames{handler: handler} + self48.processorMap["setTraceTimeToLive"] = &zipkinQueryProcessorSetTraceTimeToLive{handler: handler} + self48.processorMap["getTraceTimeToLive"] = &zipkinQueryProcessorGetTraceTimeToLive{handler: handler} + self48.processorMap["getDataTimeToLive"] = &zipkinQueryProcessorGetDataTimeToLive{handler: handler} + self48.processorMap["getDependencies"] = &zipkinQueryProcessorGetDependencies{handler: handler} + self48.processorMap["getTopAnnotations"] = &zipkinQueryProcessorGetTopAnnotations{handler: handler} + self48.processorMap["getTopKeyValueAnnotations"] = &zipkinQueryProcessorGetTopKeyValueAnnotations{handler: handler} + self48.processorMap["getSpanDurations"] = &zipkinQueryProcessorGetSpanDurations{handler: handler} + self48.processorMap["getServiceNamesToTraceIds"] = &zipkinQueryProcessorGetServiceNamesToTraceIds{handler: handler} + return self48 +} + +func (p *ZipkinQueryProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x49 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x49.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, x49 + +} + +type zipkinQueryProcessorGetTraceIds struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTraceIds) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTraceIdsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTraceIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTraceIdsResult{} + var retval *QueryResponse + var err2 error + if retval, err2 = p.handler.GetTraceIds(args.Request); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTraceIds: "+err2.Error()) + oprot.WriteMessageBegin("getTraceIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTraceIds", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTraceIdsBySpanName struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTraceIdsBySpanName) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTraceIdsBySpanNameArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTraceIdsBySpanName", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTraceIdsBySpanNameResult{} + var retval []int64 + var err2 error + if retval, err2 = p.handler.GetTraceIdsBySpanName(args.ServiceName, args.SpanName, args.EndTs, args.Limit, args.Order); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTraceIdsBySpanName: "+err2.Error()) + oprot.WriteMessageBegin("getTraceIdsBySpanName", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTraceIdsBySpanName", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTraceIdsByServiceName struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTraceIdsByServiceName) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTraceIdsByServiceNameArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTraceIdsByServiceName", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTraceIdsByServiceNameResult{} + var retval []int64 + var err2 error + if retval, err2 = p.handler.GetTraceIdsByServiceName(args.ServiceName, args.EndTs, args.Limit, args.Order); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTraceIdsByServiceName: "+err2.Error()) + oprot.WriteMessageBegin("getTraceIdsByServiceName", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTraceIdsByServiceName", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTraceIdsByAnnotation struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTraceIdsByAnnotation) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTraceIdsByAnnotationArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTraceIdsByAnnotation", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTraceIdsByAnnotationResult{} + var retval []int64 + var err2 error + if retval, err2 = p.handler.GetTraceIdsByAnnotation(args.ServiceName, args.Annotation, args.Value, args.EndTs, args.Limit, args.Order); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTraceIdsByAnnotation: "+err2.Error()) + oprot.WriteMessageBegin("getTraceIdsByAnnotation", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTraceIdsByAnnotation", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorTracesExist struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorTracesExist) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := TracesExistArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("tracesExist", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := TracesExistResult{} + var retval map[int64]bool + var err2 error + if retval, err2 = p.handler.TracesExist(args.TraceIds); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing tracesExist: "+err2.Error()) + oprot.WriteMessageBegin("tracesExist", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("tracesExist", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTracesByIds struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTracesByIds) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTracesByIdsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTracesByIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTracesByIdsResult{} + var retval []*Trace + var err2 error + if retval, err2 = p.handler.GetTracesByIds(args.TraceIds, args.Adjust); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTracesByIds: "+err2.Error()) + oprot.WriteMessageBegin("getTracesByIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTracesByIds", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTraceTimelinesByIds struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTraceTimelinesByIds) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTraceTimelinesByIdsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTraceTimelinesByIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTraceTimelinesByIdsResult{} + var retval []*TraceTimeline + var err2 error + if retval, err2 = p.handler.GetTraceTimelinesByIds(args.TraceIds, args.Adjust); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTraceTimelinesByIds: "+err2.Error()) + oprot.WriteMessageBegin("getTraceTimelinesByIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTraceTimelinesByIds", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTraceSummariesByIds struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTraceSummariesByIds) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTraceSummariesByIdsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTraceSummariesByIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTraceSummariesByIdsResult{} + var retval []*TraceSummary + var err2 error + if retval, err2 = p.handler.GetTraceSummariesByIds(args.TraceIds, args.Adjust); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTraceSummariesByIds: "+err2.Error()) + oprot.WriteMessageBegin("getTraceSummariesByIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTraceSummariesByIds", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTraceCombosByIds struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTraceCombosByIds) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTraceCombosByIdsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTraceCombosByIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTraceCombosByIdsResult{} + var retval []*TraceCombo + var err2 error + if retval, err2 = p.handler.GetTraceCombosByIds(args.TraceIds, args.Adjust); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTraceCombosByIds: "+err2.Error()) + oprot.WriteMessageBegin("getTraceCombosByIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTraceCombosByIds", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetServiceNames struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetServiceNames) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetServiceNamesArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getServiceNames", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetServiceNamesResult{} + var retval map[string]bool + var err2 error + if retval, err2 = p.handler.GetServiceNames(); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getServiceNames: "+err2.Error()) + oprot.WriteMessageBegin("getServiceNames", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getServiceNames", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetSpanNames struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetSpanNames) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetSpanNamesArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getSpanNames", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetSpanNamesResult{} + var retval map[string]bool + var err2 error + if retval, err2 = p.handler.GetSpanNames(args.ServiceName); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getSpanNames: "+err2.Error()) + oprot.WriteMessageBegin("getSpanNames", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getSpanNames", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorSetTraceTimeToLive struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorSetTraceTimeToLive) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := SetTraceTimeToLiveArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("setTraceTimeToLive", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := SetTraceTimeToLiveResult{} + var err2 error + if err2 = p.handler.SetTraceTimeToLive(args.TraceId, args.TtlSeconds); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing setTraceTimeToLive: "+err2.Error()) + oprot.WriteMessageBegin("setTraceTimeToLive", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } + if err2 = oprot.WriteMessageBegin("setTraceTimeToLive", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTraceTimeToLive struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTraceTimeToLive) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTraceTimeToLiveArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTraceTimeToLive", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTraceTimeToLiveResult{} + var retval int32 + var err2 error + if retval, err2 = p.handler.GetTraceTimeToLive(args.TraceId); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTraceTimeToLive: "+err2.Error()) + oprot.WriteMessageBegin("getTraceTimeToLive", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = &retval + } + if err2 = oprot.WriteMessageBegin("getTraceTimeToLive", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetDataTimeToLive struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetDataTimeToLive) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetDataTimeToLiveArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getDataTimeToLive", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetDataTimeToLiveResult{} + var retval int32 + var err2 error + if retval, err2 = p.handler.GetDataTimeToLive(); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getDataTimeToLive: "+err2.Error()) + oprot.WriteMessageBegin("getDataTimeToLive", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = &retval + } + if err2 = oprot.WriteMessageBegin("getDataTimeToLive", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetDependencies struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetDependencies) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetDependenciesArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getDependencies", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetDependenciesResult{} + var retval *zipkindependencies.Dependencies + var err2 error + if retval, err2 = p.handler.GetDependencies(args.StartTime, args.EndTime); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getDependencies: "+err2.Error()) + oprot.WriteMessageBegin("getDependencies", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getDependencies", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTopAnnotations struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTopAnnotations) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTopAnnotationsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTopAnnotations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTopAnnotationsResult{} + var retval []string + var err2 error + if retval, err2 = p.handler.GetTopAnnotations(args.ServiceName); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTopAnnotations: "+err2.Error()) + oprot.WriteMessageBegin("getTopAnnotations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTopAnnotations", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetTopKeyValueAnnotations struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetTopKeyValueAnnotations) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetTopKeyValueAnnotationsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getTopKeyValueAnnotations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetTopKeyValueAnnotationsResult{} + var retval []string + var err2 error + if retval, err2 = p.handler.GetTopKeyValueAnnotations(args.ServiceName); err2 != nil { + switch v := err2.(type) { + case *QueryException: + result.Qe = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getTopKeyValueAnnotations: "+err2.Error()) + oprot.WriteMessageBegin("getTopKeyValueAnnotations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getTopKeyValueAnnotations", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetSpanDurations struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetSpanDurations) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetSpanDurationsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getSpanDurations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetSpanDurationsResult{} + var retval map[string][]int64 + var err2 error + if retval, err2 = p.handler.GetSpanDurations(args.TimeStamp, args.ServiceName, args.RpcName); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getSpanDurations: "+err2.Error()) + oprot.WriteMessageBegin("getSpanDurations", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getSpanDurations", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type zipkinQueryProcessorGetServiceNamesToTraceIds struct { + handler ZipkinQuery +} + +func (p *zipkinQueryProcessorGetServiceNamesToTraceIds) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := GetServiceNamesToTraceIdsArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("getServiceNamesToTraceIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := GetServiceNamesToTraceIdsResult{} + var retval map[string][]int64 + var err2 error + if retval, err2 = p.handler.GetServiceNamesToTraceIds(args.TimeStamp, args.ServiceName, args.RpcName); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing getServiceNamesToTraceIds: "+err2.Error()) + oprot.WriteMessageBegin("getServiceNamesToTraceIds", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("getServiceNamesToTraceIds", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +// HELPER FUNCTIONS AND STRUCTURES + +type GetTraceIdsArgs struct { + Request *QueryRequest `thrift:"request,1" json:"request"` +} + +func NewGetTraceIdsArgs() *GetTraceIdsArgs { + return &GetTraceIdsArgs{} +} + +var GetTraceIdsArgs_Request_DEFAULT *QueryRequest + +func (p *GetTraceIdsArgs) GetRequest() *QueryRequest { + if !p.IsSetRequest() { + return GetTraceIdsArgs_Request_DEFAULT + } + return p.Request +} +func (p *GetTraceIdsArgs) IsSetRequest() bool { + return p.Request != nil +} + +func (p *GetTraceIdsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceIdsArgs) ReadField1(iprot thrift.TProtocol) error { + p.Request = &QueryRequest{} + if err := p.Request.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Request, err) + } + return nil +} + +func (p *GetTraceIdsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceIds_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceIdsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("request", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:request: %s", p, err) + } + if err := p.Request.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Request, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:request: %s", p, err) + } + return err +} + +func (p *GetTraceIdsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceIdsArgs(%+v)", *p) +} + +type GetTraceIdsResult struct { + Success *QueryResponse `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTraceIdsResult() *GetTraceIdsResult { + return &GetTraceIdsResult{} +} + +var GetTraceIdsResult_Success_DEFAULT *QueryResponse + +func (p *GetTraceIdsResult) GetSuccess() *QueryResponse { + if !p.IsSetSuccess() { + return GetTraceIdsResult_Success_DEFAULT + } + return p.Success +} + +var GetTraceIdsResult_Qe_DEFAULT *QueryException + +func (p *GetTraceIdsResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTraceIdsResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTraceIdsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTraceIdsResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTraceIdsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceIdsResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = &QueryResponse{} + if err := p.Success.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Success, err) + } + return nil +} + +func (p *GetTraceIdsResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTraceIdsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceIds_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceIdsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := p.Success.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Success, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTraceIdsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTraceIdsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceIdsResult(%+v)", *p) +} + +type GetTraceIdsBySpanNameArgs struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` + SpanName string `thrift:"span_name,2" json:"span_name"` + // unused field # 3 + EndTs int64 `thrift:"end_ts,4" json:"end_ts"` + Limit int32 `thrift:"limit,5" json:"limit"` + Order Order `thrift:"order,6" json:"order"` +} + +func NewGetTraceIdsBySpanNameArgs() *GetTraceIdsBySpanNameArgs { + return &GetTraceIdsBySpanNameArgs{} +} + +func (p *GetTraceIdsBySpanNameArgs) GetServiceName() string { + return p.ServiceName +} + +func (p *GetTraceIdsBySpanNameArgs) GetSpanName() string { + return p.SpanName +} + +func (p *GetTraceIdsBySpanNameArgs) GetEndTs() int64 { + return p.EndTs +} + +func (p *GetTraceIdsBySpanNameArgs) GetLimit() int32 { + return p.Limit +} + +func (p *GetTraceIdsBySpanNameArgs) GetOrder() Order { + return p.Order +} +func (p *GetTraceIdsBySpanNameArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceIdsBySpanNameArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *GetTraceIdsBySpanNameArgs) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.SpanName = v + } + return nil +} + +func (p *GetTraceIdsBySpanNameArgs) ReadField4(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 4: %s", err) + } else { + p.EndTs = v + } + return nil +} + +func (p *GetTraceIdsBySpanNameArgs) ReadField5(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 5: %s", err) + } else { + p.Limit = v + } + return nil +} + +func (p *GetTraceIdsBySpanNameArgs) ReadField6(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 6: %s", err) + } else { + temp := Order(v) + p.Order = temp + } + return nil +} + +func (p *GetTraceIdsBySpanNameArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceIdsBySpanName_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := p.writeField5(oprot); err != nil { + return err + } + if err := p.writeField6(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceIdsBySpanNameArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *GetTraceIdsBySpanNameArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("span_name", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:span_name: %s", p, err) + } + if err := oprot.WriteString(string(p.SpanName)); err != nil { + return fmt.Errorf("%T.span_name (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:span_name: %s", p, err) + } + return err +} + +func (p *GetTraceIdsBySpanNameArgs) writeField4(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_ts", thrift.I64, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:end_ts: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTs)); err != nil { + return fmt.Errorf("%T.end_ts (4) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:end_ts: %s", p, err) + } + return err +} + +func (p *GetTraceIdsBySpanNameArgs) writeField5(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("limit", thrift.I32, 5); err != nil { + return fmt.Errorf("%T write field begin error 5:limit: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Limit)); err != nil { + return fmt.Errorf("%T.limit (5) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 5:limit: %s", p, err) + } + return err +} + +func (p *GetTraceIdsBySpanNameArgs) writeField6(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("order", thrift.I32, 6); err != nil { + return fmt.Errorf("%T write field begin error 6:order: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Order)); err != nil { + return fmt.Errorf("%T.order (6) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 6:order: %s", p, err) + } + return err +} + +func (p *GetTraceIdsBySpanNameArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceIdsBySpanNameArgs(%+v)", *p) +} + +type GetTraceIdsBySpanNameResult struct { + Success []int64 `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTraceIdsBySpanNameResult() *GetTraceIdsBySpanNameResult { + return &GetTraceIdsBySpanNameResult{} +} + +var GetTraceIdsBySpanNameResult_Success_DEFAULT []int64 + +func (p *GetTraceIdsBySpanNameResult) GetSuccess() []int64 { + return p.Success +} + +var GetTraceIdsBySpanNameResult_Qe_DEFAULT *QueryException + +func (p *GetTraceIdsBySpanNameResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTraceIdsBySpanNameResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTraceIdsBySpanNameResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTraceIdsBySpanNameResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTraceIdsBySpanNameResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceIdsBySpanNameResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + var _elem50 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem50 = v + } + p.Success = append(p.Success, _elem50) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceIdsBySpanNameResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTraceIdsBySpanNameResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceIdsBySpanName_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceIdsBySpanNameResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTraceIdsBySpanNameResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTraceIdsBySpanNameResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceIdsBySpanNameResult(%+v)", *p) +} + +type GetTraceIdsByServiceNameArgs struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` + // unused field # 2 + EndTs int64 `thrift:"end_ts,3" json:"end_ts"` + Limit int32 `thrift:"limit,4" json:"limit"` + Order Order `thrift:"order,5" json:"order"` +} + +func NewGetTraceIdsByServiceNameArgs() *GetTraceIdsByServiceNameArgs { + return &GetTraceIdsByServiceNameArgs{} +} + +func (p *GetTraceIdsByServiceNameArgs) GetServiceName() string { + return p.ServiceName +} + +func (p *GetTraceIdsByServiceNameArgs) GetEndTs() int64 { + return p.EndTs +} + +func (p *GetTraceIdsByServiceNameArgs) GetLimit() int32 { + return p.Limit +} + +func (p *GetTraceIdsByServiceNameArgs) GetOrder() Order { + return p.Order +} +func (p *GetTraceIdsByServiceNameArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 4: + if err := p.ReadField4(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceIdsByServiceNameArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *GetTraceIdsByServiceNameArgs) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.EndTs = v + } + return nil +} + +func (p *GetTraceIdsByServiceNameArgs) ReadField4(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 4: %s", err) + } else { + p.Limit = v + } + return nil +} + +func (p *GetTraceIdsByServiceNameArgs) ReadField5(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 5: %s", err) + } else { + temp := Order(v) + p.Order = temp + } + return nil +} + +func (p *GetTraceIdsByServiceNameArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceIdsByServiceName_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField4(oprot); err != nil { + return err + } + if err := p.writeField5(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceIdsByServiceNameArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByServiceNameArgs) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_ts", thrift.I64, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:end_ts: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTs)); err != nil { + return fmt.Errorf("%T.end_ts (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:end_ts: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByServiceNameArgs) writeField4(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("limit", thrift.I32, 4); err != nil { + return fmt.Errorf("%T write field begin error 4:limit: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Limit)); err != nil { + return fmt.Errorf("%T.limit (4) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 4:limit: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByServiceNameArgs) writeField5(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("order", thrift.I32, 5); err != nil { + return fmt.Errorf("%T write field begin error 5:order: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Order)); err != nil { + return fmt.Errorf("%T.order (5) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 5:order: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByServiceNameArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceIdsByServiceNameArgs(%+v)", *p) +} + +type GetTraceIdsByServiceNameResult struct { + Success []int64 `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTraceIdsByServiceNameResult() *GetTraceIdsByServiceNameResult { + return &GetTraceIdsByServiceNameResult{} +} + +var GetTraceIdsByServiceNameResult_Success_DEFAULT []int64 + +func (p *GetTraceIdsByServiceNameResult) GetSuccess() []int64 { + return p.Success +} + +var GetTraceIdsByServiceNameResult_Qe_DEFAULT *QueryException + +func (p *GetTraceIdsByServiceNameResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTraceIdsByServiceNameResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTraceIdsByServiceNameResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTraceIdsByServiceNameResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTraceIdsByServiceNameResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceIdsByServiceNameResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + var _elem51 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem51 = v + } + p.Success = append(p.Success, _elem51) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceIdsByServiceNameResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTraceIdsByServiceNameResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceIdsByServiceName_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceIdsByServiceNameResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTraceIdsByServiceNameResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTraceIdsByServiceNameResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceIdsByServiceNameResult(%+v)", *p) +} + +type GetTraceIdsByAnnotationArgs struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` + Annotation string `thrift:"annotation,2" json:"annotation"` + Value []byte `thrift:"value,3" json:"value"` + // unused field # 4 + EndTs int64 `thrift:"end_ts,5" json:"end_ts"` + Limit int32 `thrift:"limit,6" json:"limit"` + Order Order `thrift:"order,7" json:"order"` +} + +func NewGetTraceIdsByAnnotationArgs() *GetTraceIdsByAnnotationArgs { + return &GetTraceIdsByAnnotationArgs{} +} + +func (p *GetTraceIdsByAnnotationArgs) GetServiceName() string { + return p.ServiceName +} + +func (p *GetTraceIdsByAnnotationArgs) GetAnnotation() string { + return p.Annotation +} + +func (p *GetTraceIdsByAnnotationArgs) GetValue() []byte { + return p.Value +} + +func (p *GetTraceIdsByAnnotationArgs) GetEndTs() int64 { + return p.EndTs +} + +func (p *GetTraceIdsByAnnotationArgs) GetLimit() int32 { + return p.Limit +} + +func (p *GetTraceIdsByAnnotationArgs) GetOrder() Order { + return p.Order +} +func (p *GetTraceIdsByAnnotationArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + case 5: + if err := p.ReadField5(iprot); err != nil { + return err + } + case 6: + if err := p.ReadField6(iprot); err != nil { + return err + } + case 7: + if err := p.ReadField7(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceIdsByAnnotationArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *GetTraceIdsByAnnotationArgs) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.Annotation = v + } + return nil +} + +func (p *GetTraceIdsByAnnotationArgs) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.Value = v + } + return nil +} + +func (p *GetTraceIdsByAnnotationArgs) ReadField5(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 5: %s", err) + } else { + p.EndTs = v + } + return nil +} + +func (p *GetTraceIdsByAnnotationArgs) ReadField6(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 6: %s", err) + } else { + p.Limit = v + } + return nil +} + +func (p *GetTraceIdsByAnnotationArgs) ReadField7(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 7: %s", err) + } else { + temp := Order(v) + p.Order = temp + } + return nil +} + +func (p *GetTraceIdsByAnnotationArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceIdsByAnnotation_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := p.writeField5(oprot); err != nil { + return err + } + if err := p.writeField6(oprot); err != nil { + return err + } + if err := p.writeField7(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceIdsByAnnotationArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByAnnotationArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("annotation", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:annotation: %s", p, err) + } + if err := oprot.WriteString(string(p.Annotation)); err != nil { + return fmt.Errorf("%T.annotation (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:annotation: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByAnnotationArgs) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("value", thrift.STRING, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:value: %s", p, err) + } + if err := oprot.WriteBinary(p.Value); err != nil { + return fmt.Errorf("%T.value (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:value: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByAnnotationArgs) writeField5(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_ts", thrift.I64, 5); err != nil { + return fmt.Errorf("%T write field begin error 5:end_ts: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTs)); err != nil { + return fmt.Errorf("%T.end_ts (5) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 5:end_ts: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByAnnotationArgs) writeField6(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("limit", thrift.I32, 6); err != nil { + return fmt.Errorf("%T write field begin error 6:limit: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Limit)); err != nil { + return fmt.Errorf("%T.limit (6) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 6:limit: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByAnnotationArgs) writeField7(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("order", thrift.I32, 7); err != nil { + return fmt.Errorf("%T write field begin error 7:order: %s", p, err) + } + if err := oprot.WriteI32(int32(p.Order)); err != nil { + return fmt.Errorf("%T.order (7) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 7:order: %s", p, err) + } + return err +} + +func (p *GetTraceIdsByAnnotationArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceIdsByAnnotationArgs(%+v)", *p) +} + +type GetTraceIdsByAnnotationResult struct { + Success []int64 `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTraceIdsByAnnotationResult() *GetTraceIdsByAnnotationResult { + return &GetTraceIdsByAnnotationResult{} +} + +var GetTraceIdsByAnnotationResult_Success_DEFAULT []int64 + +func (p *GetTraceIdsByAnnotationResult) GetSuccess() []int64 { + return p.Success +} + +var GetTraceIdsByAnnotationResult_Qe_DEFAULT *QueryException + +func (p *GetTraceIdsByAnnotationResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTraceIdsByAnnotationResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTraceIdsByAnnotationResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTraceIdsByAnnotationResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTraceIdsByAnnotationResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceIdsByAnnotationResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + var _elem52 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem52 = v + } + p.Success = append(p.Success, _elem52) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceIdsByAnnotationResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTraceIdsByAnnotationResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceIdsByAnnotation_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceIdsByAnnotationResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTraceIdsByAnnotationResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTraceIdsByAnnotationResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceIdsByAnnotationResult(%+v)", *p) +} + +type TracesExistArgs struct { + TraceIds []int64 `thrift:"trace_ids,1" json:"trace_ids"` +} + +func NewTracesExistArgs() *TracesExistArgs { + return &TracesExistArgs{} +} + +func (p *TracesExistArgs) GetTraceIds() []int64 { + return p.TraceIds +} +func (p *TracesExistArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *TracesExistArgs) ReadField1(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.TraceIds = tSlice + for i := 0; i < size; i++ { + var _elem53 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem53 = v + } + p.TraceIds = append(p.TraceIds, _elem53) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *TracesExistArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("tracesExist_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *TracesExistArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_ids", thrift.LIST, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_ids: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.TraceIds)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.TraceIds { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_ids: %s", p, err) + } + return err +} + +func (p *TracesExistArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("TracesExistArgs(%+v)", *p) +} + +type TracesExistResult struct { + Success map[int64]bool `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewTracesExistResult() *TracesExistResult { + return &TracesExistResult{} +} + +var TracesExistResult_Success_DEFAULT map[int64]bool + +func (p *TracesExistResult) GetSuccess() map[int64]bool { + return p.Success +} + +var TracesExistResult_Qe_DEFAULT *QueryException + +func (p *TracesExistResult) GetQe() *QueryException { + if !p.IsSetQe() { + return TracesExistResult_Qe_DEFAULT + } + return p.Qe +} +func (p *TracesExistResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *TracesExistResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *TracesExistResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *TracesExistResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadSetBegin() + if err != nil { + return fmt.Errorf("error reading set begin: %s", err) + } + tSet := make(map[int64]bool, size) + p.Success = tSet + for i := 0; i < size; i++ { + var _elem54 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem54 = v + } + p.Success[_elem54] = true + } + if err := iprot.ReadSetEnd(); err != nil { + return fmt.Errorf("error reading set end: %s", err) + } + return nil +} + +func (p *TracesExistResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *TracesExistResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("tracesExist_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *TracesExistResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.SET, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteSetBegin(thrift.I64, len(p.Success)); err != nil { + return fmt.Errorf("error writing set begin: %s", err) + } + for v, _ := range p.Success { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteSetEnd(); err != nil { + return fmt.Errorf("error writing set end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *TracesExistResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *TracesExistResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("TracesExistResult(%+v)", *p) +} + +type GetTracesByIdsArgs struct { + TraceIds []int64 `thrift:"trace_ids,1" json:"trace_ids"` + Adjust []Adjust `thrift:"adjust,2" json:"adjust"` +} + +func NewGetTracesByIdsArgs() *GetTracesByIdsArgs { + return &GetTracesByIdsArgs{} +} + +func (p *GetTracesByIdsArgs) GetTraceIds() []int64 { + return p.TraceIds +} + +func (p *GetTracesByIdsArgs) GetAdjust() []Adjust { + return p.Adjust +} +func (p *GetTracesByIdsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTracesByIdsArgs) ReadField1(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.TraceIds = tSlice + for i := 0; i < size; i++ { + var _elem55 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem55 = v + } + p.TraceIds = append(p.TraceIds, _elem55) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTracesByIdsArgs) ReadField2(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]Adjust, 0, size) + p.Adjust = tSlice + for i := 0; i < size; i++ { + var _elem56 Adjust + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + temp := Adjust(v) + _elem56 = temp + } + p.Adjust = append(p.Adjust, _elem56) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTracesByIdsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTracesByIds_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTracesByIdsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_ids", thrift.LIST, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_ids: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.TraceIds)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.TraceIds { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_ids: %s", p, err) + } + return err +} + +func (p *GetTracesByIdsArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("adjust", thrift.LIST, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:adjust: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I32, len(p.Adjust)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Adjust { + if err := oprot.WriteI32(int32(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:adjust: %s", p, err) + } + return err +} + +func (p *GetTracesByIdsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTracesByIdsArgs(%+v)", *p) +} + +type GetTracesByIdsResult struct { + Success []*Trace `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTracesByIdsResult() *GetTracesByIdsResult { + return &GetTracesByIdsResult{} +} + +var GetTracesByIdsResult_Success_DEFAULT []*Trace + +func (p *GetTracesByIdsResult) GetSuccess() []*Trace { + return p.Success +} + +var GetTracesByIdsResult_Qe_DEFAULT *QueryException + +func (p *GetTracesByIdsResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTracesByIdsResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTracesByIdsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTracesByIdsResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTracesByIdsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTracesByIdsResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*Trace, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + _elem57 := &Trace{} + if err := _elem57.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem57, err) + } + p.Success = append(p.Success, _elem57) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTracesByIdsResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTracesByIdsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTracesByIds_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTracesByIdsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTracesByIdsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTracesByIdsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTracesByIdsResult(%+v)", *p) +} + +type GetTraceTimelinesByIdsArgs struct { + TraceIds []int64 `thrift:"trace_ids,1" json:"trace_ids"` + Adjust []Adjust `thrift:"adjust,2" json:"adjust"` +} + +func NewGetTraceTimelinesByIdsArgs() *GetTraceTimelinesByIdsArgs { + return &GetTraceTimelinesByIdsArgs{} +} + +func (p *GetTraceTimelinesByIdsArgs) GetTraceIds() []int64 { + return p.TraceIds +} + +func (p *GetTraceTimelinesByIdsArgs) GetAdjust() []Adjust { + return p.Adjust +} +func (p *GetTraceTimelinesByIdsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceTimelinesByIdsArgs) ReadField1(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.TraceIds = tSlice + for i := 0; i < size; i++ { + var _elem58 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem58 = v + } + p.TraceIds = append(p.TraceIds, _elem58) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceTimelinesByIdsArgs) ReadField2(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]Adjust, 0, size) + p.Adjust = tSlice + for i := 0; i < size; i++ { + var _elem59 Adjust + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + temp := Adjust(v) + _elem59 = temp + } + p.Adjust = append(p.Adjust, _elem59) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceTimelinesByIdsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceTimelinesByIds_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceTimelinesByIdsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_ids", thrift.LIST, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_ids: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.TraceIds)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.TraceIds { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_ids: %s", p, err) + } + return err +} + +func (p *GetTraceTimelinesByIdsArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("adjust", thrift.LIST, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:adjust: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I32, len(p.Adjust)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Adjust { + if err := oprot.WriteI32(int32(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:adjust: %s", p, err) + } + return err +} + +func (p *GetTraceTimelinesByIdsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceTimelinesByIdsArgs(%+v)", *p) +} + +type GetTraceTimelinesByIdsResult struct { + Success []*TraceTimeline `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTraceTimelinesByIdsResult() *GetTraceTimelinesByIdsResult { + return &GetTraceTimelinesByIdsResult{} +} + +var GetTraceTimelinesByIdsResult_Success_DEFAULT []*TraceTimeline + +func (p *GetTraceTimelinesByIdsResult) GetSuccess() []*TraceTimeline { + return p.Success +} + +var GetTraceTimelinesByIdsResult_Qe_DEFAULT *QueryException + +func (p *GetTraceTimelinesByIdsResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTraceTimelinesByIdsResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTraceTimelinesByIdsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTraceTimelinesByIdsResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTraceTimelinesByIdsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceTimelinesByIdsResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*TraceTimeline, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + _elem60 := &TraceTimeline{} + if err := _elem60.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem60, err) + } + p.Success = append(p.Success, _elem60) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceTimelinesByIdsResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTraceTimelinesByIdsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceTimelinesByIds_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceTimelinesByIdsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTraceTimelinesByIdsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTraceTimelinesByIdsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceTimelinesByIdsResult(%+v)", *p) +} + +type GetTraceSummariesByIdsArgs struct { + TraceIds []int64 `thrift:"trace_ids,1" json:"trace_ids"` + Adjust []Adjust `thrift:"adjust,2" json:"adjust"` +} + +func NewGetTraceSummariesByIdsArgs() *GetTraceSummariesByIdsArgs { + return &GetTraceSummariesByIdsArgs{} +} + +func (p *GetTraceSummariesByIdsArgs) GetTraceIds() []int64 { + return p.TraceIds +} + +func (p *GetTraceSummariesByIdsArgs) GetAdjust() []Adjust { + return p.Adjust +} +func (p *GetTraceSummariesByIdsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceSummariesByIdsArgs) ReadField1(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.TraceIds = tSlice + for i := 0; i < size; i++ { + var _elem61 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem61 = v + } + p.TraceIds = append(p.TraceIds, _elem61) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceSummariesByIdsArgs) ReadField2(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]Adjust, 0, size) + p.Adjust = tSlice + for i := 0; i < size; i++ { + var _elem62 Adjust + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + temp := Adjust(v) + _elem62 = temp + } + p.Adjust = append(p.Adjust, _elem62) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceSummariesByIdsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceSummariesByIds_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceSummariesByIdsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_ids", thrift.LIST, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_ids: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.TraceIds)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.TraceIds { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_ids: %s", p, err) + } + return err +} + +func (p *GetTraceSummariesByIdsArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("adjust", thrift.LIST, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:adjust: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I32, len(p.Adjust)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Adjust { + if err := oprot.WriteI32(int32(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:adjust: %s", p, err) + } + return err +} + +func (p *GetTraceSummariesByIdsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceSummariesByIdsArgs(%+v)", *p) +} + +type GetTraceSummariesByIdsResult struct { + Success []*TraceSummary `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTraceSummariesByIdsResult() *GetTraceSummariesByIdsResult { + return &GetTraceSummariesByIdsResult{} +} + +var GetTraceSummariesByIdsResult_Success_DEFAULT []*TraceSummary + +func (p *GetTraceSummariesByIdsResult) GetSuccess() []*TraceSummary { + return p.Success +} + +var GetTraceSummariesByIdsResult_Qe_DEFAULT *QueryException + +func (p *GetTraceSummariesByIdsResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTraceSummariesByIdsResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTraceSummariesByIdsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTraceSummariesByIdsResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTraceSummariesByIdsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceSummariesByIdsResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*TraceSummary, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + _elem63 := &TraceSummary{} + if err := _elem63.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem63, err) + } + p.Success = append(p.Success, _elem63) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceSummariesByIdsResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTraceSummariesByIdsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceSummariesByIds_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceSummariesByIdsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTraceSummariesByIdsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTraceSummariesByIdsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceSummariesByIdsResult(%+v)", *p) +} + +type GetTraceCombosByIdsArgs struct { + TraceIds []int64 `thrift:"trace_ids,1" json:"trace_ids"` + Adjust []Adjust `thrift:"adjust,2" json:"adjust"` +} + +func NewGetTraceCombosByIdsArgs() *GetTraceCombosByIdsArgs { + return &GetTraceCombosByIdsArgs{} +} + +func (p *GetTraceCombosByIdsArgs) GetTraceIds() []int64 { + return p.TraceIds +} + +func (p *GetTraceCombosByIdsArgs) GetAdjust() []Adjust { + return p.Adjust +} +func (p *GetTraceCombosByIdsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceCombosByIdsArgs) ReadField1(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + p.TraceIds = tSlice + for i := 0; i < size; i++ { + var _elem64 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem64 = v + } + p.TraceIds = append(p.TraceIds, _elem64) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceCombosByIdsArgs) ReadField2(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]Adjust, 0, size) + p.Adjust = tSlice + for i := 0; i < size; i++ { + var _elem65 Adjust + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + temp := Adjust(v) + _elem65 = temp + } + p.Adjust = append(p.Adjust, _elem65) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceCombosByIdsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceCombosByIds_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceCombosByIdsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_ids", thrift.LIST, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_ids: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(p.TraceIds)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.TraceIds { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_ids: %s", p, err) + } + return err +} + +func (p *GetTraceCombosByIdsArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("adjust", thrift.LIST, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:adjust: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I32, len(p.Adjust)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Adjust { + if err := oprot.WriteI32(int32(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:adjust: %s", p, err) + } + return err +} + +func (p *GetTraceCombosByIdsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceCombosByIdsArgs(%+v)", *p) +} + +type GetTraceCombosByIdsResult struct { + Success []*TraceCombo `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTraceCombosByIdsResult() *GetTraceCombosByIdsResult { + return &GetTraceCombosByIdsResult{} +} + +var GetTraceCombosByIdsResult_Success_DEFAULT []*TraceCombo + +func (p *GetTraceCombosByIdsResult) GetSuccess() []*TraceCombo { + return p.Success +} + +var GetTraceCombosByIdsResult_Qe_DEFAULT *QueryException + +func (p *GetTraceCombosByIdsResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTraceCombosByIdsResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTraceCombosByIdsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTraceCombosByIdsResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTraceCombosByIdsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceCombosByIdsResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]*TraceCombo, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + _elem66 := &TraceCombo{} + if err := _elem66.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", _elem66, err) + } + p.Success = append(p.Success, _elem66) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTraceCombosByIdsResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTraceCombosByIdsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceCombosByIds_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceCombosByIdsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := v.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", v, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTraceCombosByIdsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTraceCombosByIdsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceCombosByIdsResult(%+v)", *p) +} + +type GetServiceNamesArgs struct { +} + +func NewGetServiceNamesArgs() *GetServiceNamesArgs { + return &GetServiceNamesArgs{} +} + +func (p *GetServiceNamesArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetServiceNamesArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getServiceNames_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetServiceNamesArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetServiceNamesArgs(%+v)", *p) +} + +type GetServiceNamesResult struct { + Success map[string]bool `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetServiceNamesResult() *GetServiceNamesResult { + return &GetServiceNamesResult{} +} + +var GetServiceNamesResult_Success_DEFAULT map[string]bool + +func (p *GetServiceNamesResult) GetSuccess() map[string]bool { + return p.Success +} + +var GetServiceNamesResult_Qe_DEFAULT *QueryException + +func (p *GetServiceNamesResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetServiceNamesResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetServiceNamesResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetServiceNamesResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetServiceNamesResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetServiceNamesResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadSetBegin() + if err != nil { + return fmt.Errorf("error reading set begin: %s", err) + } + tSet := make(map[string]bool, size) + p.Success = tSet + for i := 0; i < size; i++ { + var _elem67 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem67 = v + } + p.Success[_elem67] = true + } + if err := iprot.ReadSetEnd(); err != nil { + return fmt.Errorf("error reading set end: %s", err) + } + return nil +} + +func (p *GetServiceNamesResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetServiceNamesResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getServiceNames_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetServiceNamesResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.SET, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteSetBegin(thrift.STRING, len(p.Success)); err != nil { + return fmt.Errorf("error writing set begin: %s", err) + } + for v, _ := range p.Success { + if err := oprot.WriteString(string(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteSetEnd(); err != nil { + return fmt.Errorf("error writing set end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetServiceNamesResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetServiceNamesResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetServiceNamesResult(%+v)", *p) +} + +type GetSpanNamesArgs struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` +} + +func NewGetSpanNamesArgs() *GetSpanNamesArgs { + return &GetSpanNamesArgs{} +} + +func (p *GetSpanNamesArgs) GetServiceName() string { + return p.ServiceName +} +func (p *GetSpanNamesArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetSpanNamesArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *GetSpanNamesArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getSpanNames_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetSpanNamesArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *GetSpanNamesArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetSpanNamesArgs(%+v)", *p) +} + +type GetSpanNamesResult struct { + Success map[string]bool `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetSpanNamesResult() *GetSpanNamesResult { + return &GetSpanNamesResult{} +} + +var GetSpanNamesResult_Success_DEFAULT map[string]bool + +func (p *GetSpanNamesResult) GetSuccess() map[string]bool { + return p.Success +} + +var GetSpanNamesResult_Qe_DEFAULT *QueryException + +func (p *GetSpanNamesResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetSpanNamesResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetSpanNamesResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetSpanNamesResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetSpanNamesResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetSpanNamesResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadSetBegin() + if err != nil { + return fmt.Errorf("error reading set begin: %s", err) + } + tSet := make(map[string]bool, size) + p.Success = tSet + for i := 0; i < size; i++ { + var _elem68 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem68 = v + } + p.Success[_elem68] = true + } + if err := iprot.ReadSetEnd(); err != nil { + return fmt.Errorf("error reading set end: %s", err) + } + return nil +} + +func (p *GetSpanNamesResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetSpanNamesResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getSpanNames_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetSpanNamesResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.SET, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteSetBegin(thrift.STRING, len(p.Success)); err != nil { + return fmt.Errorf("error writing set begin: %s", err) + } + for v, _ := range p.Success { + if err := oprot.WriteString(string(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteSetEnd(); err != nil { + return fmt.Errorf("error writing set end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetSpanNamesResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetSpanNamesResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetSpanNamesResult(%+v)", *p) +} + +type SetTraceTimeToLiveArgs struct { + TraceId int64 `thrift:"trace_id,1" json:"trace_id"` + TtlSeconds int32 `thrift:"ttl_seconds,2" json:"ttl_seconds"` +} + +func NewSetTraceTimeToLiveArgs() *SetTraceTimeToLiveArgs { + return &SetTraceTimeToLiveArgs{} +} + +func (p *SetTraceTimeToLiveArgs) GetTraceId() int64 { + return p.TraceId +} + +func (p *SetTraceTimeToLiveArgs) GetTtlSeconds() int32 { + return p.TtlSeconds +} +func (p *SetTraceTimeToLiveArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *SetTraceTimeToLiveArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.TraceId = v + } + return nil +} + +func (p *SetTraceTimeToLiveArgs) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.TtlSeconds = v + } + return nil +} + +func (p *SetTraceTimeToLiveArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("setTraceTimeToLive_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *SetTraceTimeToLiveArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_id", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_id: %s", p, err) + } + if err := oprot.WriteI64(int64(p.TraceId)); err != nil { + return fmt.Errorf("%T.trace_id (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_id: %s", p, err) + } + return err +} + +func (p *SetTraceTimeToLiveArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("ttl_seconds", thrift.I32, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:ttl_seconds: %s", p, err) + } + if err := oprot.WriteI32(int32(p.TtlSeconds)); err != nil { + return fmt.Errorf("%T.ttl_seconds (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:ttl_seconds: %s", p, err) + } + return err +} + +func (p *SetTraceTimeToLiveArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("SetTraceTimeToLiveArgs(%+v)", *p) +} + +type SetTraceTimeToLiveResult struct { + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewSetTraceTimeToLiveResult() *SetTraceTimeToLiveResult { + return &SetTraceTimeToLiveResult{} +} + +var SetTraceTimeToLiveResult_Qe_DEFAULT *QueryException + +func (p *SetTraceTimeToLiveResult) GetQe() *QueryException { + if !p.IsSetQe() { + return SetTraceTimeToLiveResult_Qe_DEFAULT + } + return p.Qe +} +func (p *SetTraceTimeToLiveResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *SetTraceTimeToLiveResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *SetTraceTimeToLiveResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *SetTraceTimeToLiveResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("setTraceTimeToLive_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *SetTraceTimeToLiveResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *SetTraceTimeToLiveResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("SetTraceTimeToLiveResult(%+v)", *p) +} + +type GetTraceTimeToLiveArgs struct { + TraceId int64 `thrift:"trace_id,1" json:"trace_id"` +} + +func NewGetTraceTimeToLiveArgs() *GetTraceTimeToLiveArgs { + return &GetTraceTimeToLiveArgs{} +} + +func (p *GetTraceTimeToLiveArgs) GetTraceId() int64 { + return p.TraceId +} +func (p *GetTraceTimeToLiveArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceTimeToLiveArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.TraceId = v + } + return nil +} + +func (p *GetTraceTimeToLiveArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceTimeToLive_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceTimeToLiveArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("trace_id", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:trace_id: %s", p, err) + } + if err := oprot.WriteI64(int64(p.TraceId)); err != nil { + return fmt.Errorf("%T.trace_id (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:trace_id: %s", p, err) + } + return err +} + +func (p *GetTraceTimeToLiveArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceTimeToLiveArgs(%+v)", *p) +} + +type GetTraceTimeToLiveResult struct { + Success *int32 `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTraceTimeToLiveResult() *GetTraceTimeToLiveResult { + return &GetTraceTimeToLiveResult{} +} + +var GetTraceTimeToLiveResult_Success_DEFAULT int32 + +func (p *GetTraceTimeToLiveResult) GetSuccess() int32 { + if !p.IsSetSuccess() { + return GetTraceTimeToLiveResult_Success_DEFAULT + } + return *p.Success +} + +var GetTraceTimeToLiveResult_Qe_DEFAULT *QueryException + +func (p *GetTraceTimeToLiveResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTraceTimeToLiveResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTraceTimeToLiveResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTraceTimeToLiveResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTraceTimeToLiveResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTraceTimeToLiveResult) ReadField0(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + p.Success = &v + } + return nil +} + +func (p *GetTraceTimeToLiveResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTraceTimeToLiveResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTraceTimeToLive_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTraceTimeToLiveResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.I32, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteI32(int32(*p.Success)); err != nil { + return fmt.Errorf("%T.success (0) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTraceTimeToLiveResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTraceTimeToLiveResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTraceTimeToLiveResult(%+v)", *p) +} + +type GetDataTimeToLiveArgs struct { +} + +func NewGetDataTimeToLiveArgs() *GetDataTimeToLiveArgs { + return &GetDataTimeToLiveArgs{} +} + +func (p *GetDataTimeToLiveArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetDataTimeToLiveArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getDataTimeToLive_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetDataTimeToLiveArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetDataTimeToLiveArgs(%+v)", *p) +} + +type GetDataTimeToLiveResult struct { + Success *int32 `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetDataTimeToLiveResult() *GetDataTimeToLiveResult { + return &GetDataTimeToLiveResult{} +} + +var GetDataTimeToLiveResult_Success_DEFAULT int32 + +func (p *GetDataTimeToLiveResult) GetSuccess() int32 { + if !p.IsSetSuccess() { + return GetDataTimeToLiveResult_Success_DEFAULT + } + return *p.Success +} + +var GetDataTimeToLiveResult_Qe_DEFAULT *QueryException + +func (p *GetDataTimeToLiveResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetDataTimeToLiveResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetDataTimeToLiveResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetDataTimeToLiveResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetDataTimeToLiveResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetDataTimeToLiveResult) ReadField0(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + p.Success = &v + } + return nil +} + +func (p *GetDataTimeToLiveResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetDataTimeToLiveResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getDataTimeToLive_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetDataTimeToLiveResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.I32, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteI32(int32(*p.Success)); err != nil { + return fmt.Errorf("%T.success (0) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetDataTimeToLiveResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetDataTimeToLiveResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetDataTimeToLiveResult(%+v)", *p) +} + +type GetDependenciesArgs struct { + StartTime int64 `thrift:"start_time,1" json:"start_time"` + EndTime int64 `thrift:"end_time,2" json:"end_time"` +} + +func NewGetDependenciesArgs() *GetDependenciesArgs { + return &GetDependenciesArgs{} +} + +func (p *GetDependenciesArgs) GetStartTime() int64 { + return p.StartTime +} + +func (p *GetDependenciesArgs) GetEndTime() int64 { + return p.EndTime +} +func (p *GetDependenciesArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetDependenciesArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.StartTime = v + } + return nil +} + +func (p *GetDependenciesArgs) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.EndTime = v + } + return nil +} + +func (p *GetDependenciesArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getDependencies_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetDependenciesArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("start_time", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:start_time: %s", p, err) + } + if err := oprot.WriteI64(int64(p.StartTime)); err != nil { + return fmt.Errorf("%T.start_time (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:start_time: %s", p, err) + } + return err +} + +func (p *GetDependenciesArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("end_time", thrift.I64, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:end_time: %s", p, err) + } + if err := oprot.WriteI64(int64(p.EndTime)); err != nil { + return fmt.Errorf("%T.end_time (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:end_time: %s", p, err) + } + return err +} + +func (p *GetDependenciesArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetDependenciesArgs(%+v)", *p) +} + +type GetDependenciesResult struct { + Success *zipkindependencies.Dependencies `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetDependenciesResult() *GetDependenciesResult { + return &GetDependenciesResult{} +} + +var GetDependenciesResult_Success_DEFAULT *zipkindependencies.Dependencies + +func (p *GetDependenciesResult) GetSuccess() *zipkindependencies.Dependencies { + if !p.IsSetSuccess() { + return GetDependenciesResult_Success_DEFAULT + } + return p.Success +} + +var GetDependenciesResult_Qe_DEFAULT *QueryException + +func (p *GetDependenciesResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetDependenciesResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetDependenciesResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetDependenciesResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetDependenciesResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetDependenciesResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = &zipkindependencies.Dependencies{} + if err := p.Success.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Success, err) + } + return nil +} + +func (p *GetDependenciesResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetDependenciesResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getDependencies_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetDependenciesResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := p.Success.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Success, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetDependenciesResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetDependenciesResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetDependenciesResult(%+v)", *p) +} + +type GetTopAnnotationsArgs struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` +} + +func NewGetTopAnnotationsArgs() *GetTopAnnotationsArgs { + return &GetTopAnnotationsArgs{} +} + +func (p *GetTopAnnotationsArgs) GetServiceName() string { + return p.ServiceName +} +func (p *GetTopAnnotationsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTopAnnotationsArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *GetTopAnnotationsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTopAnnotations_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTopAnnotationsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *GetTopAnnotationsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTopAnnotationsArgs(%+v)", *p) +} + +type GetTopAnnotationsResult struct { + Success []string `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTopAnnotationsResult() *GetTopAnnotationsResult { + return &GetTopAnnotationsResult{} +} + +var GetTopAnnotationsResult_Success_DEFAULT []string + +func (p *GetTopAnnotationsResult) GetSuccess() []string { + return p.Success +} + +var GetTopAnnotationsResult_Qe_DEFAULT *QueryException + +func (p *GetTopAnnotationsResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTopAnnotationsResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTopAnnotationsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTopAnnotationsResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTopAnnotationsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTopAnnotationsResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]string, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + var _elem69 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem69 = v + } + p.Success = append(p.Success, _elem69) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTopAnnotationsResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTopAnnotationsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTopAnnotations_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTopAnnotationsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRING, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := oprot.WriteString(string(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTopAnnotationsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTopAnnotationsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTopAnnotationsResult(%+v)", *p) +} + +type GetTopKeyValueAnnotationsArgs struct { + ServiceName string `thrift:"service_name,1" json:"service_name"` +} + +func NewGetTopKeyValueAnnotationsArgs() *GetTopKeyValueAnnotationsArgs { + return &GetTopKeyValueAnnotationsArgs{} +} + +func (p *GetTopKeyValueAnnotationsArgs) GetServiceName() string { + return p.ServiceName +} +func (p *GetTopKeyValueAnnotationsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTopKeyValueAnnotationsArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *GetTopKeyValueAnnotationsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTopKeyValueAnnotations_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTopKeyValueAnnotationsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:service_name: %s", p, err) + } + return err +} + +func (p *GetTopKeyValueAnnotationsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTopKeyValueAnnotationsArgs(%+v)", *p) +} + +type GetTopKeyValueAnnotationsResult struct { + Success []string `thrift:"success,0" json:"success"` + Qe *QueryException `thrift:"qe,1" json:"qe"` +} + +func NewGetTopKeyValueAnnotationsResult() *GetTopKeyValueAnnotationsResult { + return &GetTopKeyValueAnnotationsResult{} +} + +var GetTopKeyValueAnnotationsResult_Success_DEFAULT []string + +func (p *GetTopKeyValueAnnotationsResult) GetSuccess() []string { + return p.Success +} + +var GetTopKeyValueAnnotationsResult_Qe_DEFAULT *QueryException + +func (p *GetTopKeyValueAnnotationsResult) GetQe() *QueryException { + if !p.IsSetQe() { + return GetTopKeyValueAnnotationsResult_Qe_DEFAULT + } + return p.Qe +} +func (p *GetTopKeyValueAnnotationsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetTopKeyValueAnnotationsResult) IsSetQe() bool { + return p.Qe != nil +} + +func (p *GetTopKeyValueAnnotationsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetTopKeyValueAnnotationsResult) ReadField0(iprot thrift.TProtocol) error { + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]string, 0, size) + p.Success = tSlice + for i := 0; i < size; i++ { + var _elem70 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem70 = v + } + p.Success = append(p.Success, _elem70) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + return nil +} + +func (p *GetTopKeyValueAnnotationsResult) ReadField1(iprot thrift.TProtocol) error { + p.Qe = &QueryException{} + if err := p.Qe.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Qe, err) + } + return nil +} + +func (p *GetTopKeyValueAnnotationsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getTopKeyValueAnnotations_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetTopKeyValueAnnotationsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.LIST, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.STRING, len(p.Success)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range p.Success { + if err := oprot.WriteString(string(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetTopKeyValueAnnotationsResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetQe() { + if err := oprot.WriteFieldBegin("qe", thrift.STRUCT, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:qe: %s", p, err) + } + if err := p.Qe.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Qe, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:qe: %s", p, err) + } + } + return err +} + +func (p *GetTopKeyValueAnnotationsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetTopKeyValueAnnotationsResult(%+v)", *p) +} + +type GetSpanDurationsArgs struct { + TimeStamp int64 `thrift:"time_stamp,1" json:"time_stamp"` + ServiceName string `thrift:"service_name,2" json:"service_name"` + RpcName string `thrift:"rpc_name,3" json:"rpc_name"` +} + +func NewGetSpanDurationsArgs() *GetSpanDurationsArgs { + return &GetSpanDurationsArgs{} +} + +func (p *GetSpanDurationsArgs) GetTimeStamp() int64 { + return p.TimeStamp +} + +func (p *GetSpanDurationsArgs) GetServiceName() string { + return p.ServiceName +} + +func (p *GetSpanDurationsArgs) GetRpcName() string { + return p.RpcName +} +func (p *GetSpanDurationsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetSpanDurationsArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.TimeStamp = v + } + return nil +} + +func (p *GetSpanDurationsArgs) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *GetSpanDurationsArgs) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.RpcName = v + } + return nil +} + +func (p *GetSpanDurationsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getSpanDurations_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetSpanDurationsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("time_stamp", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:time_stamp: %s", p, err) + } + if err := oprot.WriteI64(int64(p.TimeStamp)); err != nil { + return fmt.Errorf("%T.time_stamp (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:time_stamp: %s", p, err) + } + return err +} + +func (p *GetSpanDurationsArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:service_name: %s", p, err) + } + return err +} + +func (p *GetSpanDurationsArgs) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("rpc_name", thrift.STRING, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:rpc_name: %s", p, err) + } + if err := oprot.WriteString(string(p.RpcName)); err != nil { + return fmt.Errorf("%T.rpc_name (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:rpc_name: %s", p, err) + } + return err +} + +func (p *GetSpanDurationsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetSpanDurationsArgs(%+v)", *p) +} + +type GetSpanDurationsResult struct { + Success map[string][]int64 `thrift:"success,0" json:"success"` +} + +func NewGetSpanDurationsResult() *GetSpanDurationsResult { + return &GetSpanDurationsResult{} +} + +var GetSpanDurationsResult_Success_DEFAULT map[string][]int64 + +func (p *GetSpanDurationsResult) GetSuccess() map[string][]int64 { + return p.Success +} +func (p *GetSpanDurationsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetSpanDurationsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetSpanDurationsResult) ReadField0(iprot thrift.TProtocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return fmt.Errorf("error reading map begin: %s", err) + } + tMap := make(map[string][]int64, size) + p.Success = tMap + for i := 0; i < size; i++ { + var _key71 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _key71 = v + } + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + _val72 := tSlice + for i := 0; i < size; i++ { + var _elem73 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem73 = v + } + _val72 = append(_val72, _elem73) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + p.Success[_key71] = _val72 + } + if err := iprot.ReadMapEnd(); err != nil { + return fmt.Errorf("error reading map end: %s", err) + } + return nil +} + +func (p *GetSpanDurationsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getSpanDurations_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetSpanDurationsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.MAP, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteMapBegin(thrift.STRING, thrift.LIST, len(p.Success)); err != nil { + return fmt.Errorf("error writing map begin: %s", err) + } + for k, v := range p.Success { + if err := oprot.WriteString(string(k)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(v)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range v { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + } + if err := oprot.WriteMapEnd(); err != nil { + return fmt.Errorf("error writing map end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetSpanDurationsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetSpanDurationsResult(%+v)", *p) +} + +type GetServiceNamesToTraceIdsArgs struct { + TimeStamp int64 `thrift:"time_stamp,1" json:"time_stamp"` + ServiceName string `thrift:"service_name,2" json:"service_name"` + RpcName string `thrift:"rpc_name,3" json:"rpc_name"` +} + +func NewGetServiceNamesToTraceIdsArgs() *GetServiceNamesToTraceIdsArgs { + return &GetServiceNamesToTraceIdsArgs{} +} + +func (p *GetServiceNamesToTraceIdsArgs) GetTimeStamp() int64 { + return p.TimeStamp +} + +func (p *GetServiceNamesToTraceIdsArgs) GetServiceName() string { + return p.ServiceName +} + +func (p *GetServiceNamesToTraceIdsArgs) GetRpcName() string { + return p.RpcName +} +func (p *GetServiceNamesToTraceIdsArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + case 3: + if err := p.ReadField3(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetServiceNamesToTraceIdsArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.TimeStamp = v + } + return nil +} + +func (p *GetServiceNamesToTraceIdsArgs) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.ServiceName = v + } + return nil +} + +func (p *GetServiceNamesToTraceIdsArgs) ReadField3(iprot thrift.TProtocol) error { + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 3: %s", err) + } else { + p.RpcName = v + } + return nil +} + +func (p *GetServiceNamesToTraceIdsArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getServiceNamesToTraceIds_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := p.writeField3(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetServiceNamesToTraceIdsArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("time_stamp", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:time_stamp: %s", p, err) + } + if err := oprot.WriteI64(int64(p.TimeStamp)); err != nil { + return fmt.Errorf("%T.time_stamp (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:time_stamp: %s", p, err) + } + return err +} + +func (p *GetServiceNamesToTraceIdsArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("service_name", thrift.STRING, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:service_name: %s", p, err) + } + if err := oprot.WriteString(string(p.ServiceName)); err != nil { + return fmt.Errorf("%T.service_name (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:service_name: %s", p, err) + } + return err +} + +func (p *GetServiceNamesToTraceIdsArgs) writeField3(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("rpc_name", thrift.STRING, 3); err != nil { + return fmt.Errorf("%T write field begin error 3:rpc_name: %s", p, err) + } + if err := oprot.WriteString(string(p.RpcName)); err != nil { + return fmt.Errorf("%T.rpc_name (3) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 3:rpc_name: %s", p, err) + } + return err +} + +func (p *GetServiceNamesToTraceIdsArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetServiceNamesToTraceIdsArgs(%+v)", *p) +} + +type GetServiceNamesToTraceIdsResult struct { + Success map[string][]int64 `thrift:"success,0" json:"success"` +} + +func NewGetServiceNamesToTraceIdsResult() *GetServiceNamesToTraceIdsResult { + return &GetServiceNamesToTraceIdsResult{} +} + +var GetServiceNamesToTraceIdsResult_Success_DEFAULT map[string][]int64 + +func (p *GetServiceNamesToTraceIdsResult) GetSuccess() map[string][]int64 { + return p.Success +} +func (p *GetServiceNamesToTraceIdsResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *GetServiceNamesToTraceIdsResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *GetServiceNamesToTraceIdsResult) ReadField0(iprot thrift.TProtocol) error { + _, _, size, err := iprot.ReadMapBegin() + if err != nil { + return fmt.Errorf("error reading map begin: %s", err) + } + tMap := make(map[string][]int64, size) + p.Success = tMap + for i := 0; i < size; i++ { + var _key74 string + if v, err := iprot.ReadString(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _key74 = v + } + _, size, err := iprot.ReadListBegin() + if err != nil { + return fmt.Errorf("error reading list begin: %s", err) + } + tSlice := make([]int64, 0, size) + _val75 := tSlice + for i := 0; i < size; i++ { + var _elem76 int64 + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 0: %s", err) + } else { + _elem76 = v + } + _val75 = append(_val75, _elem76) + } + if err := iprot.ReadListEnd(); err != nil { + return fmt.Errorf("error reading list end: %s", err) + } + p.Success[_key74] = _val75 + } + if err := iprot.ReadMapEnd(); err != nil { + return fmt.Errorf("error reading map end: %s", err) + } + return nil +} + +func (p *GetServiceNamesToTraceIdsResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("getServiceNamesToTraceIds_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *GetServiceNamesToTraceIdsResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.MAP, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := oprot.WriteMapBegin(thrift.STRING, thrift.LIST, len(p.Success)); err != nil { + return fmt.Errorf("error writing map begin: %s", err) + } + for k, v := range p.Success { + if err := oprot.WriteString(string(k)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + if err := oprot.WriteListBegin(thrift.I64, len(v)); err != nil { + return fmt.Errorf("error writing list begin: %s", err) + } + for _, v := range v { + if err := oprot.WriteI64(int64(v)); err != nil { + return fmt.Errorf("%T. (0) field write error: %s", p, err) + } + } + if err := oprot.WriteListEnd(); err != nil { + return fmt.Errorf("error writing list end: %s", err) + } + } + if err := oprot.WriteMapEnd(); err != nil { + return fmt.Errorf("error writing map end: %s", err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *GetServiceNamesToTraceIdsResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("GetServiceNamesToTraceIdsResult(%+v)", *p) +} diff --git a/tracing/zipkin/thrift/scribe.thrift b/tracing/zipkin/thrift/scribe.thrift new file mode 100644 index 000000000..12e21ce1e --- /dev/null +++ b/tracing/zipkin/thrift/scribe.thrift @@ -0,0 +1,32 @@ +# Copyright 2012 Twitter Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +namespace java com.twitter.zipkin.thriftjava +#@namespace scala com.twitter.zipkin.thriftscala + +enum ResultCode +{ + OK, + TRY_LATER +} + +struct LogEntry +{ + 1: string category, + 2: string message +} + +service Scribe +{ + ResultCode Log(1: list messages); +} diff --git a/tracing/zipkin/thrift/zipkinCollector.thrift b/tracing/zipkin/thrift/zipkinCollector.thrift new file mode 100644 index 000000000..aba6d9da1 --- /dev/null +++ b/tracing/zipkin/thrift/zipkinCollector.thrift @@ -0,0 +1,35 @@ +# Copyright 2012 Twitter Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +namespace java com.twitter.zipkin.thriftjava +#@namespace scala com.twitter.zipkin.thriftscala +namespace rb Zipkin + +include "scribe.thrift" +include "zipkinDependencies.thrift" + +exception AdjustableRateException { + 1: string msg +} + +exception StoreAggregatesException { + 1: string msg +} + +service ZipkinCollector extends scribe.Scribe { + + /** Aggregates methods */ + void storeTopAnnotations(1: string service_name, 2: list annotations) throws (1: StoreAggregatesException e); + void storeTopKeyValueAnnotations(1: string service_name, 2: list annotations) throws (1: StoreAggregatesException e); + void storeDependencies(1: zipkinDependencies.Dependencies dependencies) throws (1: StoreAggregatesException e); +} diff --git a/tracing/zipkin/thrift/zipkinCore.thrift b/tracing/zipkin/thrift/zipkinCore.thrift new file mode 100644 index 000000000..50ea914f0 --- /dev/null +++ b/tracing/zipkin/thrift/zipkinCore.thrift @@ -0,0 +1,59 @@ +# Copyright 2012 Twitter Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +namespace java com.twitter.zipkin.thriftjava +#@namespace scala com.twitter.zipkin.thriftscala +namespace rb Zipkin + +#************** Collection related structs ************** + +# these are the annotations we always expect to find in a span +const string CLIENT_SEND = "cs" +const string CLIENT_RECV = "cr" +const string SERVER_SEND = "ss" +const string SERVER_RECV = "sr" + +# this represents a host and port in a network +struct Endpoint { + 1: i32 ipv4, + 2: i16 port # beware that this will give us negative ports. some conversion needed + 3: string service_name # which service did this operation happen on? +} + +# some event took place, either one by the framework or by the user +struct Annotation { + 1: i64 timestamp # microseconds from epoch + 2: string value # what happened at the timestamp? + 3: optional Endpoint host # host this happened on + 4: optional i32 duration # how long did the operation take? microseconds +} + +enum AnnotationType { BOOL, BYTES, I16, I32, I64, DOUBLE, STRING } + +struct BinaryAnnotation { + 1: string key, + 2: binary value, + 3: AnnotationType annotation_type, + 4: optional Endpoint host +} + +struct Span { + 1: i64 trace_id # unique trace id, use for all spans in trace + 3: string name, # span name, rpc method for example + 4: i64 id, # unique span id, only used for this span + 5: optional i64 parent_id, # parent span id + 6: list annotations, # list of all annotations/events that occured + 8: list binary_annotations # any binary annotations + 9: optional bool debug = 0 # if true, we DEMAND that this span passes all samplers +} + diff --git a/tracing/zipkin/thrift/zipkinDependencies.thrift b/tracing/zipkin/thrift/zipkinDependencies.thrift new file mode 100644 index 000000000..b12cdda54 --- /dev/null +++ b/tracing/zipkin/thrift/zipkinDependencies.thrift @@ -0,0 +1,43 @@ +# Copyright 2013 Twitter Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +namespace java com.twitter.zipkin.thriftjava +#@namespace scala com.twitter.zipkin.thriftscala +namespace rb Zipkin + +#********* Zipkin Aggregate Dependency Related Structs *********** + + +# This is a 1-to-1 translation of algebird Moments structure for holding +# count/mean/variance(stdDev)/skewness/etc about a set of values. It's +# used below to represent span time duration ranges. +struct Moments { + 1: i64 m0, # count + 2: double m1, # mean + 3: double m2, # variance * count + 4: double m3, + 5: double m4 +} + +struct DependencyLink { + 1: string parent, # parent service name (caller) + 2: string child, # child service name (callee) + 3: Moments duration_moments + # histogram? +} + +struct Dependencies { + 1: i64 start_time # microseconds from epoch + 2: i64 end_time # microseconds from epoch + 3: list links # our data +} diff --git a/tracing/zipkin/thrift/zipkinQuery.thrift b/tracing/zipkin/thrift/zipkinQuery.thrift new file mode 100644 index 000000000..13ede1594 --- /dev/null +++ b/tracing/zipkin/thrift/zipkinQuery.thrift @@ -0,0 +1,252 @@ +# Copyright 2012 Twitter Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +namespace java com.twitter.zipkin.thriftjava +#@namespace scala com.twitter.zipkin.thriftscala +namespace rb Zipkin + +include "zipkinCore.thrift" +include "zipkinDependencies.thrift" + +struct Trace { + 1: list spans +} + +exception QueryException { + 1: string msg +} + +struct SpanTimestamp { + 1: string name + 2: i64 start_timestamp + 3: i64 end_timestamp +} + +/** + * This sums up a single Trace to make it easy for a client to get an overview of what happened. + */ +struct TraceSummary { + 1: i64 trace_id # the trace + 2: i64 start_timestamp # start timestamp of the trace, in microseconds + 3: i64 end_timestamp # end timestamp of the trace, in microseconds + 4: i32 duration_micro # how long did the entire trace take? in microseconds + # 5: map service_counts # which services were involved? + 6: list endpoints # which endpoints were involved? + 7: list span_timestamps +} + +/** + * A modified version of the Annotation struct that brings in more information + */ +struct TimelineAnnotation { + 1: i64 timestamp # microseconds from epoch + 2: string value # what happened at the timestamp? + 3: zipkinCore.Endpoint host # host this happened on + 4: i64 span_id # which span does this annotation belong to? + 5: optional i64 parent_id # parent span id + 6: string service_name # which service did this annotation happen on? + 7: string span_name # span name, rpc method for example +} + +/** + * This sums up a single Trace to make it easy for a client to get an overview of what happened. + */ +struct TraceTimeline { + 1: i64 trace_id # the trace + 2: i64 root_most_span_id # either the true root span or the closest we can find + 6: list annotations # annotations as they happened + 7: list binary_annotations # all the binary annotations +} + +/** + * Returns a combination of trace, summary and timeline. + */ +struct TraceCombo { + 1: Trace trace + 2: optional TraceSummary summary # not set if no spans in trace + 3: optional TraceTimeline timeline # not set if no spans in trace + 4: optional map span_depths # not set if no spans in trace +} + +enum Order { TIMESTAMP_DESC, TIMESTAMP_ASC, DURATION_ASC, DURATION_DESC, NONE } + +/** + * The raw data in our storage might have various problems. How should we adjust it before + * returning it to the user? + * + * Time skew adjuster tries to make sure that even though servers might have slightly + * different clocks the annotations in the returned data are adjusted so that they are + * in the correct order. + */ +enum Adjust { NOTHING, TIME_SKEW } + +struct QueryRequest { + 1: string service_name + 2: optional string span_name + 3: optional list annotations + 4: optional list binary_annotations + 5: i64 end_ts + 6: i32 limit + 7: Order order +} + +struct QueryResponse { + 1: list trace_ids + 2: i64 start_ts + 3: i64 end_ts +} + +service ZipkinQuery { + + #************** Index lookups ************** + + QueryResponse getTraceIds(1: QueryRequest request) throws (1: QueryException qe); + + /** + * Fetch trace ids by service and span name. + * Gets "limit" number of entries from before the "end_ts". + * + * Span name is optional. + * Timestamps are in microseconds. + */ + list getTraceIdsBySpanName(1: string service_name, 2: string span_name, + 4: i64 end_ts, 5: i32 limit, 6: Order order) throws (1: QueryException qe); + + /** + * Fetch trace ids by service name. + * Gets "limit" number of entries from before the "end_ts". + * + * Timestamps are in microseconds. + */ + list getTraceIdsByServiceName(1: string service_name, + 3: i64 end_ts, 4: i32 limit, 5: Order order) throws (1: QueryException qe); + + /** + * Fetch trace ids with a particular annotation. + * Gets "limit" number of entries from before the "end_ts". + * + * When requesting based on time based annotations only pass in the first parameter, "annotation" and leave out + * the second "value". If looking for a key-value binary annotation provide both, "annotation" is then the + * key in the key-value. + * + * Timestamps are in microseconds. + */ + list getTraceIdsByAnnotation(1: string service_name, 2: string annotation, 3: binary value, + 5: i64 end_ts, 6: i32 limit, 7: Order order) throws (1: QueryException qe); + + + #************** Fetch traces from id ************** + + /** + * Get the traces that are in the database from the given list of trace ids. + */ + + set tracesExist(1: list trace_ids) throws (1: QueryException qe); + + /** + * Get the full traces associated with the given trace ids. + * + * Second argument is a list of methods of adjusting the trace + * data before returning it. Can be empty. + */ + list getTracesByIds(1: list trace_ids, 2: list adjust) throws (1: QueryException qe); + + /** + * Get the trace timelines associated with the given trace ids. + * This is a convenience method for users that just want to know + * the annotations and the (assumed) order they happened in. + * + * Second argument is a list of methods of adjusting the trace + * data before returning it. Can be empty. + * + * Note that if one of the trace ids does not have any data associated with it, it will not be + * represented in the output list. + */ + list getTraceTimelinesByIds(1: list trace_ids, 2: list adjust) throws (1: QueryException qe); + + /** + * Fetch trace summaries for the given trace ids. + * + * Second argument is a list of methods of adjusting the trace + * data before returning it. Can be empty. + * + * Note that if one of the trace ids does not have any data associated with it, it will not be + * represented in the output list. + */ + list getTraceSummariesByIds(1: list trace_ids, 2: list adjust) throws (1: QueryException qe); + + /** + * Not content with just one of traces, summaries or timelines? Want it all? This is the method for you. + */ + list getTraceCombosByIds(1: list trace_ids, 2: list adjust) throws (1: QueryException qe); + + #************** Misc metadata ************** + + /** + * Fetch all the service names we have seen from now all the way back to the set ttl. + */ + set getServiceNames() throws (1: QueryException qe); + + /** + * Get all the seen span names for a particular service, from now back until the set ttl. + */ + set getSpanNames(1: string service_name) throws (1: QueryException qe); + + #************** TTL related ************** + + /** + * Change the TTL of a trace. If we find an interesting trace we want to keep around for further + * investigation. + */ + void setTraceTimeToLive(1: i64 trace_id, 2: i32 ttl_seconds) throws (1: QueryException qe); + + /** + * Get the TTL in seconds of a specific trace. + */ + i32 getTraceTimeToLive(1: i64 trace_id) throws (1: QueryException qe); + + /** + * Get the data ttl. This is the number of seconds we keep the data around before deleting it. + */ + i32 getDataTimeToLive() throws (1: QueryException qe); + + /** + * Get an aggregate representation of all services paired with every service they call in to. + * This includes information on call counts and mean/stdDev/etc of call durations. The two arguments + * specify epoch time in microseconds. The end time is optional and defaults to one day after the + * start time. + */ + zipkinDependencies.Dependencies getDependencies(1: optional i64 start_time, 2: optional i64 end_time) throws (1: QueryException qe); + + list getTopAnnotations(1: string service_name) throws (1: QueryException qe); + list getTopKeyValueAnnotations(1: string service_name) throws (1: QueryException qe); + + /** + * Given a time stamp, server service name, and rpc name, fetch all of the client services calling in paired + * with the lists of every span duration (list) from the server to client. The lists of span durations + * include information on call counts and mean/stdDev/etc of call durations. + * + * The three arguments specify epoch time in microseconds, server side service name and rpc name. The return maps + * contains the key - client_service_name and value - list. + */ + map> getSpanDurations(1: i64 time_stamp, 2: string service_name, 3: string rpc_name); + + /** + * Given a time stamp, server service name, and rpc name, fetch all of the client services calling in paired + * with the lists of every trace Ids (list) from the server to client. + * + * The three arguments specify epoch time in microseconds, server side service name and rpc name. The return maps + * contains the key - client_service_name and value - list. + */ + map> getServiceNamesToTraceIds(1: i64 time_stamp, 2: string service_name, 3: string rpc_name); +} From 4c839649578b7e27b8779c7a8ed74ff188af16f6 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 17 Apr 2015 17:26:21 +0200 Subject: [PATCH 25/38] zipkin: fix Scribe collector - Proper batch semantics - Fix race conditions Unfortunately Thrift socket servers apparently cannot be cleanly introspected or shut down due to their API design. Therefore the scribe server we build for unit tests must just be abandoned at the end... --- tracing/zipkin/collector.go | 120 +++++++++++-------- tracing/zipkin/collector_test.go | 193 ++++++++++++------------------- 2 files changed, 143 insertions(+), 170 deletions(-) diff --git a/tracing/zipkin/collector.go b/tracing/zipkin/collector.go index 05ac01d31..da1fc2350 100644 --- a/tracing/zipkin/collector.go +++ b/tracing/zipkin/collector.go @@ -20,13 +20,21 @@ type Collector interface { } // ScribeCollector implements Collector by forwarding spans to a Scribe -// service in batches. +// service, in batches. type ScribeCollector struct { - spanc chan spanTuple + client scribe.Scribe + factory func() (scribe.Scribe, error) + spanc chan *Span + sendc chan struct{} + quitc chan chan struct{} + batch []*scribe.LogEntry + nextSend time.Time + batchInterval time.Duration + batchSize int } // NewScribeCollector returns a new Scribe-backed Collector, ready for use. -func NewScribeCollector(addr string, timeout time.Duration, batchSize int, batchTime time.Duration) (Collector, error) { +func NewScribeCollector(addr string, timeout time.Duration, batchSize int, batchInterval time.Duration) (Collector, error) { factory := func() (scribe.Scribe, error) { return newScribeClient(addr, timeout) } @@ -35,65 +43,79 @@ func NewScribeCollector(addr string, timeout time.Duration, batchSize int, batch return nil, err } c := &ScribeCollector{ - spanc: make(chan spanTuple), + client: client, + factory: factory, + spanc: make(chan *Span), + sendc: make(chan struct{}), + quitc: make(chan chan struct{}), + batch: []*scribe.LogEntry{}, + nextSend: time.Now().Add(batchInterval), + batchInterval: batchInterval, + batchSize: batchSize, } - go c.loop(client, factory, batchSize, batchTime) + go c.loop() return c, nil } // Collect implements Collector. func (c *ScribeCollector) Collect(s *Span) error { - e := make(chan error) - c.spanc <- spanTuple{s, e} - return <-e + c.spanc <- s + return nil // accepted } -func (c *ScribeCollector) loop(client scribe.Scribe, factory func() (scribe.Scribe, error), batchSize int, batchTime time.Duration) { - batch := make([]*scribe.LogEntry, 0, batchSize) - nextPublish := time.Now().Add(batchTime) - publish := func() error { - if client == nil { - var err error - if client, err = factory(); err != nil { - return fmt.Errorf("during reconnect: %v", err) +func (c *ScribeCollector) loop() { + ticker := time.NewTicker(c.batchInterval / 10) + defer ticker.Stop() + + for { + select { + case span := <-c.spanc: + c.batch = append(c.batch, &scribe.LogEntry{ + Category: "zipkin", // TODO parameterize? + Message: serialize(span), + }) + if len(c.batch) >= c.batchSize { + go c.sendNow() } - } - if rc, err := client.Log(batch); err != nil { - client = nil - return fmt.Errorf("during Log: %v", err) - } else if rc != scribe.ResultCode_OK { - // probably transient error; don't reset client - return fmt.Errorf("remote returned %s", rc) - } - batch = batch[:0] - return nil - } - for t := range c.spanc { - message, err := encode(t.Span) - if err != nil { - t.errc <- err - continue - } + case <-ticker.C: + if time.Now().After(c.nextSend) { + go c.sendNow() + } - batch = append(batch, &scribe.LogEntry{ - Category: "zipkin", // TODO parmeterize? - Message: message, - }) + case <-c.sendc: + c.nextSend = time.Now().Add(c.batchInterval) + if err := c.send(c.batch); err != nil { + continue + } + c.batch = c.batch[:0] - if len(batch) >= batchSize || time.Now().After(nextPublish) { - t.errc <- publish() - nextPublish = time.Now().Add(batchTime) - continue + case q := <-c.quitc: + close(q) + return } - - t.errc <- nil } } -type spanTuple struct { - *Span - errc chan error +func (c *ScribeCollector) sendNow() { + c.sendc <- struct{}{} +} + +func (c *ScribeCollector) send(batch []*scribe.LogEntry) error { + if c.client == nil { + var err error + if c.client, err = c.factory(); err != nil { + return fmt.Errorf("during reconnect: %v", err) + } + } + if rc, err := c.client.Log(c.batch); err != nil { + c.client = nil + return fmt.Errorf("during Log: %v", err) + } else if rc != scribe.ResultCode_OK { + // probably transient error; don't reset client + return fmt.Errorf("remote returned %s", rc) + } + return nil } func newScribeClient(addr string, timeout time.Duration) (scribe.Scribe, error) { @@ -112,13 +134,13 @@ func newScribeClient(addr string, timeout time.Duration) (scribe.Scribe, error) return client, nil } -func encode(s *Span) (string, error) { +func serialize(s *Span) string { t := thrift.NewTMemoryBuffer() p := thrift.NewTBinaryProtocolTransport(t) if err := s.Encode().Write(p); err != nil { - return "", err + panic(err) } - return base64.StdEncoding.EncodeToString(t.Buffer.Bytes()), nil + return base64.StdEncoding.EncodeToString(t.Buffer.Bytes()) } // NopCollector implements Collector but performs no work. diff --git a/tracing/zipkin/collector_test.go b/tracing/zipkin/collector_test.go index ec71af561..f7e0d9e46 100644 --- a/tracing/zipkin/collector_test.go +++ b/tracing/zipkin/collector_test.go @@ -2,6 +2,8 @@ package zipkin_test import ( "encoding/base64" + "fmt" + "math/rand" "sync" "testing" "time" @@ -15,10 +17,11 @@ import ( ) func TestScribeCollector(t *testing.T) { - s := newScribeServer(t) - defer s.close() + server := newScribeServer(t) - c, err := zipkin.NewScribeCollector(s.addr(), 100*time.Millisecond, 0, 10*time.Millisecond) + timeout := time.Second + batchInterval := time.Millisecond + c, err := zipkin.NewScribeCollector(server.addr(), timeout, 0, batchInterval) if err != nil { t.Fatal(err) } @@ -38,11 +41,23 @@ func TestScribeCollector(t *testing.T) { t.Errorf("error during submit: %v", err) } - if want, have := 1, len(s.spans()); want != have { - t.Fatalf("want %d, have %d", want, have) + // Need to yield to the select loop to accept the send request, and then + // yield again to the send operation to write to the socket. I think the + // best way to do that is just give it some time. + + deadline := time.Now().Add(1 * time.Second) + for { + if time.Now().After(deadline) { + t.Fatalf("never received a span") + } + if want, have := 1, len(server.spans()); want != have { + time.Sleep(time.Millisecond) + continue + } + break } - gotSpan := s.spans()[0] + gotSpan := server.spans()[0] if want, have := name, gotSpan.GetName(); want != have { t.Errorf("want %q, have %q", want, have) } @@ -75,17 +90,29 @@ type scribeServer struct { address string server *thrift.TSimpleServer handler *scribeHandler - wg sync.WaitGroup } func newScribeServer(t *testing.T) *scribeServer { protocolFactory := thrift.NewTBinaryProtocolFactoryDefault() transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()) - transport, err := thrift.NewTServerSocket(":0") + + var port int + var transport *thrift.TServerSocket + var err error + for i := 0; i < 10; i++ { + port = 10000 + rand.Intn(10000) + transport, err = thrift.NewTServerSocket(fmt.Sprintf(":%d", port)) + if err != nil { + t.Logf("port %d: %v", port, err) + continue + } + break + } if err != nil { t.Fatal(err) } - handler := &scribeHandler{} + + handler := newScribeHandler(t) server := thrift.NewTSimpleServer4( scribe.NewScribeProcessor(handler), transport, @@ -93,25 +120,14 @@ func newScribeServer(t *testing.T) *scribeServer { protocolFactory, ) - s := &scribeServer{t: t} - s.wg.Add(1) - go func() { defer s.wg.Done(); server.Serve() }() - tickc := time.Tick(10 * time.Millisecond) - donec := time.After(1 * time.Second) - for !transport.IsListening() { - select { - case <-tickc: - continue - case <-donec: - t.Fatal("server never started listening") - } - } + go server.Serve() + time.Sleep(time.Second) - s.transport = transport - s.address = transport.Addr().String() - s.server = server - s.handler = handler - return s + return &scribeServer{ + transport: transport, + address: fmt.Sprintf("127.0.0.1:%d", port), + handler: handler, + } } func (s *scribeServer) addr() string { @@ -119,115 +135,50 @@ func (s *scribeServer) addr() string { } func (s *scribeServer) spans() []*zipkincore.Span { + return s.handler.spans() +} + +type scribeHandler struct { + t *testing.T + sync.RWMutex + entries []*scribe.LogEntry +} + +func newScribeHandler(t *testing.T) *scribeHandler { + return &scribeHandler{t: t} +} + +func (h *scribeHandler) Log(messages []*scribe.LogEntry) (scribe.ResultCode, error) { + h.Lock() + defer h.Unlock() + for _, m := range messages { + h.entries = append(h.entries, m) + } + return scribe.ResultCode_OK, nil +} + +func (h *scribeHandler) spans() []*zipkincore.Span { + h.RLock() + defer h.RUnlock() spans := []*zipkincore.Span{} - for _, m := range *s.handler { + for _, m := range h.entries { decoded, err := base64.StdEncoding.DecodeString(m.GetMessage()) if err != nil { - s.t.Error(err) + h.t.Error(err) continue } buffer := thrift.NewTMemoryBuffer() if _, err := buffer.Write(decoded); err != nil { - s.t.Error(err) + h.t.Error(err) continue } transport := thrift.NewTBinaryProtocolTransport(buffer) zs := &zipkincore.Span{} if err := zs.Read(transport); err != nil { - s.t.Error(err) + h.t.Error(err) continue } spans = append(spans, zs) } return spans } - -func (s *scribeServer) reset() { - s.handler.reset() -} - -func (s *scribeServer) close() { - s.transport.Close() - s.server.Stop() - s.wg.Wait() -} - -type scribeHandler []*scribe.LogEntry - -func (h *scribeHandler) Log(messages []*scribe.LogEntry) (scribe.ResultCode, error) { - for _, m := range messages { - (*h) = append(*h, m) - } - return scribe.ResultCode_OK, nil -} - -func (h *scribeHandler) reset() { - (*h) = (*h)[:0] -} - -/* -type server struct { - t *testing.T - wg sync.WaitGroup - listener net.Listener - - mu sync.Mutex - buffer bytes.Buffer -} - -func newServer(t *testing.T) *server { - listener, err := net.Listen("tcp", ":0") - if err != nil { - t.Fatal(err) - } - - wg := sync.WaitGroup{} - wg.Add(1) - - s := &server{ - t: t, - wg: wg, - listener: listener, - buffer: bytes.Buffer{}, - } - go s.loop() - return s -} - -func (s *server) loop() { - defer s.wg.Done() - for { - conn, err := s.listener.Accept() - s.t.Logf("Accept %v %v", conn.LocalAddr(), conn.RemoteAddr()) - if err != nil { - s.t.Log(err) // closing the listener triggers an error - return - } - buf := make([]byte, 8192) - for { - n, err := conn.Read(buf) - if err != nil { - s.t.Log(err) // also OK - break - } - s.buffer.Write(buf[:n]) - } - s.t.Logf("done") - } -} - -func (s *server) addr() string { - return s.listener.Addr().String() -} - -func (s *server) buf() []byte { - s.mu.Lock() - defer s.mu.Unlock() - return s.buffer.Bytes() // better not mutate! -} - -func (s *server) close() { - s.listener.Close() - //s.wg.Wait() -} -*/ From fb1a4e49962cab638668d700b8e5f6f04d558809 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 17 Apr 2015 17:33:11 +0200 Subject: [PATCH 26/38] zipkin: thrift to _thrift The Thrift compiler produces broken import statements in its generated files, so to keep `go [build,test,...] ./...` working, we apply a temporary hack. --- tracing/zipkin/{thrift => _thrift}/compile.sh | 0 .../zipkin/{thrift => _thrift}/gen-go/scribe/constants.go | 0 .../gen-go/scribe/scribe-remote/scribe-remote.go | 0 tracing/zipkin/{thrift => _thrift}/gen-go/scribe/scribe.go | 0 tracing/zipkin/{thrift => _thrift}/gen-go/scribe/ttypes.go | 0 .../{thrift => _thrift}/gen-go/zipkincollector/constants.go | 0 .../{thrift => _thrift}/gen-go/zipkincollector/ttypes.go | 0 .../zipkin_collector-remote/zipkin_collector-remote.go | 0 .../gen-go/zipkincollector/zipkincollector.go | 0 .../{thrift => _thrift}/gen-go/zipkincore/constants.go | 0 .../zipkin/{thrift => _thrift}/gen-go/zipkincore/ttypes.go | 0 .../gen-go/zipkindependencies/constants.go | 0 .../{thrift => _thrift}/gen-go/zipkindependencies/ttypes.go | 0 .../{thrift => _thrift}/gen-go/zipkinquery/constants.go | 0 .../zipkin/{thrift => _thrift}/gen-go/zipkinquery/ttypes.go | 0 .../zipkinquery/zipkin_query-remote/zipkin_query-remote.go | 0 .../{thrift => _thrift}/gen-go/zipkinquery/zipkinquery.go | 0 tracing/zipkin/{thrift => _thrift}/scribe.thrift | 0 tracing/zipkin/{thrift => _thrift}/zipkinCollector.thrift | 0 tracing/zipkin/{thrift => _thrift}/zipkinCore.thrift | 0 tracing/zipkin/{thrift => _thrift}/zipkinDependencies.thrift | 0 tracing/zipkin/{thrift => _thrift}/zipkinQuery.thrift | 0 tracing/zipkin/collector.go | 2 +- tracing/zipkin/collector_test.go | 5 ++--- tracing/zipkin/span.go | 2 +- 25 files changed, 4 insertions(+), 5 deletions(-) rename tracing/zipkin/{thrift => _thrift}/compile.sh (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/scribe/constants.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/scribe/scribe-remote/scribe-remote.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/scribe/scribe.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/scribe/ttypes.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkincollector/constants.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkincollector/ttypes.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkincollector/zipkincollector.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkincore/constants.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkincore/ttypes.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkindependencies/constants.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkindependencies/ttypes.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkinquery/constants.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkinquery/ttypes.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go (100%) rename tracing/zipkin/{thrift => _thrift}/gen-go/zipkinquery/zipkinquery.go (100%) rename tracing/zipkin/{thrift => _thrift}/scribe.thrift (100%) rename tracing/zipkin/{thrift => _thrift}/zipkinCollector.thrift (100%) rename tracing/zipkin/{thrift => _thrift}/zipkinCore.thrift (100%) rename tracing/zipkin/{thrift => _thrift}/zipkinDependencies.thrift (100%) rename tracing/zipkin/{thrift => _thrift}/zipkinQuery.thrift (100%) diff --git a/tracing/zipkin/thrift/compile.sh b/tracing/zipkin/_thrift/compile.sh similarity index 100% rename from tracing/zipkin/thrift/compile.sh rename to tracing/zipkin/_thrift/compile.sh diff --git a/tracing/zipkin/thrift/gen-go/scribe/constants.go b/tracing/zipkin/_thrift/gen-go/scribe/constants.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/scribe/constants.go rename to tracing/zipkin/_thrift/gen-go/scribe/constants.go diff --git a/tracing/zipkin/thrift/gen-go/scribe/scribe-remote/scribe-remote.go b/tracing/zipkin/_thrift/gen-go/scribe/scribe-remote/scribe-remote.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/scribe/scribe-remote/scribe-remote.go rename to tracing/zipkin/_thrift/gen-go/scribe/scribe-remote/scribe-remote.go diff --git a/tracing/zipkin/thrift/gen-go/scribe/scribe.go b/tracing/zipkin/_thrift/gen-go/scribe/scribe.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/scribe/scribe.go rename to tracing/zipkin/_thrift/gen-go/scribe/scribe.go diff --git a/tracing/zipkin/thrift/gen-go/scribe/ttypes.go b/tracing/zipkin/_thrift/gen-go/scribe/ttypes.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/scribe/ttypes.go rename to tracing/zipkin/_thrift/gen-go/scribe/ttypes.go diff --git a/tracing/zipkin/thrift/gen-go/zipkincollector/constants.go b/tracing/zipkin/_thrift/gen-go/zipkincollector/constants.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkincollector/constants.go rename to tracing/zipkin/_thrift/gen-go/zipkincollector/constants.go diff --git a/tracing/zipkin/thrift/gen-go/zipkincollector/ttypes.go b/tracing/zipkin/_thrift/gen-go/zipkincollector/ttypes.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkincollector/ttypes.go rename to tracing/zipkin/_thrift/gen-go/zipkincollector/ttypes.go diff --git a/tracing/zipkin/thrift/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go b/tracing/zipkin/_thrift/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go rename to tracing/zipkin/_thrift/gen-go/zipkincollector/zipkin_collector-remote/zipkin_collector-remote.go diff --git a/tracing/zipkin/thrift/gen-go/zipkincollector/zipkincollector.go b/tracing/zipkin/_thrift/gen-go/zipkincollector/zipkincollector.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkincollector/zipkincollector.go rename to tracing/zipkin/_thrift/gen-go/zipkincollector/zipkincollector.go diff --git a/tracing/zipkin/thrift/gen-go/zipkincore/constants.go b/tracing/zipkin/_thrift/gen-go/zipkincore/constants.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkincore/constants.go rename to tracing/zipkin/_thrift/gen-go/zipkincore/constants.go diff --git a/tracing/zipkin/thrift/gen-go/zipkincore/ttypes.go b/tracing/zipkin/_thrift/gen-go/zipkincore/ttypes.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkincore/ttypes.go rename to tracing/zipkin/_thrift/gen-go/zipkincore/ttypes.go diff --git a/tracing/zipkin/thrift/gen-go/zipkindependencies/constants.go b/tracing/zipkin/_thrift/gen-go/zipkindependencies/constants.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkindependencies/constants.go rename to tracing/zipkin/_thrift/gen-go/zipkindependencies/constants.go diff --git a/tracing/zipkin/thrift/gen-go/zipkindependencies/ttypes.go b/tracing/zipkin/_thrift/gen-go/zipkindependencies/ttypes.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkindependencies/ttypes.go rename to tracing/zipkin/_thrift/gen-go/zipkindependencies/ttypes.go diff --git a/tracing/zipkin/thrift/gen-go/zipkinquery/constants.go b/tracing/zipkin/_thrift/gen-go/zipkinquery/constants.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkinquery/constants.go rename to tracing/zipkin/_thrift/gen-go/zipkinquery/constants.go diff --git a/tracing/zipkin/thrift/gen-go/zipkinquery/ttypes.go b/tracing/zipkin/_thrift/gen-go/zipkinquery/ttypes.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkinquery/ttypes.go rename to tracing/zipkin/_thrift/gen-go/zipkinquery/ttypes.go diff --git a/tracing/zipkin/thrift/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go b/tracing/zipkin/_thrift/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go rename to tracing/zipkin/_thrift/gen-go/zipkinquery/zipkin_query-remote/zipkin_query-remote.go diff --git a/tracing/zipkin/thrift/gen-go/zipkinquery/zipkinquery.go b/tracing/zipkin/_thrift/gen-go/zipkinquery/zipkinquery.go similarity index 100% rename from tracing/zipkin/thrift/gen-go/zipkinquery/zipkinquery.go rename to tracing/zipkin/_thrift/gen-go/zipkinquery/zipkinquery.go diff --git a/tracing/zipkin/thrift/scribe.thrift b/tracing/zipkin/_thrift/scribe.thrift similarity index 100% rename from tracing/zipkin/thrift/scribe.thrift rename to tracing/zipkin/_thrift/scribe.thrift diff --git a/tracing/zipkin/thrift/zipkinCollector.thrift b/tracing/zipkin/_thrift/zipkinCollector.thrift similarity index 100% rename from tracing/zipkin/thrift/zipkinCollector.thrift rename to tracing/zipkin/_thrift/zipkinCollector.thrift diff --git a/tracing/zipkin/thrift/zipkinCore.thrift b/tracing/zipkin/_thrift/zipkinCore.thrift similarity index 100% rename from tracing/zipkin/thrift/zipkinCore.thrift rename to tracing/zipkin/_thrift/zipkinCore.thrift diff --git a/tracing/zipkin/thrift/zipkinDependencies.thrift b/tracing/zipkin/_thrift/zipkinDependencies.thrift similarity index 100% rename from tracing/zipkin/thrift/zipkinDependencies.thrift rename to tracing/zipkin/_thrift/zipkinDependencies.thrift diff --git a/tracing/zipkin/thrift/zipkinQuery.thrift b/tracing/zipkin/_thrift/zipkinQuery.thrift similarity index 100% rename from tracing/zipkin/thrift/zipkinQuery.thrift rename to tracing/zipkin/_thrift/zipkinQuery.thrift diff --git a/tracing/zipkin/collector.go b/tracing/zipkin/collector.go index da1fc2350..6c6637058 100644 --- a/tracing/zipkin/collector.go +++ b/tracing/zipkin/collector.go @@ -10,7 +10,7 @@ import ( "github.com/apache/thrift/lib/go/thrift" - "github.com/peterbourgon/gokit/tracing/zipkin/thrift/gen-go/scribe" + "github.com/peterbourgon/gokit/tracing/zipkin/_thrift/gen-go/scribe" ) // Collector represents a Zipkin trace collector, which is probably a set of diff --git a/tracing/zipkin/collector_test.go b/tracing/zipkin/collector_test.go index f7e0d9e46..2832f09ae 100644 --- a/tracing/zipkin/collector_test.go +++ b/tracing/zipkin/collector_test.go @@ -8,12 +8,11 @@ import ( "testing" "time" - "github.com/peterbourgon/gokit/tracing/zipkin/thrift/gen-go/zipkincore" - "github.com/apache/thrift/lib/go/thrift" "github.com/peterbourgon/gokit/tracing/zipkin" - "github.com/peterbourgon/gokit/tracing/zipkin/thrift/gen-go/scribe" + "github.com/peterbourgon/gokit/tracing/zipkin/_thrift/gen-go/scribe" + "github.com/peterbourgon/gokit/tracing/zipkin/_thrift/gen-go/zipkincore" ) func TestScribeCollector(t *testing.T) { diff --git a/tracing/zipkin/span.go b/tracing/zipkin/span.go index cee5d253b..f19bc7999 100644 --- a/tracing/zipkin/span.go +++ b/tracing/zipkin/span.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/peterbourgon/gokit/tracing/zipkin/thrift/gen-go/zipkincore" + "github.com/peterbourgon/gokit/tracing/zipkin/_thrift/gen-go/zipkincore" ) var ( From e72a454ebe84249b01052b09dc0a30eff14d6b55 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 17 Apr 2015 17:49:49 +0200 Subject: [PATCH 27/38] addsvc: re-add Thrift binding --- addsvc/{thrift => _thrift}/add.thrift | 0 addsvc/{thrift => _thrift}/compile.sh | 0 .../add_service-remote/add_service-remote.go | 144 ++++++ addsvc/_thrift/gen-go/add/addservice.go | 433 ++++++++++++++++++ addsvc/_thrift/gen-go/add/constants.go | 18 + addsvc/_thrift/gen-go/add/ttypes.go | 105 +++++ addsvc/main.go | 62 ++- addsvc/thrift_binding.go | 51 +++ 8 files changed, 811 insertions(+), 2 deletions(-) rename addsvc/{thrift => _thrift}/add.thrift (100%) rename addsvc/{thrift => _thrift}/compile.sh (100%) create mode 100755 addsvc/_thrift/gen-go/add/add_service-remote/add_service-remote.go create mode 100644 addsvc/_thrift/gen-go/add/addservice.go create mode 100644 addsvc/_thrift/gen-go/add/constants.go create mode 100644 addsvc/_thrift/gen-go/add/ttypes.go create mode 100644 addsvc/thrift_binding.go diff --git a/addsvc/thrift/add.thrift b/addsvc/_thrift/add.thrift similarity index 100% rename from addsvc/thrift/add.thrift rename to addsvc/_thrift/add.thrift diff --git a/addsvc/thrift/compile.sh b/addsvc/_thrift/compile.sh similarity index 100% rename from addsvc/thrift/compile.sh rename to addsvc/_thrift/compile.sh diff --git a/addsvc/_thrift/gen-go/add/add_service-remote/add_service-remote.go b/addsvc/_thrift/gen-go/add/add_service-remote/add_service-remote.go new file mode 100755 index 000000000..f350da6b8 --- /dev/null +++ b/addsvc/_thrift/gen-go/add/add_service-remote/add_service-remote.go @@ -0,0 +1,144 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package main + +import ( + "add" + "flag" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "math" + "net" + "net/url" + "os" + "strconv" + "strings" +) + +func Usage() { + fmt.Fprintln(os.Stderr, "Usage of ", os.Args[0], " [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]:") + flag.PrintDefaults() + fmt.Fprintln(os.Stderr, "\nFunctions:") + fmt.Fprintln(os.Stderr, " AddReply Add(i64 a, i64 b)") + fmt.Fprintln(os.Stderr) + os.Exit(0) +} + +func main() { + flag.Usage = Usage + var host string + var port int + var protocol string + var urlString string + var framed bool + var useHttp bool + var parsedUrl url.URL + var trans thrift.TTransport + _ = strconv.Atoi + _ = math.Abs + flag.Usage = Usage + flag.StringVar(&host, "h", "localhost", "Specify host and port") + flag.IntVar(&port, "p", 9090, "Specify port") + flag.StringVar(&protocol, "P", "binary", "Specify the protocol (binary, compact, simplejson, json)") + flag.StringVar(&urlString, "u", "", "Specify the url") + flag.BoolVar(&framed, "framed", false, "Use framed transport") + flag.BoolVar(&useHttp, "http", false, "Use http") + flag.Parse() + + if len(urlString) > 0 { + parsedUrl, err := url.Parse(urlString) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + host = parsedUrl.Host + useHttp = len(parsedUrl.Scheme) <= 0 || parsedUrl.Scheme == "http" + } else if useHttp { + _, err := url.Parse(fmt.Sprint("http://", host, ":", port)) + if err != nil { + fmt.Fprintln(os.Stderr, "Error parsing URL: ", err) + flag.Usage() + } + } + + cmd := flag.Arg(0) + var err error + if useHttp { + trans, err = thrift.NewTHttpClient(parsedUrl.String()) + } else { + portStr := fmt.Sprint(port) + if strings.Contains(host, ":") { + host, portStr, err = net.SplitHostPort(host) + if err != nil { + fmt.Fprintln(os.Stderr, "error with host:", err) + os.Exit(1) + } + } + trans, err = thrift.NewTSocket(net.JoinHostPort(host, portStr)) + if err != nil { + fmt.Fprintln(os.Stderr, "error resolving address:", err) + os.Exit(1) + } + if framed { + trans = thrift.NewTFramedTransport(trans) + } + } + if err != nil { + fmt.Fprintln(os.Stderr, "Error creating transport", err) + os.Exit(1) + } + defer trans.Close() + var protocolFactory thrift.TProtocolFactory + switch protocol { + case "compact": + protocolFactory = thrift.NewTCompactProtocolFactory() + break + case "simplejson": + protocolFactory = thrift.NewTSimpleJSONProtocolFactory() + break + case "json": + protocolFactory = thrift.NewTJSONProtocolFactory() + break + case "binary", "": + protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() + break + default: + fmt.Fprintln(os.Stderr, "Invalid protocol specified: ", protocol) + Usage() + os.Exit(1) + } + client := add.NewAddServiceClientFactory(trans, protocolFactory) + if err := trans.Open(); err != nil { + fmt.Fprintln(os.Stderr, "Error opening socket to ", host, ":", port, " ", err) + os.Exit(1) + } + + switch cmd { + case "Add": + if flag.NArg()-1 != 2 { + fmt.Fprintln(os.Stderr, "Add requires 2 args") + flag.Usage() + } + argvalue0, err4 := (strconv.ParseInt(flag.Arg(1), 10, 64)) + if err4 != nil { + Usage() + return + } + value0 := argvalue0 + argvalue1, err5 := (strconv.ParseInt(flag.Arg(2), 10, 64)) + if err5 != nil { + Usage() + return + } + value1 := argvalue1 + fmt.Print(client.Add(value0, value1)) + fmt.Print("\n") + break + case "": + Usage() + break + default: + fmt.Fprintln(os.Stderr, "Invalid function ", cmd) + } +} diff --git a/addsvc/_thrift/gen-go/add/addservice.go b/addsvc/_thrift/gen-go/add/addservice.go new file mode 100644 index 000000000..8ab56a506 --- /dev/null +++ b/addsvc/_thrift/gen-go/add/addservice.go @@ -0,0 +1,433 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package add + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +type AddService interface { + // Parameters: + // - A + // - B + Add(a int64, b int64) (r *AddReply, err error) +} + +type AddServiceClient struct { + Transport thrift.TTransport + ProtocolFactory thrift.TProtocolFactory + InputProtocol thrift.TProtocol + OutputProtocol thrift.TProtocol + SeqId int32 +} + +func NewAddServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *AddServiceClient { + return &AddServiceClient{Transport: t, + ProtocolFactory: f, + InputProtocol: f.GetProtocol(t), + OutputProtocol: f.GetProtocol(t), + SeqId: 0, + } +} + +func NewAddServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *AddServiceClient { + return &AddServiceClient{Transport: t, + ProtocolFactory: nil, + InputProtocol: iprot, + OutputProtocol: oprot, + SeqId: 0, + } +} + +// Parameters: +// - A +// - B +func (p *AddServiceClient) Add(a int64, b int64) (r *AddReply, err error) { + if err = p.sendAdd(a, b); err != nil { + return + } + return p.recvAdd() +} + +func (p *AddServiceClient) sendAdd(a int64, b int64) (err error) { + oprot := p.OutputProtocol + if oprot == nil { + oprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.OutputProtocol = oprot + } + p.SeqId++ + if err = oprot.WriteMessageBegin("Add", thrift.CALL, p.SeqId); err != nil { + return + } + args := AddArgs{ + A: a, + B: b, + } + if err = args.Write(oprot); err != nil { + return + } + if err = oprot.WriteMessageEnd(); err != nil { + return + } + return oprot.Flush() +} + +func (p *AddServiceClient) recvAdd() (value *AddReply, err error) { + iprot := p.InputProtocol + if iprot == nil { + iprot = p.ProtocolFactory.GetProtocol(p.Transport) + p.InputProtocol = iprot + } + _, mTypeId, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return + } + if mTypeId == thrift.EXCEPTION { + error0 := thrift.NewTApplicationException(thrift.UNKNOWN_APPLICATION_EXCEPTION, "Unknown Exception") + var error1 error + error1, err = error0.Read(iprot) + if err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + err = error1 + return + } + if p.SeqId != seqId { + err = thrift.NewTApplicationException(thrift.BAD_SEQUENCE_ID, "Add failed: out of sequence response") + return + } + result := AddResult{} + if err = result.Read(iprot); err != nil { + return + } + if err = iprot.ReadMessageEnd(); err != nil { + return + } + value = result.GetSuccess() + return +} + +type AddServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler AddService +} + +func (p *AddServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *AddServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *AddServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewAddServiceProcessor(handler AddService) *AddServiceProcessor { + + self2 := &AddServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self2.processorMap["Add"] = &addServiceProcessorAdd{handler: handler} + return self2 +} + +func (p *AddServiceProcessor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x3 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x3.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, x3 + +} + +type addServiceProcessorAdd struct { + handler AddService +} + +func (p *addServiceProcessorAdd) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := AddArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("Add", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return false, err + } + + iprot.ReadMessageEnd() + result := AddResult{} + var retval *AddReply + var err2 error + if retval, err2 = p.handler.Add(args.A, args.B); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Add: "+err2.Error()) + oprot.WriteMessageBegin("Add", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("Add", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +// HELPER FUNCTIONS AND STRUCTURES + +type AddArgs struct { + A int64 `thrift:"a,1" json:"a"` + B int64 `thrift:"b,2" json:"b"` +} + +func NewAddArgs() *AddArgs { + return &AddArgs{} +} + +func (p *AddArgs) GetA() int64 { + return p.A +} + +func (p *AddArgs) GetB() int64 { + return p.B +} +func (p *AddArgs) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *AddArgs) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.A = v + } + return nil +} + +func (p *AddArgs) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 2: %s", err) + } else { + p.B = v + } + return nil +} + +func (p *AddArgs) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Add_args"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *AddArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("a", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:a: %s", p, err) + } + if err := oprot.WriteI64(int64(p.A)); err != nil { + return fmt.Errorf("%T.a (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:a: %s", p, err) + } + return err +} + +func (p *AddArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("b", thrift.I64, 2); err != nil { + return fmt.Errorf("%T write field begin error 2:b: %s", p, err) + } + if err := oprot.WriteI64(int64(p.B)); err != nil { + return fmt.Errorf("%T.b (2) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 2:b: %s", p, err) + } + return err +} + +func (p *AddArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AddArgs(%+v)", *p) +} + +type AddResult struct { + Success *AddReply `thrift:"success,0" json:"success"` +} + +func NewAddResult() *AddResult { + return &AddResult{} +} + +var AddResult_Success_DEFAULT *AddReply + +func (p *AddResult) GetSuccess() *AddReply { + if !p.IsSetSuccess() { + return AddResult_Success_DEFAULT + } + return p.Success +} +func (p *AddResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *AddResult) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if err := p.ReadField0(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *AddResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = &AddReply{} + if err := p.Success.Read(iprot); err != nil { + return fmt.Errorf("%T error reading struct: %s", p.Success, err) + } + return nil +} + +func (p *AddResult) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("Add_result"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField0(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *AddResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err := oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + return fmt.Errorf("%T write field begin error 0:success: %s", p, err) + } + if err := p.Success.Write(oprot); err != nil { + return fmt.Errorf("%T error writing struct: %s", p.Success, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 0:success: %s", p, err) + } + } + return err +} + +func (p *AddResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AddResult(%+v)", *p) +} diff --git a/addsvc/_thrift/gen-go/add/constants.go b/addsvc/_thrift/gen-go/add/constants.go new file mode 100644 index 000000000..0b745ba54 --- /dev/null +++ b/addsvc/_thrift/gen-go/add/constants.go @@ -0,0 +1,18 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package add + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +func init() { +} diff --git a/addsvc/_thrift/gen-go/add/ttypes.go b/addsvc/_thrift/gen-go/add/ttypes.go new file mode 100644 index 000000000..23adcef87 --- /dev/null +++ b/addsvc/_thrift/gen-go/add/ttypes.go @@ -0,0 +1,105 @@ +// Autogenerated by Thrift Compiler (0.9.2) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package add + +import ( + "bytes" + "fmt" + "github.com/apache/thrift/lib/go/thrift" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal + +var GoUnusedProtection__ int + +type AddReply struct { + Value int64 `thrift:"value,1" json:"value"` +} + +func NewAddReply() *AddReply { + return &AddReply{} +} + +func (p *AddReply) GetValue() int64 { + return p.Value +} +func (p *AddReply) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return fmt.Errorf("%T read error: %s", p, err) + } + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return fmt.Errorf("%T field %d read error: %s", p, fieldId, err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return fmt.Errorf("%T read struct end error: %s", p, err) + } + return nil +} + +func (p *AddReply) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI64(); err != nil { + return fmt.Errorf("error reading field 1: %s", err) + } else { + p.Value = v + } + return nil +} + +func (p *AddReply) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("AddReply"); err != nil { + return fmt.Errorf("%T write struct begin error: %s", p, err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return fmt.Errorf("write field stop error: %s", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return fmt.Errorf("write struct stop error: %s", err) + } + return nil +} + +func (p *AddReply) writeField1(oprot thrift.TProtocol) (err error) { + if err := oprot.WriteFieldBegin("value", thrift.I64, 1); err != nil { + return fmt.Errorf("%T write field begin error 1:value: %s", p, err) + } + if err := oprot.WriteI64(int64(p.Value)); err != nil { + return fmt.Errorf("%T.value (1) field write error: %s", p, err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return fmt.Errorf("%T write field end error 1:value: %s", p, err) + } + return err +} + +func (p *AddReply) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("AddReply(%+v)", *p) +} diff --git a/addsvc/main.go b/addsvc/main.go index 58e6fbef8..da4f6d650 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -12,11 +12,13 @@ import ( "syscall" "time" + "github.com/apache/thrift/lib/go/thrift" "github.com/streadway/handy/cors" "github.com/streadway/handy/encoding" "golang.org/x/net/context" "google.golang.org/grpc" + thriftadd "github.com/peterbourgon/gokit/addsvc/_thrift/gen-go/add" "github.com/peterbourgon/gokit/addsvc/pb" "github.com/peterbourgon/gokit/metrics" "github.com/peterbourgon/gokit/metrics/expvar" @@ -28,8 +30,12 @@ import ( func main() { var ( - httpAddr = flag.String("http.addr", ":8001", "Address for HTTP (JSON) server") - grpcAddr = flag.String("grpc.addr", ":8002", "Address for gRPC server") + httpAddr = flag.String("http.addr", ":8001", "Address for HTTP (JSON) server") + grpcAddr = flag.String("grpc.addr", ":8002", "Address for gRPC server") + thriftAddr = flag.String("thrift.addr", ":8003", "Address for Thrift server") + thriftProtocol = flag.String("thrift.protocol", "binary", "binary, compact, json, simplejson") + thriftBufferSize = flag.Int("thrift.buffer.size", 0, "0 for unbuffered") + thriftFramed = flag.Bool("thrift.framed", false, "true to enable framing") ) flag.Parse() @@ -106,6 +112,58 @@ func main() { errc <- http.ListenAndServe(*httpAddr, mux) }() + // Transport: Thrift + go func() { + ctx, cancel := context.WithCancel(root) + defer cancel() + + var protocolFactory thrift.TProtocolFactory + switch *thriftProtocol { + case "binary": + protocolFactory = thrift.NewTBinaryProtocolFactoryDefault() + case "compact": + protocolFactory = thrift.NewTCompactProtocolFactory() + case "json": + protocolFactory = thrift.NewTJSONProtocolFactory() + case "simplejson": + protocolFactory = thrift.NewTSimpleJSONProtocolFactory() + default: + errc <- fmt.Errorf("invalid Thrift protocol %q", *thriftProtocol) + return + } + + var transportFactory thrift.TTransportFactory + if *thriftBufferSize > 0 { + transportFactory = thrift.NewTBufferedTransportFactory(*thriftBufferSize) + } else { + transportFactory = thrift.NewTTransportFactory() + } + + if *thriftFramed { + transportFactory = thrift.NewTFramedTransportFactory(transportFactory) + } + + transport, err := thrift.NewTServerSocket(*thriftAddr) + if err != nil { + errc <- err + return + } + + field := metrics.Field{Key: "transport", Value: "thrift"} + + var service thriftadd.AddService + service = thriftBinding{ctx, e} + service = thriftInstrument(requests.With(field), duration.With(field))(service) + + log.Printf("Thrift server on %s", *thriftAddr) + errc <- thrift.NewTSimpleServer4( + thriftadd.NewAddServiceProcessor(service), + transport, + transportFactory, + protocolFactory, + ).Serve() + }() + log.Fatal(<-errc) } diff --git a/addsvc/thrift_binding.go b/addsvc/thrift_binding.go new file mode 100644 index 000000000..e62165287 --- /dev/null +++ b/addsvc/thrift_binding.go @@ -0,0 +1,51 @@ +package main + +import ( + "time" + + "golang.org/x/net/context" + + thriftadd "github.com/peterbourgon/gokit/addsvc/_thrift/gen-go/add" + "github.com/peterbourgon/gokit/metrics" + "github.com/peterbourgon/gokit/server" +) + +// A binding wraps an Endpoint so that it's usable by a transport. +// thriftBinding makes an Endpoint usable over Thrift. +type thriftBinding struct { + context.Context + server.Endpoint +} + +// Add implements Thrift's AddService interface. +func (tb thriftBinding) Add(a, b int64) (*thriftadd.AddReply, error) { + r, err := tb.Endpoint(tb.Context, request{a, b}) + if err != nil { + return nil, err + } + + resp, ok := r.(*response) + if !ok { + return nil, server.ErrBadCast + } + + return &thriftadd.AddReply{Value: resp.V}, nil +} + +func thriftInstrument(requests metrics.Counter, duration metrics.Histogram) func(thriftadd.AddService) thriftadd.AddService { + return func(next thriftadd.AddService) thriftadd.AddService { + return thriftInstrumented{requests, duration, next} + } +} + +type thriftInstrumented struct { + requests metrics.Counter + duration metrics.Histogram + next thriftadd.AddService +} + +func (i thriftInstrumented) Add(a, b int64) (*thriftadd.AddReply, error) { + i.requests.Add(1) + defer func(begin time.Time) { i.duration.Observe(time.Since(begin).Nanoseconds()) }(time.Now()) + return i.next.Add(a, b) +} From da28ae6b287db8ae3138d7487e092578c1292f7e Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Fri, 17 Apr 2015 18:03:14 +0200 Subject: [PATCH 28/38] zipkin: improve Scribe collector and tests --- tracing/zipkin/collector.go | 42 ++++++++++++++------------------ tracing/zipkin/collector_test.go | 19 ++++++++++++++- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/tracing/zipkin/collector.go b/tracing/zipkin/collector.go index 6c6637058..ef7dbc0ea 100644 --- a/tracing/zipkin/collector.go +++ b/tracing/zipkin/collector.go @@ -35,9 +35,7 @@ type ScribeCollector struct { // NewScribeCollector returns a new Scribe-backed Collector, ready for use. func NewScribeCollector(addr string, timeout time.Duration, batchSize int, batchInterval time.Duration) (Collector, error) { - factory := func() (scribe.Scribe, error) { - return newScribeClient(addr, timeout) - } + factory := scribeClientFactory(addr, timeout) client, err := factory() if err != nil { return nil, err @@ -47,7 +45,6 @@ func NewScribeCollector(addr string, timeout time.Duration, batchSize int, batch factory: factory, spanc: make(chan *Span), sendc: make(chan struct{}), - quitc: make(chan chan struct{}), batch: []*scribe.LogEntry{}, nextSend: time.Now().Add(batchInterval), batchInterval: batchInterval, @@ -64,8 +61,7 @@ func (c *ScribeCollector) Collect(s *Span) error { } func (c *ScribeCollector) loop() { - ticker := time.NewTicker(c.batchInterval / 10) - defer ticker.Stop() + tickc := time.Tick(c.batchInterval / 10) for { select { @@ -78,7 +74,7 @@ func (c *ScribeCollector) loop() { go c.sendNow() } - case <-ticker.C: + case <-tickc: if time.Now().After(c.nextSend) { go c.sendNow() } @@ -89,10 +85,6 @@ func (c *ScribeCollector) loop() { continue } c.batch = c.batch[:0] - - case q := <-c.quitc: - close(q) - return } } } @@ -118,20 +110,22 @@ func (c *ScribeCollector) send(batch []*scribe.LogEntry) error { return nil } -func newScribeClient(addr string, timeout time.Duration) (scribe.Scribe, error) { - a, err := net.ResolveTCPAddr("tcp", addr) - if err != nil { - return nil, err - } - socket := thrift.NewTSocketFromAddrTimeout(a, timeout) - transport := thrift.NewTFramedTransport(socket) - if err := transport.Open(); err != nil { - socket.Close() - return nil, err +func scribeClientFactory(addr string, timeout time.Duration) func() (scribe.Scribe, error) { + return func() (scribe.Scribe, error) { + a, err := net.ResolveTCPAddr("tcp", addr) + if err != nil { + return nil, err + } + socket := thrift.NewTSocketFromAddrTimeout(a, timeout) + transport := thrift.NewTFramedTransport(socket) + if err := transport.Open(); err != nil { + socket.Close() + return nil, err + } + proto := thrift.NewTBinaryProtocolTransport(transport) + client := scribe.NewScribeClientProtocol(transport, proto, proto) + return client, nil } - proto := thrift.NewTBinaryProtocolTransport(transport) - client := scribe.NewScribeClientProtocol(transport, proto, proto) - return client, nil } func serialize(s *Span) string { diff --git a/tracing/zipkin/collector_test.go b/tracing/zipkin/collector_test.go index 2832f09ae..874dd3803 100644 --- a/tracing/zipkin/collector_test.go +++ b/tracing/zipkin/collector_test.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "fmt" "math/rand" + "net" "sync" "testing" "time" @@ -120,7 +121,14 @@ func newScribeServer(t *testing.T) *scribeServer { ) go server.Serve() - time.Sleep(time.Second) + + deadline := time.Now().Add(time.Second) + for !canConnect(port) { + if time.Now().After(deadline) { + t.Fatal("server never started") + } + time.Sleep(time.Millisecond) + } return &scribeServer{ transport: transport, @@ -181,3 +189,12 @@ func (h *scribeHandler) spans() []*zipkincore.Span { } return spans } + +func canConnect(port int) bool { + c, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port)) + if err != nil { + return false + } + c.Close() + return true +} From 667b0bf58c65d82e96db0750d50048c39971213d Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Mon, 27 Apr 2015 17:42:16 +0200 Subject: [PATCH 29/38] log: support writing to stdlib logger --- log/prefix_logger.go | 8 +-- log/{stdlib_writer.go => stdlib.go} | 53 ++++++++++++------- log/{stdlib_writer_test.go => stdlib_test.go} | 27 +++++++--- 3 files changed, 57 insertions(+), 31 deletions(-) rename log/{stdlib_writer.go => stdlib.go} (56%) rename log/{stdlib_writer_test.go => stdlib_test.go} (84%) diff --git a/log/prefix_logger.go b/log/prefix_logger.go index f37324a72..8fbfa5fd1 100644 --- a/log/prefix_logger.go +++ b/log/prefix_logger.go @@ -1,6 +1,7 @@ package log import ( + "bytes" "fmt" "io" ) @@ -19,17 +20,18 @@ func (l prefixLogger) Log(keyvals ...interface{}) error { if len(keyvals)%2 == 1 { panic("odd number of keyvals") } + buf := &bytes.Buffer{} for i := 0; i < len(keyvals); i += 2 { if i != 0 { - if _, err := fmt.Fprint(l.Writer, " "); err != nil { + if _, err := fmt.Fprint(buf, " "); err != nil { return err } } - if _, err := fmt.Fprintf(l.Writer, "%s=%v", keyvals[i], keyvals[i+1]); err != nil { + if _, err := fmt.Fprintf(buf, "%s=%v", keyvals[i], keyvals[i+1]); err != nil { return err } } - if _, err := fmt.Fprintln(l.Writer); err != nil { + if _, err := fmt.Fprintln(l.Writer, buf.String()); err != nil { return err } return nil diff --git a/log/stdlib_writer.go b/log/stdlib.go similarity index 56% rename from log/stdlib_writer.go rename to log/stdlib.go index fcdea1eee..4869f8de7 100644 --- a/log/stdlib_writer.go +++ b/log/stdlib.go @@ -2,53 +2,66 @@ package log import ( "io" + "log" "regexp" + "strings" ) -// StdlibWriter wraps a Logger and allows it to be passed to the stdlib +// StdlibWriter implements io.Writer by invoking the stdlib log.Printf. It's +// designed to be passed to a gokit logger as the writer, for cases where it's +// desirable to pipe all log output to the same, canonical destination. +type StdlibWriter struct{} + +// Write implements io.Writer. +func (w StdlibWriter) Write(p []byte) (int, error) { + log.Printf(strings.TrimSpace(string(p))) + return len(p), nil +} + +// StdlibAdapter wraps a Logger and allows it to be passed to the stdlib // logger's SetOutput. It will extract date/timestamps, filenames, and // messages, and place them under relevant keys. -type StdlibWriter struct { +type StdlibAdapter struct { Logger timestampKey string fileKey string messageKey string } -// StdlibWriterOption sets a parameter for the StdlibWriter. -type StdlibWriterOption func(*StdlibWriter) +// StdlibAdapterOption sets a parameter for the StdlibAdapter. +type StdlibAdapterOption func(*StdlibAdapter) // TimestampKey sets the key for the timestamp field. By default, it's "ts". -func TimestampKey(key string) StdlibWriterOption { - return func(w *StdlibWriter) { w.timestampKey = key } +func TimestampKey(key string) StdlibAdapterOption { + return func(a *StdlibAdapter) { a.timestampKey = key } } // FileKey sets the key for the file and line field. By default, it's "file". -func FileKey(key string) StdlibWriterOption { - return func(w *StdlibWriter) { w.fileKey = key } +func FileKey(key string) StdlibAdapterOption { + return func(a *StdlibAdapter) { a.fileKey = key } } // MessageKey sets the key for the actual log message. By default, it's "msg". -func MessageKey(key string) StdlibWriterOption { - return func(w *StdlibWriter) { w.messageKey = key } +func MessageKey(key string) StdlibAdapterOption { + return func(a *StdlibAdapter) { a.messageKey = key } } -// NewStdlibWriter returns a new StdlibWriter wrapper around the passed +// NewStdlibAdapter returns a new StdlibAdapter wrapper around the passed // logger. It's designed to be passed to log.SetOutput. -func NewStdlibWriter(logger Logger, options ...StdlibWriterOption) io.Writer { - w := StdlibWriter{ +func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer { + a := StdlibAdapter{ Logger: logger, timestampKey: "ts", fileKey: "file", messageKey: "msg", } for _, option := range options { - option(&w) + option(&a) } - return w + return a } -func (w StdlibWriter) Write(p []byte) (int, error) { +func (a StdlibAdapter) Write(p []byte) (int, error) { result := subexps(p) keyvals := []interface{}{} var timestamp string @@ -62,15 +75,15 @@ func (w StdlibWriter) Write(p []byte) (int, error) { timestamp += time } if timestamp != "" { - keyvals = append(keyvals, w.timestampKey, timestamp) + keyvals = append(keyvals, a.timestampKey, timestamp) } if file, ok := result["file"]; ok && file != "" { - keyvals = append(keyvals, w.fileKey, file) + keyvals = append(keyvals, a.fileKey, file) } if msg, ok := result["msg"]; ok { - keyvals = append(keyvals, w.messageKey, msg) + keyvals = append(keyvals, a.messageKey, msg) } - if err := w.Logger.Log(keyvals...); err != nil { + if err := a.Logger.Log(keyvals...); err != nil { return 0, err } return len(p), nil diff --git a/log/stdlib_writer_test.go b/log/stdlib_test.go similarity index 84% rename from log/stdlib_writer_test.go rename to log/stdlib_test.go index e972206a8..9df922d42 100644 --- a/log/stdlib_writer_test.go +++ b/log/stdlib_test.go @@ -8,10 +8,21 @@ import ( "time" ) -func TestStdlibWriterUsage(t *testing.T) { +func TestStdlibWriter(t *testing.T) { + buf := &bytes.Buffer{} + log.SetOutput(buf) + logger := NewPrefixLogger(StdlibWriter{}) + logger.Log("key", "val") + timestamp := time.Now().Format("2006/01/02 15:04:05") + if want, have := timestamp+" key=val\n", buf.String(); want != have { + t.Errorf("want %q, have %q", want, have) + } +} + +func TestStdlibAdapterUsage(t *testing.T) { buf := &bytes.Buffer{} logger := NewPrefixLogger(buf) - writer := NewStdlibWriter(logger) + writer := NewStdlibAdapter(logger) log.SetOutput(writer) now := time.Now() @@ -23,9 +34,9 @@ func TestStdlibWriterUsage(t *testing.T) { log.Ldate: "ts=" + date + " msg=hello\n", log.Ltime: "ts=" + time + " msg=hello\n", log.Ldate | log.Ltime: "ts=" + date + " " + time + " msg=hello\n", - log.Lshortfile: "file=stdlib_writer_test.go:32 msg=hello\n", - log.Lshortfile | log.Ldate: "ts=" + date + " file=stdlib_writer_test.go:32 msg=hello\n", - log.Lshortfile | log.Ldate | log.Ltime: "ts=" + date + " " + time + " file=stdlib_writer_test.go:32 msg=hello\n", + log.Lshortfile: "file=stdlib_test.go:43 msg=hello\n", + log.Lshortfile | log.Ldate: "ts=" + date + " file=stdlib_test.go:43 msg=hello\n", + log.Lshortfile | log.Ldate | log.Ltime: "ts=" + date + " " + time + " file=stdlib_test.go:43 msg=hello\n", } { buf.Reset() log.SetFlags(flag) @@ -36,10 +47,10 @@ func TestStdlibWriterUsage(t *testing.T) { } } -func TestStdLibWriterExtraction(t *testing.T) { +func TestStdLibAdapterExtraction(t *testing.T) { buf := &bytes.Buffer{} logger := NewPrefixLogger(buf) - writer := NewStdlibWriter(logger) + writer := NewStdlibAdapter(logger) for input, want := range map[string]string{ "hello": "msg=hello\n", "2009/01/23: hello": "ts=2009/01/23 msg=hello\n", @@ -60,7 +71,7 @@ func TestStdLibWriterExtraction(t *testing.T) { } } -func TestStdlibWriterSubexps(t *testing.T) { +func TestStdlibAdapterSubexps(t *testing.T) { for input, wantMap := range map[string]map[string]string{ "hello world": map[string]string{ "date": "", From ab1c14c08ddec8a773e366172a4e917e794c18e7 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Mon, 27 Apr 2015 17:42:31 +0200 Subject: [PATCH 30/38] transport: comment formatting --- transport/http/before_after.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transport/http/before_after.go b/transport/http/before_after.go index 66e487090..bff51c6d3 100644 --- a/transport/http/before_after.go +++ b/transport/http/before_after.go @@ -16,8 +16,8 @@ type BeforeFunc func(context.Context, *http.Request) context.Context // after invoking the endpoint but prior to writing a response. type AfterFunc func(context.Context, http.ResponseWriter) -// SetContentType returns a AfterFunc that sets the HTTP Content-Type -// header to the provided value. +// SetContentType returns an AfterFunc that sets the HTTP Content-Type header +// to the provided value. func SetContentType(value string) AfterFunc { return func(_ context.Context, w http.ResponseWriter) { w.Header().Set("Content-Type", value) From 4e4efb36573afea702537daed9728af64d888c10 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Mon, 27 Apr 2015 18:07:03 +0200 Subject: [PATCH 31/38] define and invoke log.DefaultLogger where appropriate --- log/default_logger.go | 5 +++++ tracing/zipkin/collector.go | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 log/default_logger.go diff --git a/log/default_logger.go b/log/default_logger.go new file mode 100644 index 000000000..5a70efc2f --- /dev/null +++ b/log/default_logger.go @@ -0,0 +1,5 @@ +package log + +// DefaultLogger is used by gokit components. By default, it's a PrefixLogger +// that writes to the stdlib log. +var DefaultLogger = NewPrefixLogger(StdlibWriter{}) diff --git a/tracing/zipkin/collector.go b/tracing/zipkin/collector.go index ef7dbc0ea..2f9de5fe7 100644 --- a/tracing/zipkin/collector.go +++ b/tracing/zipkin/collector.go @@ -10,6 +10,7 @@ import ( "github.com/apache/thrift/lib/go/thrift" + "github.com/peterbourgon/gokit/log" "github.com/peterbourgon/gokit/tracing/zipkin/_thrift/gen-go/scribe" ) @@ -82,6 +83,7 @@ func (c *ScribeCollector) loop() { case <-c.sendc: c.nextSend = time.Now().Add(c.batchInterval) if err := c.send(c.batch); err != nil { + log.DefaultLogger.Log("caller", log.DefaultCaller, "error", err.Error()) continue } c.batch = c.batch[:0] From 144bfe8205f27b6ae393834b7fd950c56739bf7f Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 28 Apr 2015 14:31:12 +0200 Subject: [PATCH 32/38] tracing: zipkin: log 'err' rather than 'error' --- tracing/zipkin/collector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing/zipkin/collector.go b/tracing/zipkin/collector.go index 2f9de5fe7..4e40c6c43 100644 --- a/tracing/zipkin/collector.go +++ b/tracing/zipkin/collector.go @@ -83,7 +83,7 @@ func (c *ScribeCollector) loop() { case <-c.sendc: c.nextSend = time.Now().Add(c.batchInterval) if err := c.send(c.batch); err != nil { - log.DefaultLogger.Log("caller", log.DefaultCaller, "error", err.Error()) + log.DefaultLogger.Log("caller", log.DefaultCaller, "err", err.Error()) continue } c.batch = c.batch[:0] From 8c863f72caa356882d37a67dd6a882d5df4155cf Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 28 Apr 2015 14:35:12 +0200 Subject: [PATCH 33/38] addsvc: new protoc defs --- addsvc/pb/add.pb.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addsvc/pb/add.pb.go b/addsvc/pb/add.pb.go index 126f411b0..fbe7f5bd1 100644 --- a/addsvc/pb/add.pb.go +++ b/addsvc/pb/add.pb.go @@ -85,9 +85,9 @@ func RegisterAddServer(s *grpc.Server, srv AddServer) { s.RegisterService(&_Add_serviceDesc, srv) } -func _Add_Add_Handler(srv interface{}, ctx context.Context, buf []byte) (interface{}, error) { +func _Add_Add_Handler(srv interface{}, ctx context.Context, codec grpc.Codec, buf []byte) (interface{}, error) { in := new(AddRequest) - if err := proto.Unmarshal(buf, in); err != nil { + if err := codec.Unmarshal(buf, in); err != nil { return nil, err } out, err := srv.(AddServer).Add(ctx, in) From abb8001e12b6ce4793de28b3e2dff58d916302bb Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 28 Apr 2015 14:48:37 +0200 Subject: [PATCH 34/38] addsvc: uniform IDL compilation scripts --- addsvc/_thrift/compile.sh | 8 +++++--- addsvc/pb/compile.sh | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/addsvc/_thrift/compile.sh b/addsvc/_thrift/compile.sh index a8c311992..046192d12 100755 --- a/addsvc/_thrift/compile.sh +++ b/addsvc/_thrift/compile.sh @@ -1,8 +1,10 @@ #!/usr/bin/env sh # Thrift code generation for Go is broken in the current stable (0.9.2) -# release. Leaving this stubbed out until the fix is released. -# https://issues.apache.org/jira/browse/THRIFT-3021 +# release. See https://issues.apache.org/jira/browse/THRIFT-3021. We prefix +# `thrift` as `_thrift` so the `go` tool ignores the subdir. +# +# See also +# https://thrift.apache.org/tutorial/go -# https://thrift.apache.org/tutorial/go thrift -r --gen go:thrift_import=github.com/apache/thrift/lib/go/thrift add.thrift diff --git a/addsvc/pb/compile.sh b/addsvc/pb/compile.sh index 6fce4a588..090afc08a 100755 --- a/addsvc/pb/compile.sh +++ b/addsvc/pb/compile.sh @@ -1,4 +1,9 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +# Update protoc via +# go get -u github.com/golang/protobuf/{proto,protoc-gen-go} +# +# See also +# https://github.com/grpc/grpc-common/tree/master/go -# https://github.com/grpc/grpc-common/tree/master/go protoc add.proto --go_out=plugins=grpc:. From 4a1ed2865ff7385cae7fd03695148a966d62bb02 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 29 Apr 2015 10:42:35 +0200 Subject: [PATCH 35/38] Tracing and logging upgrades to addsvc - Use proper `package log` loggers throughout - Improve Zipkin tracing API substantially - Prefer Zipkin middleware on server.Endpoint (vs. transport) - Fix Zipkin annotation semantics (cs, sr, ss, cr) - log.DefaultTimestamp[UTC] use RFC3339 formatting --- addsvc/enhancements.go | 13 ++---- addsvc/main.go | 55 ++++++++++++---------- log/value.go | 15 +++--- tracing/zipkin/collector_test.go | 6 +-- tracing/zipkin/span.go | 16 ++----- tracing/zipkin/zipkin.go | 79 ++++++++++++++++++++++++-------- tracing/zipkin/zipkin_test.go | 77 ++++++++++++++++++++++++++----- 7 files changed, 174 insertions(+), 87 deletions(-) diff --git a/addsvc/enhancements.go b/addsvc/enhancements.go index 9d87327ab..238a3bac6 100644 --- a/addsvc/enhancements.go +++ b/addsvc/enhancements.go @@ -1,20 +1,15 @@ package main import ( - "encoding/json" - "io" "time" + + "github.com/peterbourgon/gokit/log" ) -func logging(w io.Writer, add Add) Add { +func logging(logger log.Logger, add Add) Add { return func(a, b int64) (v int64) { defer func(begin time.Time) { - json.NewEncoder(w).Encode(map[string]interface{}{ - "a": a, - "b": b, - "result": v, - "took": time.Since(begin), - }) + logger.Log("a", a, "b", b, "result", v, "took", time.Since(begin)) }(time.Now()) v = add(a, b) return diff --git a/addsvc/main.go b/addsvc/main.go index da4f6d650..baf136a25 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -4,7 +4,7 @@ import ( "flag" "fmt" "io/ioutil" - "log" + stdlog "log" "net" "net/http" "os" @@ -20,6 +20,7 @@ import ( thriftadd "github.com/peterbourgon/gokit/addsvc/_thrift/gen-go/add" "github.com/peterbourgon/gokit/addsvc/pb" + kitlog "github.com/peterbourgon/gokit/log" "github.com/peterbourgon/gokit/metrics" "github.com/peterbourgon/gokit/metrics/expvar" "github.com/peterbourgon/gokit/metrics/statsd" @@ -39,16 +40,6 @@ func main() { ) flag.Parse() - // Our business and operational domain - var a Add - a = pureAdd - a = logging(logWriter{}, a) - - // `package server` domain - var e server.Endpoint - e = makeEndpoint(a) - // e = server.ChainableEnhancement(arg1, arg2, e) - // `package metrics` domain requests := metrics.NewMultiCounter( expvar.NewCounter("requests"), @@ -62,7 +53,30 @@ func main() { // `package tracing` domain zipkinHost := "some-host" // TODO zipkinCollector := zipkin.NopCollector{} // TODO - zipkinSpanFunc := zipkin.NewSpanFunc(zipkinHost, zipkinCollector) + zipkinAddName := "ADD" // is that right? + zipkinAddSpanFunc := zipkin.NewSpanFunc(zipkinHost, zipkinAddName) + + // `package log` domain + var logger kitlog.Logger + logger = kitlog.NewPrefixLogger(kitlog.StdlibWriter{}) + logger = kitlog.With(logger, "ts", kitlog.DefaultTimestampUTC) + kitlog.DefaultLogger = logger // for other gokit components + stdlog.SetOutput(os.Stderr) // + stdlog.SetFlags(0) // flags are handled in our logger + logf := func(format string, args ...interface{}) { + logger.Log("msg", fmt.Sprintf(format, args...)) + } + + // Our business and operational domain + var a Add + a = pureAdd + a = logging(logger, a) + + // `package server` domain + var e server.Endpoint + e = makeEndpoint(a) + e = zipkin.AnnotateEndpoint(zipkinAddSpanFunc, zipkinCollector)(e) + // e = someother.Middleware(arg1, arg2)(e) // Mechanical stuff root := context.Background() @@ -87,7 +101,7 @@ func main() { addServer = grpcInstrument(requests.With(field), duration.With(field))(addServer) pb.RegisterAddServer(s, addServer) - log.Printf("gRPC server on %s", *grpcAddr) + logf("gRPC server on %s", *grpcAddr) errc <- s.Serve(ln) }() @@ -97,7 +111,7 @@ func main() { defer cancel() field := metrics.Field{Key: "transport", Value: "http"} - before := kithttp.Before(zipkin.ToContext(zipkin.FromHTTP(zipkinSpanFunc))) + before := kithttp.Before(zipkin.ToContext(zipkin.FromHTTP(zipkinAddSpanFunc))) after := kithttp.After(kithttp.SetContentType("application/json")) var handler http.Handler @@ -108,7 +122,7 @@ func main() { mux := http.NewServeMux() mux.Handle("/add", handler) - log.Printf("HTTP server on %s", *httpAddr) + logf("HTTP server on %s", *httpAddr) errc <- http.ListenAndServe(*httpAddr, mux) }() @@ -155,7 +169,7 @@ func main() { service = thriftBinding{ctx, e} service = thriftInstrument(requests.With(field), duration.With(field))(service) - log.Printf("Thrift server on %s", *thriftAddr) + logf("Thrift server on %s", *thriftAddr) errc <- thrift.NewTSimpleServer4( thriftadd.NewAddServiceProcessor(service), transport, @@ -164,14 +178,7 @@ func main() { ).Serve() }() - log.Fatal(<-errc) -} - -type logWriter struct{} - -func (logWriter) Write(p []byte) (int, error) { - log.Printf("%s", p) - return len(p), nil + logger.Log("fatal", <-errc) } func interrupt() error { diff --git a/log/value.go b/log/value.go index 3ae74f097..ec78a9ffa 100644 --- a/log/value.go +++ b/log/value.go @@ -40,16 +40,13 @@ func Timestamp(t func() time.Time) Valuer { } var ( - // DefaultTimestamp is a Timestamp Valuer that returns the current - // wallclock time, respecting time zones, when bound. - DefaultTimestamp = Timestamp(time.Now) + // DefaultTimestamp is a Valuer that returns the current wallclock time, + // respecting time zones, when bound. + DefaultTimestamp Valuer = func() interface{} { return time.Now().Format(time.RFC3339) } - // DefaultTimestampUTC wraps DefaultTimestamp but ensures the returned - // time is always in UTC. Note that it invokes DefaultTimestamp, and so - // reflects any changes to the DefaultTimestamp package global. - DefaultTimestampUTC = Timestamp(func() time.Time { - return DefaultTimestamp().(time.Time).UTC() - }) + // DefaultTimestampUTC is a Valuer that returns the current time in UTC + // when bound. + DefaultTimestampUTC Valuer = func() interface{} { return time.Now().UTC().Format(time.RFC3339) } ) // Caller returns a Valuer that returns a file and line from a specified depth diff --git a/tracing/zipkin/collector_test.go b/tracing/zipkin/collector_test.go index 874dd3803..19c253167 100644 --- a/tracing/zipkin/collector_test.go +++ b/tracing/zipkin/collector_test.go @@ -35,10 +35,10 @@ func TestScribeCollector(t *testing.T) { duration = 42 * time.Millisecond ) - span := zipkin.NewSpan("some-host", c, name, traceID, spanID, parentSpanID) + span := zipkin.NewSpan("some-host", name, traceID, spanID, parentSpanID) span.AnnotateDuration("foo", 42*time.Millisecond) - if err := span.Submit(); err != nil { - t.Errorf("error during submit: %v", err) + if err := c.Collect(span); err != nil { + t.Errorf("error during collection: %v", err) } // Need to yield to the select loop to accept the send request, and then diff --git a/tracing/zipkin/span.go b/tracing/zipkin/span.go index f19bc7999..db5d83cb3 100644 --- a/tracing/zipkin/span.go +++ b/tracing/zipkin/span.go @@ -20,9 +20,7 @@ var ( // service. Clients should annotate the span, and submit it when the request // that generated it is complete. type Span struct { - host string - collector Collector - + host string name string traceID int64 spanID int64 @@ -33,10 +31,9 @@ type Span struct { } // NewSpan returns a new Span object ready for use. -func NewSpan(host string, collector Collector, name string, traceID, spanID, parentSpanID int64) *Span { +func NewSpan(host string, name string, traceID, spanID, parentSpanID int64) *Span { return &Span{ host: host, - collector: collector, name: name, traceID: traceID, spanID: spanID, @@ -45,9 +42,9 @@ func NewSpan(host string, collector Collector, name string, traceID, spanID, par } // NewSpanFunc returns a function that generates a new Zipkin span. -func NewSpanFunc(host string, collector Collector) func(string, int64, int64, int64) *Span { - return func(name string, traceID, spanID, parentSpanID int64) *Span { - return NewSpan(host, collector, name, traceID, spanID, parentSpanID) +func NewSpanFunc(host, name string) func(int64, int64, int64) *Span { + return func(traceID, spanID, parentSpanID int64) *Span { + return NewSpan(host, name, traceID, spanID, parentSpanID) } } @@ -76,9 +73,6 @@ func (s *Span) AnnotateDuration(value string, duration time.Duration) { }) } -// Submit sends the span to the collector. -func (s *Span) Submit() error { return s.collector.Collect(s) } - // Encode creates a Thrift Span from the gokit Span. func (s *Span) Encode() *zipkincore.Span { // TODO lots of garbage here. We can improve by preallocating e.g. the diff --git a/tracing/zipkin/zipkin.go b/tracing/zipkin/zipkin.go index 19b7d5318..296b7b513 100644 --- a/tracing/zipkin/zipkin.go +++ b/tracing/zipkin/zipkin.go @@ -6,25 +6,48 @@ import ( "strconv" "golang.org/x/net/context" + + "github.com/peterbourgon/gokit/server" ) // http://www.slideshare.net/johanoskarsson/zipkin-runtime-open-house +// https://groups.google.com/forum/#!topic/zipkin-user/KilwtSA0g1k +// https://gist.github.com/yoavaa/3478d3a0df666f21a98c const ( // https://github.com/racker/tryfer#headers traceIDHTTPHeader = "X-B3-TraceId" spanIDHTTPHeader = "X-B3-SpanId" parentSpanIDHTTPHeader = "X-B3-ParentSpanId" + + clientSend = "cs" + serverReceive = "sr" + serverSend = "ss" + clientReceive = "cr" ) +// AnnotateEndpoint extracts a span from the context, adds server-receive and +// server-send annotations at the boundaries, and submits the span to the +// collector. If no span is present, a new span is generated and put in the +// context. +func AnnotateEndpoint(f func(int64, int64, int64) *Span, c Collector) func(server.Endpoint) server.Endpoint { + return func(e server.Endpoint) server.Endpoint { + return func(ctx context.Context, req server.Request) (server.Response, error) { + span, ctx := mustGetServerSpan(ctx, f) + span.Annotate(serverReceive) + defer func() { span.Annotate(serverSend); c.Collect(span) }() + return e(ctx, req) + } + } +} + // FromHTTP is a helper method that allows NewSpanFunc's factory function to // be easily invoked by passing an HTTP request. The span name is the HTTP -// method, The trace, span, and parent span IDs are taken from the request +// method. The trace, span, and parent span IDs are taken from the request // headers. -func FromHTTP(f func(string, int64, int64, int64) *Span) func(*http.Request) *Span { +func FromHTTP(f func(int64, int64, int64) *Span) func(*http.Request) *Span { return func(r *http.Request) *Span { return f( - r.Method, getID(r.Header, traceIDHTTPHeader), getID(r.Header, spanIDHTTPHeader), getID(r.Header, parentSpanIDHTTPHeader), @@ -32,7 +55,7 @@ func FromHTTP(f func(string, int64, int64, int64) *Span) func(*http.Request) *Sp } } -// ToContext returns a function satisfies transport/http.BeforeFunc. When +// ToContext returns a function that satisfies transport/http.BeforeFunc. When // invoked, it generates a Zipkin span from the incoming HTTP request, and // saves it in the request context under the SpanContextKey. func ToContext(f func(*http.Request) *Span) func(context.Context, *http.Request) context.Context { @@ -41,34 +64,50 @@ func ToContext(f func(*http.Request) *Span) func(context.Context, *http.Request) } } -// SetRequestHeaders sets up HTTP headers for a new outgoing request, based on -// the Span in the request context. It transparently passes through the trace -// ID, assigns a new, random span ID, and sets the parent span ID to the -// current span ID. All IDs are encoded as hex strings. -// -// This function is meant to be applied to outgoing HTTP requests. -func SetRequestHeaders(ctx context.Context, h http.Header) error { +// NewChildSpan creates a new child (client) span. If a span is present in the +// context, it will be interpreted as the parent. +func NewChildSpan(ctx context.Context, f func(int64, int64, int64) *Span) *Span { val := ctx.Value(SpanContextKey) if val == nil { - return ErrSpanNotFound + return f(newID(), newID(), 0) } - - span, ok := val.(*Span) + parentSpan, ok := val.(*Span) if !ok { panic(SpanContextKey + " value isn't a span object") } + var ( + traceID = parentSpan.TraceID() + spanID = newID() + parentSpanID = parentSpan.SpanID() + ) + return f(traceID, spanID, parentSpanID) +} - if id := span.TraceID(); id > 0 { +// SetRequestHeaders sets up HTTP headers for a new outbound request based on +// the (client) span. All IDs are encoded as hex strings. +func SetRequestHeaders(h http.Header, s *Span) { + if id := s.TraceID(); id > 0 { h.Set(traceIDHTTPHeader, strconv.FormatInt(id, 16)) } - - h.Set(spanIDHTTPHeader, strconv.FormatInt(newID(), 16)) - - if id := span.SpanID(); id > 0 { + if id := s.SpanID(); id > 0 { + h.Set(spanIDHTTPHeader, strconv.FormatInt(id, 16)) + } + if id := s.ParentSpanID(); id > 0 { h.Set(parentSpanIDHTTPHeader, strconv.FormatInt(id, 16)) } +} - return nil +func mustGetServerSpan(ctx context.Context, f func(int64, int64, int64) *Span) (*Span, context.Context) { + val := ctx.Value(SpanContextKey) + if val == nil { + span := f(newID(), newID(), 0) + return span, context.WithValue(ctx, SpanContextKey, span) + } + span, ok := val.(*Span) + if !ok { + panic(SpanContextKey + " value isn't a span object") + } + return span, ctx } func getID(h http.Header, key string) int64 { diff --git a/tracing/zipkin/zipkin_test.go b/tracing/zipkin/zipkin_test.go index 223febbae..95b640eda 100644 --- a/tracing/zipkin/zipkin_test.go +++ b/tracing/zipkin/zipkin_test.go @@ -1,17 +1,47 @@ package zipkin_test import ( + "math/rand" "net/http" "strconv" + "sync/atomic" "testing" + "github.com/peterbourgon/gokit/server" + "golang.org/x/net/context" "github.com/peterbourgon/gokit/tracing/zipkin" ) -func TestContextInjection(t *testing.T) { +func TestAnnotateEndpoint(t *testing.T) { const ( + host = "some-host" + name = "some-name" + ) + + f := zipkin.NewSpanFunc(host, name) + c := &countingCollector{} + + var e server.Endpoint + e = func(context.Context, server.Request) (server.Response, error) { return struct{}{}, nil } + e = zipkin.AnnotateEndpoint(f, c)(e) + + if want, have := int32(0), int32(c.int32); want != have { + t.Errorf("want %d, have %d", want, have) + } + if _, err := e(context.Background(), struct{}{}); err != nil { + t.Fatal(err) + } + if want, have := int32(1), int32(c.int32); want != have { + t.Errorf("want %d, have %d", want, have) + } +} + +func TestFromHTTPToContext(t *testing.T) { + const ( + host = "foo-host" + name = "foo-name" traceID int64 = 12 spanID int64 = 34 parentSpanID int64 = 56 @@ -22,7 +52,7 @@ func TestContextInjection(t *testing.T) { r.Header.Set("X-B3-SpanId", strconv.FormatInt(spanID, 16)) r.Header.Set("X-B3-ParentSpanId", strconv.FormatInt(parentSpanID, 16)) - sf := zipkin.NewSpanFunc("my-host", zipkin.NopCollector{}) + sf := zipkin.NewSpanFunc(host, name) hf := zipkin.FromHTTP(sf) cf := zipkin.ToContext(hf) @@ -49,7 +79,9 @@ func TestContextInjection(t *testing.T) { } } -func TestSetRequestHeaders(t *testing.T) { +func TestNewChildSpan(t *testing.T) { + rand.Seed(123) + const ( host = "my-host" name = "my-name" @@ -58,21 +90,44 @@ func TestSetRequestHeaders(t *testing.T) { parentSpanID int64 = 789 ) - span := zipkin.NewSpan(host, zipkin.NopCollector{}, name, traceID, spanID, parentSpanID) - ctx := context.WithValue(context.Background(), zipkin.SpanContextKey, span) + f := zipkin.NewSpanFunc(host, name) + ctx := context.WithValue(context.Background(), zipkin.SpanContextKey, f(traceID, spanID, parentSpanID)) + childSpan := zipkin.NewChildSpan(ctx, f) - r, _ := http.NewRequest("POST", "http://destroy.horse", nil) - if err := zipkin.SetRequestHeaders(ctx, r.Header); err != nil { - t.Fatal(err) + if want, have := traceID, childSpan.TraceID(); want != have { + t.Errorf("want %d, have %d", want, have) + } + if have := childSpan.SpanID(); have == spanID { + t.Errorf("span ID should be random, but we have %d", have) + } + if want, have := spanID, childSpan.ParentSpanID(); want != have { + t.Errorf("want %d, have %d", want, have) } +} + +func TestSetRequestHeaders(t *testing.T) { + const ( + host = "bar-host" + name = "bar-name" + traceID int64 = 123 + spanID int64 = 456 + parentSpanID int64 = 789 + ) + + r, _ := http.NewRequest("POST", "http://destroy.horse", nil) + zipkin.SetRequestHeaders(r.Header, zipkin.NewSpan(host, name, traceID, spanID, parentSpanID)) for h, want := range map[string]string{ - "X-B3-TraceId": strconv.FormatInt(traceID, 16), - // span ID is now random - "X-B3-ParentSpanId": strconv.FormatInt(spanID, 16), + "X-B3-TraceId": strconv.FormatInt(traceID, 16), + "X-B3-SpanId": strconv.FormatInt(spanID, 16), + "X-B3-ParentSpanId": strconv.FormatInt(parentSpanID, 16), } { if have := r.Header.Get(h); want != have { t.Errorf("%s: want %s, have %s", h, want, have) } } } + +type countingCollector struct{ int32 } + +func (c *countingCollector) Collect(*zipkin.Span) error { atomic.AddInt32(&(c.int32), 1); return nil } From 93559349ec880b1ffb45b2760ee44e335e8bdfb2 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 29 Apr 2015 11:45:30 +0200 Subject: [PATCH 36/38] Temporary cleanup for log.Caller --- log/value.go | 4 ++-- log/value_test.go | 4 ++-- tracing/zipkin/collector.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/log/value.go b/log/value.go index ec78a9ffa..583622910 100644 --- a/log/value.go +++ b/log/value.go @@ -56,7 +56,7 @@ func Caller(depth int) Valuer { } var ( - // DefaultCaller is a Valuer that returns the file and line where the Log - // method was invoked. + // DefaultCaller is a Valuer that returns the file and line where the With + // method was invoked. It can only be used with log.With. DefaultCaller = Caller(3) ) diff --git a/log/value_test.go b/log/value_test.go index b8797207a..3a7360de4 100644 --- a/log/value_test.go +++ b/log/value_test.go @@ -34,7 +34,7 @@ func TestValueBinding(t *testing.T) { t.Errorf("output[1]: want %v, have %v", want, have) } if want, have := "value_test.go:28", fmt.Sprint(output[3]); want != have { - t.Fatalf("output[3]: want %s, have %s", want, have) + t.Errorf("output[3]: want %s, have %s", want, have) } // A second attempt to confirm the bindings are truly dynamic. @@ -47,7 +47,7 @@ func TestValueBinding(t *testing.T) { t.Errorf("output[1]: want %v, have %v", want, have) } if want, have := "value_test.go:41", fmt.Sprint(output[3]); want != have { - t.Fatalf("output[3]: want %s, have %s", want, have) + t.Errorf("output[3]: want %s, have %s", want, have) } } diff --git a/tracing/zipkin/collector.go b/tracing/zipkin/collector.go index 4e40c6c43..002c9e49a 100644 --- a/tracing/zipkin/collector.go +++ b/tracing/zipkin/collector.go @@ -83,7 +83,7 @@ func (c *ScribeCollector) loop() { case <-c.sendc: c.nextSend = time.Now().Add(c.batchInterval) if err := c.send(c.batch); err != nil { - log.DefaultLogger.Log("caller", log.DefaultCaller, "err", err.Error()) + log.DefaultLogger.Log("err", err.Error()) continue } c.batch = c.batch[:0] From 383fa68cd350dee063f5ef1eff1d28c07a444762 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 29 Apr 2015 15:48:45 +0200 Subject: [PATCH 37/38] addsvc: proper structured logging --- addsvc/main.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/addsvc/main.go b/addsvc/main.go index baf136a25..19235f27d 100644 --- a/addsvc/main.go +++ b/addsvc/main.go @@ -63,9 +63,6 @@ func main() { kitlog.DefaultLogger = logger // for other gokit components stdlog.SetOutput(os.Stderr) // stdlog.SetFlags(0) // flags are handled in our logger - logf := func(format string, args ...interface{}) { - logger.Log("msg", fmt.Sprintf(format, args...)) - } // Our business and operational domain var a Add @@ -101,7 +98,7 @@ func main() { addServer = grpcInstrument(requests.With(field), duration.With(field))(addServer) pb.RegisterAddServer(s, addServer) - logf("gRPC server on %s", *grpcAddr) + logger.Log("msg", "gRPC server started", "addr", *grpcAddr) errc <- s.Serve(ln) }() @@ -122,7 +119,7 @@ func main() { mux := http.NewServeMux() mux.Handle("/add", handler) - logf("HTTP server on %s", *httpAddr) + logger.Log("msg", "HTTP server started", "addr", *httpAddr) errc <- http.ListenAndServe(*httpAddr, mux) }() @@ -169,7 +166,7 @@ func main() { service = thriftBinding{ctx, e} service = thriftInstrument(requests.With(field), duration.With(field))(service) - logf("Thrift server on %s", *thriftAddr) + logger.Log("msg", "Thrift server started", "addr", *thriftAddr) errc <- thrift.NewTSimpleServer4( thriftadd.NewAddServiceProcessor(service), transport, From bfcc5b94ead9bb66fc2c280e77053ca257abc3cd Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Wed, 29 Apr 2015 16:13:02 +0200 Subject: [PATCH 38/38] log: fix comment --- log/value.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log/value.go b/log/value.go index 583622910..a9881ceb3 100644 --- a/log/value.go +++ b/log/value.go @@ -56,7 +56,7 @@ func Caller(depth int) Valuer { } var ( - // DefaultCaller is a Valuer that returns the file and line where the With + // DefaultCaller is a Valuer that returns the file and line where the Log // method was invoked. It can only be used with log.With. DefaultCaller = Caller(3) )