From bf19dc6654a3f7cc9aee11f65b1999810e91fb1f Mon Sep 17 00:00:00 2001 From: Jason Smith Date: Mon, 19 Dec 2016 17:10:52 +0100 Subject: [PATCH 01/17] added some basics for open tracing, not working --- api/transport.go | 24 +++++++++++++----------- main.go | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/api/transport.go b/api/transport.go index 2f522d8e..77765604 100644 --- a/api/transport.go +++ b/api/transport.go @@ -10,9 +10,11 @@ import ( "strings" "github.com/go-kit/kit/log" + "github.com/go-kit/kit/tracing/opentracing" httptransport "github.com/go-kit/kit/transport/http" "github.com/gorilla/mux" "github.com/microservices-demo/user/users" + stdopentracing "github.com/opentracing/opentracing-go" "github.com/prometheus/client_golang/prometheus/promhttp" "golang.org/x/net/context" ) @@ -22,7 +24,7 @@ var ( ) // MakeHTTPHandler mounts the endpoints into a REST-y HTTP handler. -func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger) http.Handler { +func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger, tracer stdopentracing.Tracer) http.Handler { r := mux.NewRouter().StrictSlash(false) options := []httptransport.ServerOption{ httptransport.ServerErrorLogger(logger), @@ -38,70 +40,70 @@ func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger) http.H e.LoginEndpoint, decodeLoginRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GetLogin", logger)))..., )) r.Methods("POST").Path("/register").Handler(httptransport.NewServer( ctx, e.RegisterEndpoint, decodeRegisterRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "PostRegister", logger)))..., )) r.Methods("GET").PathPrefix("/customers").Handler(httptransport.NewServer( ctx, e.UserGetEndpoint, decodeGetRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GetCustomers", logger)))..., )) r.Methods("GET").PathPrefix("/cards").Handler(httptransport.NewServer( ctx, e.CardGetEndpoint, decodeGetRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GetCards", logger)))..., )) r.Methods("GET").PathPrefix("/addresses").Handler(httptransport.NewServer( ctx, e.AddressGetEndpoint, decodeGetRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GetAddresses", logger)))..., )) r.Methods("POST").Path("/customers").Handler(httptransport.NewServer( ctx, e.UserPostEndpoint, decodeUserRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "PostCustomers", logger)))..., )) r.Methods("POST").Path("/addresses").Handler(httptransport.NewServer( ctx, e.AddressPostEndpoint, decodeAddressRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "PostAddresses", logger)))..., )) r.Methods("POST").Path("/cards").Handler(httptransport.NewServer( ctx, e.CardPostEndpoint, decodeCardRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "PostCards", logger)))..., )) r.Methods("DELETE").PathPrefix("/").Handler(httptransport.NewServer( ctx, e.DeleteEndpoint, decodeDeleteRequest, encodeResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "Delete", logger)))..., )) r.Methods("GET").PathPrefix("/health").Handler(httptransport.NewServer( ctx, e.HealthEndpoint, decodeHealthRequest, encodeHealthResponse, - options..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "Health", logger)))..., )) r.Handle("/metrics", promhttp.Handler()) return r diff --git a/main.go b/main.go index 701f82a5..ed34e08e 100644 --- a/main.go +++ b/main.go @@ -15,15 +15,26 @@ import ( "github.com/microservices-demo/user/api" "github.com/microservices-demo/user/db" "github.com/microservices-demo/user/db/mongodb" + stdopentracing "github.com/opentracing/opentracing-go" + zipkin "github.com/openzipkin/zipkin-go-opentracing" stdprometheus "github.com/prometheus/client_golang/prometheus" "golang.org/x/net/context" ) -var dev bool -var port string -var acc string +var ( + dev bool + port string + acc string + zip string +) + +const ( + ServiceName = "user" +) func init() { + + flag.StringVar(&zip, "zipkin", "", "Enable Zipkin tracing via a Kafka server host:port") flag.StringVar(&port, "port", "8084", "Port on which to run") db.Register("mongodb", &mongodb.Mongo{}) } @@ -42,6 +53,26 @@ func main() { logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC) logger = log.NewContext(logger).With("caller", log.DefaultCaller) } + + logger = log.NewContext(logger).With("tracer", "Zipkin") + logger.Log("addr", zip) + collector, err := zipkin.NewHTTPCollector( + zip, + zipkin.HTTPLogger(logger), + ) + if err != nil { + logger.Log("err", err) + os.Exit(1) + } + var tracer stdopentracing.Tracer + tracer, err = zipkin.NewTracer( + zipkin.NewRecorder(collector, false, fmt.Sprintf(":%v", port), ServiceName), + ) + if err != nil { + logger.Log("err", err) + os.Exit(1) + } + dbconn := false for !dbconn { err := db.Init() @@ -86,7 +117,7 @@ func main() { // Create and launch the HTTP server. go func() { logger.Log("transport", "HTTP", "port", port) - handler := api.MakeHTTPHandler(ctx, endpoints, logger) + handler := api.MakeHTTPHandler(ctx, endpoints, logger, tracer) errc <- http.ListenAndServe(fmt.Sprintf(":%v", port), handler) }() From 4d426f674eacca3995135ca08efb0463c807037a Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Tue, 20 Dec 2016 13:03:49 +0100 Subject: [PATCH 02/17] added dep, and some missing funcs for trace --- glide.lock | 66 +++++++++++++++++++++++++++++++++++++++++++++++++----- glide.yaml | 5 ++++- main.go | 8 +++---- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/glide.lock b/glide.lock index 85e932e8..3045ab5c 100644 --- a/glide.lock +++ b/glide.lock @@ -1,36 +1,81 @@ -hash: c5965c301f7206beca5d0b4a1a9954295a6151e365e3d3323ec081d7a591cd8e -updated: 2016-09-22T22:39:17.110450335+01:00 +hash: d7e1e9f32b8031156dc93516a91cdbf36da66d9c2c4fe7627cfe1ca1a6367aee +updated: 2016-12-20T12:20:18.268810406+01:00 imports: +- name: github.com/apache/thrift + version: 0c27352179e0463bde1f68757f2d77e3c222f530 + subpackages: + - lib/go/thrift - name: github.com/beorn7/perks version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 subpackages: - quantile +- name: github.com/davecgh/go-spew + version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d + subpackages: + - spew +- name: github.com/eapache/go-resiliency + version: b86b1ec0dd4209a588dc1285cdd471e73525c0b3 + subpackages: + - breaker +- name: github.com/eapache/go-xerial-snappy + version: bb955e01b9346ac19dc29eb16586c90ded99a98c +- name: github.com/eapache/queue + version: 44cc805cf13205b55f69e14bcb69867d1ae92f98 - name: github.com/go-kit/kit version: 988c05d06d8ee3a9c13782f0e49b2c6e4726388d subpackages: - endpoint - log - metrics + - metrics/internal/lv - metrics/prometheus + - tracing/opentracing - transport/http - name: github.com/go-logfmt/logfmt version: d4327190ff838312623b09bfeb50d7c93c8d9c1d - name: github.com/go-stack/stack version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 +- name: github.com/gogo/protobuf + version: 06ec6c31ff1bac6ed4e205a547a3d72934813ef3 + subpackages: + - proto - name: github.com/golang/protobuf version: 1f49d83d9aa00e6ce4fc8258c71cc7786aec968a subpackages: - proto +- name: github.com/golang/snappy + version: d9eb7a3d35ec988b8585d4a0068e462c27d28380 - name: github.com/gorilla/context version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 - name: github.com/gorilla/mux version: cf79e51a62d8219d52060dfc1b4e810414ba2d15 +- name: github.com/klauspost/crc32 + version: cb6bfca970f6908083f26f39a79009d608efd5cd - name: github.com/kr/logfmt version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 - name: github.com/matttproud/golang_protobuf_extensions version: c12348ce28de40eed0136aa2b644d0ee0650e56c subpackages: - pbutil +- name: github.com/opentracing/opentracing-go + version: 0c3154a3c2ce79d3271985848659870599dfb77c + subpackages: + - ext + - log +- name: github.com/openzipkin/zipkin-go-opentracing + version: e877b8e9d1069eaedfe4f27e9b6a51cfe20073c9 + subpackages: + - _thrift/gen-go/scribe + - _thrift/gen-go/zipkincore + - flag + - types + - wire +- name: github.com/pierrec/lz4 + version: 5c9560bfa9ace2bf86080bf40d46b34ae44604df +- name: github.com/pierrec/xxHash + version: 5a004441f897722c627870a981d02b29924215fa + subpackages: + - xxHash32 - name: github.com/prometheus/client_golang version: 5636dc67ae776adf5590da7349e70fbb9559972d subpackages: @@ -44,22 +89,33 @@ imports: version: 9a94032291f2192936512bab367bc45e77990d6a subpackages: - expfmt - - model - internal/bitbucket.org/ww/goautoneg + - model - name: github.com/prometheus/procfs version: abf152e5f3e97f2fafac028d2cc06c1feb87ffa5 +- name: github.com/rcrowley/go-metrics + version: 1f30fe9094a513ce4c700b9a54458bbb0c96996c +- name: github.com/Shopify/sarama + version: 9418d7c7189af6ea2df537692f9428efe1368368 - name: golang.org/x/net version: 7394c112eae4dba7e96bfcfe738e6373d61772b4 subpackages: - context - context/ctxhttp + - internal/timeseries + - trace +- name: google.golang.org/grpc + version: 09aecb094ef6b9ebe49dd999f52c505beeeb402e + subpackages: + - metadata - name: gopkg.in/mgo.v2 version: 3f83fa5005286a7fe593b055f0d7771a7dce4655 subpackages: - bson + - dbtest + - internal/json - internal/sasl - internal/scram - - internal/json - name: gopkg.in/tomb.v2 version: 14b3d72120e8d10ea6e6b7f87f7175734b1faab8 -devImports: [] +testImports: [] diff --git a/glide.yaml b/glide.yaml index e5fea30e..85f43ba8 100644 --- a/glide.yaml +++ b/glide.yaml @@ -19,4 +19,7 @@ import: subpackages: - bson - package: gopkg.in/tomb.v2 - +- package: github.com/opentracing/opentracing-go + version: ^1.0.0 +- package: github.com/openzipkin/zipkin-go-opentracing + version: ^0.2.1 diff --git a/main.go b/main.go index ed34e08e..dfc44bfa 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ const ( func init() { - flag.StringVar(&zip, "zipkin", "", "Enable Zipkin tracing via a Kafka server host:port") + flag.StringVar(&zip, "zipkin", "", "Zipkin address") flag.StringVar(&port, "port", "8084", "Port on which to run") db.Register("mongodb", &mongodb.Mongo{}) } @@ -66,13 +66,13 @@ func main() { } var tracer stdopentracing.Tracer tracer, err = zipkin.NewTracer( - zipkin.NewRecorder(collector, false, fmt.Sprintf(":%v", port), ServiceName), + zipkin.NewRecorder(collector, false, fmt.Sprintf("localhost:%v", port), ServiceName), ) if err != nil { logger.Log("err", err) os.Exit(1) } - + stdopentracing.InitGlobalTracer(tracer) dbconn := false for !dbconn { err := db.Init() @@ -112,7 +112,7 @@ func main() { } // Endpoint domain. - endpoints := api.MakeEndpoints(service) + endpoints := api.MakeEndpoints(service, tracer) // Create and launch the HTTP server. go func() { From 5444fc9cd1db52060987f62401d83476c4ae6656 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Tue, 20 Dec 2016 13:31:38 +0100 Subject: [PATCH 03/17] zipkin getting service names but no traces --- api/endpoints.go | 11 +++++++++-- api/transport.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/api/endpoints.go b/api/endpoints.go index 093afd91..bf44c3d8 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -6,8 +6,10 @@ package api import ( "github.com/go-kit/kit/endpoint" + "github.com/go-kit/kit/tracing/opentracing" "github.com/microservices-demo/user/db" "github.com/microservices-demo/user/users" + stdopentracing "github.com/opentracing/opentracing-go" "golang.org/x/net/context" ) @@ -27,12 +29,12 @@ type Endpoints struct { // MakeEndpoints returns an Endpoints structure, where each endpoint is // backed by the given service. -func MakeEndpoints(s Service) Endpoints { +func MakeEndpoints(s Service, tracer stdopentracing.Tracer) Endpoints { return Endpoints{ LoginEndpoint: MakeLoginEndpoint(s), RegisterEndpoint: MakeRegisterEndpoint(s), HealthEndpoint: MakeHealthEndpoint(s), - UserGetEndpoint: MakeUserGetEndpoint(s), + UserGetEndpoint: opentracing.TraceServer(tracer, "GET /customer")(MakeUserGetEndpoint(s)), UserPostEndpoint: MakeUserPostEndpoint(s), AddressGetEndpoint: MakeAddressGetEndpoint(s), AddressPostEndpoint: MakeAddressPostEndpoint(s), @@ -63,6 +65,11 @@ func MakeRegisterEndpoint(s Service) endpoint.Endpoint { // MakeUserGetEndpoint returns an endpoint via the given service. func MakeUserGetEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + span := stdopentracing.SpanFromContext(ctx) + span.SetTag("service", "user") + resourceSpan := stdopentracing.StartSpan("listing users", stdopentracing.ChildOf(span.Context())) + defer resourceSpan.Finish() + req := request.(GetRequest) usrs, err := s.GetUsers(req.ID) if req.ID == "" { diff --git a/api/transport.go b/api/transport.go index 77765604..cce076c0 100644 --- a/api/transport.go +++ b/api/transport.go @@ -54,7 +54,7 @@ func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger, tracer e.UserGetEndpoint, decodeGetRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GetCustomers", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /customer", logger)))..., )) r.Methods("GET").PathPrefix("/cards").Handler(httptransport.NewServer( ctx, From b5af71036de370440277ef519652fd97bb4292c1 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Tue, 20 Dec 2016 14:49:18 +0100 Subject: [PATCH 04/17] got working results on the get customer end point, need to port to other services --- api/endpoints.go | 11 ++++++++--- main.go | 36 +++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/api/endpoints.go b/api/endpoints.go index bf44c3d8..890f8872 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -65,13 +65,16 @@ func MakeRegisterEndpoint(s Service) endpoint.Endpoint { // MakeUserGetEndpoint returns an endpoint via the given service. func MakeUserGetEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { - span := stdopentracing.SpanFromContext(ctx) + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "get users") span.SetTag("service", "user") - resourceSpan := stdopentracing.StartSpan("listing users", stdopentracing.ChildOf(span.Context())) - defer resourceSpan.Finish() + defer span.Finish() req := request.(GetRequest) + + userspan := stdopentracing.StartSpan("users from db", stdopentracing.ChildOf(span.Context())) usrs, err := s.GetUsers(req.ID) + userspan.Finish() if req.ID == "" { return EmbedStruct{usersResponse{Users: usrs}}, err } @@ -85,7 +88,9 @@ func MakeUserGetEndpoint(s Service) endpoint.Endpoint { return users.User{}, err } user := usrs[0] + attrspan := stdopentracing.StartSpan("attributes from db", stdopentracing.ChildOf(span.Context())) db.GetUserAttributes(&user) + attrspan.Finish() if req.Attr == "addresses" { return EmbedStruct{addressesResponse{Addresses: user.Addresses}}, err } diff --git a/main.go b/main.go index dfc44bfa..a7ce2837 100644 --- a/main.go +++ b/main.go @@ -54,25 +54,27 @@ func main() { logger = log.NewContext(logger).With("caller", log.DefaultCaller) } - logger = log.NewContext(logger).With("tracer", "Zipkin") - logger.Log("addr", zip) - collector, err := zipkin.NewHTTPCollector( - zip, - zipkin.HTTPLogger(logger), - ) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } var tracer stdopentracing.Tracer - tracer, err = zipkin.NewTracer( - zipkin.NewRecorder(collector, false, fmt.Sprintf("localhost:%v", port), ServiceName), - ) - if err != nil { - logger.Log("err", err) - os.Exit(1) + { + logger := log.NewContext(logger).With("tracer", "Zipkin") + logger.Log("addr", zip) + collector, err := zipkin.NewHTTPCollector( + zip, + zipkin.HTTPLogger(logger), + ) + if err != nil { + logger.Log("err", err) + os.Exit(1) + } + tracer, err = zipkin.NewTracer( + zipkin.NewRecorder(collector, false, fmt.Sprintf("localhost:%v", port), ServiceName), + ) + if err != nil { + logger.Log("err", err) + os.Exit(1) + } + stdopentracing.InitGlobalTracer(tracer) } - stdopentracing.InitGlobalTracer(tracer) dbconn := false for !dbconn { err := db.Init() From 715aafddb708f03ae3240b8fc9f441fdb19e8050 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Tue, 20 Dec 2016 15:51:45 +0100 Subject: [PATCH 05/17] added tags to all the endpoints, needs to be reviewed. --- api/endpoints.go | 60 ++++++++++++++++++++++++++++++++++++++++-------- api/transport.go | 20 ++++++++-------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/api/endpoints.go b/api/endpoints.go index 890f8872..369997b2 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -31,22 +31,26 @@ type Endpoints struct { // backed by the given service. func MakeEndpoints(s Service, tracer stdopentracing.Tracer) Endpoints { return Endpoints{ - LoginEndpoint: MakeLoginEndpoint(s), - RegisterEndpoint: MakeRegisterEndpoint(s), - HealthEndpoint: MakeHealthEndpoint(s), - UserGetEndpoint: opentracing.TraceServer(tracer, "GET /customer")(MakeUserGetEndpoint(s)), - UserPostEndpoint: MakeUserPostEndpoint(s), - AddressGetEndpoint: MakeAddressGetEndpoint(s), - AddressPostEndpoint: MakeAddressPostEndpoint(s), - CardGetEndpoint: MakeCardGetEndpoint(s), - DeleteEndpoint: MakeDeleteEndpoint(s), - CardPostEndpoint: MakeCardPostEndpoint(s), + LoginEndpoint: opentracing.TraceServer(tracer, "GET /login")(MakeLoginEndpoint(s)), + RegisterEndpoint: opentracing.TraceServer(tracer, "POST /register")(MakeRegisterEndpoint(s)), + HealthEndpoint: opentracing.TraceServer(tracer, "GET /health")(MakeHealthEndpoint(s)), + UserGetEndpoint: opentracing.TraceServer(tracer, "GET /customers")(MakeUserGetEndpoint(s)), + UserPostEndpoint: opentracing.TraceServer(tracer, "POST /customers")(MakeUserPostEndpoint(s)), + AddressGetEndpoint: opentracing.TraceServer(tracer, "GET /addresses")(MakeAddressGetEndpoint(s)), + AddressPostEndpoint: opentracing.TraceServer(tracer, "POST /addresses")(MakeAddressPostEndpoint(s)), + CardGetEndpoint: opentracing.TraceServer(tracer, "GET /cards")(MakeCardGetEndpoint(s)), + DeleteEndpoint: opentracing.TraceServer(tracer, "DELETE /")(MakeDeleteEndpoint(s)), + CardPostEndpoint: opentracing.TraceServer(tracer, "POST /cards")(MakeCardPostEndpoint(s)), } } // MakeLoginEndpoint returns an endpoint via the given service. func MakeLoginEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "login user") + span.SetTag("service", "user") + defer span.Finish() req := request.(loginRequest) u, err := s.Login(req.Username, req.Password) return userResponse{User: u}, err @@ -56,6 +60,10 @@ func MakeLoginEndpoint(s Service) endpoint.Endpoint { // MakeRegisterEndpoint returns an endpoint via the given service. func MakeRegisterEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "register user") + span.SetTag("service", "user") + defer span.Finish() req := request.(registerRequest) id, err := s.Register(req.Username, req.Password, req.Email, req.FirstName, req.LastName) return postResponse{ID: id}, err @@ -104,6 +112,10 @@ func MakeUserGetEndpoint(s Service) endpoint.Endpoint { // MakeUserPostEndpoint returns an endpoint via the given service. func MakeUserPostEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "post user") + span.SetTag("service", "user") + defer span.Finish() req := request.(users.User) id, err := s.PostUser(req) return postResponse{ID: id}, err @@ -113,8 +125,14 @@ func MakeUserPostEndpoint(s Service) endpoint.Endpoint { // MakeAddressGetEndpoint returns an endpoint via the given service. func MakeAddressGetEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "get users") + span.SetTag("service", "user") + defer span.Finish() req := request.(GetRequest) + addrspan := stdopentracing.StartSpan("addresses from db", stdopentracing.ChildOf(span.Context())) adds, err := s.GetAddresses(req.ID) + addrspan.Finish() if req.ID == "" { return EmbedStruct{addressesResponse{Addresses: adds}}, err } @@ -128,6 +146,10 @@ func MakeAddressGetEndpoint(s Service) endpoint.Endpoint { // MakeAddressPostEndpoint returns an endpoint via the given service. func MakeAddressPostEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "post address") + span.SetTag("service", "user") + defer span.Finish() req := request.(addressPostRequest) id, err := s.PostAddress(req.Address, req.UserID) return postResponse{ID: id}, err @@ -137,8 +159,14 @@ func MakeAddressPostEndpoint(s Service) endpoint.Endpoint { // MakeUserGetEndpoint returns an endpoint via the given service. func MakeCardGetEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "get cards") + span.SetTag("service", "user") + defer span.Finish() req := request.(GetRequest) + cardspan := stdopentracing.StartSpan("addresses from db", stdopentracing.ChildOf(span.Context())) cards, err := s.GetCards(req.ID) + cardspan.Finish() if req.ID == "" { return EmbedStruct{cardsResponse{Cards: cards}}, err } @@ -152,6 +180,10 @@ func MakeCardGetEndpoint(s Service) endpoint.Endpoint { // MakeCardPostEndpoint returns an endpoint via the given service. func MakeCardPostEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "post card") + span.SetTag("service", "user") + defer span.Finish() req := request.(cardPostRequest) id, err := s.PostCard(req.Card, req.UserID) return postResponse{ID: id}, err @@ -161,6 +193,10 @@ func MakeCardPostEndpoint(s Service) endpoint.Endpoint { // MakeLoginEndpoint returns an endpoint via the given service. func MakeDeleteEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "delete entity") + span.SetTag("service", "user") + defer span.Finish() req := request.(deleteRequest) err = s.Delete(req.Entity, req.ID) if err == nil { @@ -173,6 +209,10 @@ func MakeDeleteEndpoint(s Service) endpoint.Endpoint { // MakeHealthEndpoint returns current health of the given service. func MakeHealthEndpoint(s Service) endpoint.Endpoint { return func(ctx context.Context, request interface{}) (response interface{}, err error) { + var span stdopentracing.Span + span, ctx = stdopentracing.StartSpanFromContext(ctx, "health check") + span.SetTag("service", "user") + defer span.Finish() health := s.Health() return healthResponse{Health: health}, nil } diff --git a/api/transport.go b/api/transport.go index cce076c0..84197655 100644 --- a/api/transport.go +++ b/api/transport.go @@ -40,70 +40,70 @@ func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger, tracer e.LoginEndpoint, decodeLoginRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GetLogin", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /ogin", logger)))..., )) r.Methods("POST").Path("/register").Handler(httptransport.NewServer( ctx, e.RegisterEndpoint, decodeRegisterRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "PostRegister", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /register", logger)))..., )) r.Methods("GET").PathPrefix("/customers").Handler(httptransport.NewServer( ctx, e.UserGetEndpoint, decodeGetRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /customer", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /customers", logger)))..., )) r.Methods("GET").PathPrefix("/cards").Handler(httptransport.NewServer( ctx, e.CardGetEndpoint, decodeGetRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GetCards", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /cards", logger)))..., )) r.Methods("GET").PathPrefix("/addresses").Handler(httptransport.NewServer( ctx, e.AddressGetEndpoint, decodeGetRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GetAddresses", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /addresses", logger)))..., )) r.Methods("POST").Path("/customers").Handler(httptransport.NewServer( ctx, e.UserPostEndpoint, decodeUserRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "PostCustomers", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /customers", logger)))..., )) r.Methods("POST").Path("/addresses").Handler(httptransport.NewServer( ctx, e.AddressPostEndpoint, decodeAddressRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "PostAddresses", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /addresses", logger)))..., )) r.Methods("POST").Path("/cards").Handler(httptransport.NewServer( ctx, e.CardPostEndpoint, decodeCardRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "PostCards", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /cards", logger)))..., )) r.Methods("DELETE").PathPrefix("/").Handler(httptransport.NewServer( ctx, e.DeleteEndpoint, decodeDeleteRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "Delete", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "DELETE /", logger)))..., )) r.Methods("GET").PathPrefix("/health").Handler(httptransport.NewServer( ctx, e.HealthEndpoint, decodeHealthRequest, encodeHealthResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "Health", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /health", logger)))..., )) r.Handle("/metrics", promhttp.Handler()) return r From 3d2a083703074bc5f08fbd4afa279891fa6cf36b Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Tue, 20 Dec 2016 16:59:30 +0100 Subject: [PATCH 06/17] added a compose file to tests the service --- docker-compose-zipkin.yml | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 docker-compose-zipkin.yml diff --git a/docker-compose-zipkin.yml b/docker-compose-zipkin.yml new file mode 100644 index 00000000..279db4a5 --- /dev/null +++ b/docker-compose-zipkin.yml @@ -0,0 +1,57 @@ +version: '2' + +services: + user: + build: + context: . + image: weaveworksdemos/user + hostname: user + restart: always + read_only: true + environment: + - MONGO_HOST=user-db:27017 + - ZIPKIN=http://zipkin:9411/api/v1/spans + - reschedule=on-node-failure + ports: + - "8084:8084" + user-db: + build: + context: ./docker/user-db/ + image: weaveworksdemos/user-db + hostname: user-db + restart: always + cap_drop: + - all + cap_add: + - CHOWN + - SETGID + - SETUID + read_only: true + tmpfs: + - /tmp:rw,noexec,nosuid + environment: + - reschedule=on-node-failure + ports: + - "27017:27017" + zipkin: + image: openzipkin/zipkin + hostname: zipkin + restart: always + cap_drop: + - all + cap_add: + - CHOWN + - SETGID + - SETUID + read_only: true + tmpfs: + - /tmp:rw,noexec,nosuid + environment: + - reschedule=on-node-failure + ports: + - "9411:9411" + zipkinseed: + image: alpine + command: /bin/sh -c 'sleep 10 ; wget http://user:8084/health ; wget http://user:8084/customers ; wget http://user:8084/customers/57a98d98e4b00679b4a830af ; wget http://user:8084/cards' + + From 714394c50a1f123eb2ea8a33ab5182fe05532d71 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Tue, 20 Dec 2016 17:06:09 +0100 Subject: [PATCH 07/17] added instructions for zipkin test --- zipkintest.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 zipkintest.txt diff --git a/zipkintest.txt b/zipkintest.txt new file mode 100644 index 00000000..6673ec9d --- /dev/null +++ b/zipkintest.txt @@ -0,0 +1,17 @@ +To see the data put into Zipkin do the following + +At the root of the directory run: + +docker-compose -f docker-compose-zipkin.yml build +docker-compose -f docker-compose-zipkin.yml up + +It takes about 10 seconds to seed data + +you should see it at: +http://localhost:9411/ + +be sure to hit the "Find Traces" button. You may need to reload the page. + +when done you can run: + +docker-compose -f docker-compose-zipkin.yml down From 1a5179b4a43961c60c4cb5e975240c8b7eb98351 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Wed, 21 Dec 2016 15:17:27 +0100 Subject: [PATCH 08/17] added zipkin env var --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index a7ce2837..7ec7a801 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ const ( func init() { - flag.StringVar(&zip, "zipkin", "", "Zipkin address") + flag.StringVar(&zip, "zipkin", os.Getenv("ZIPKIN"), "Zipkin address") flag.StringVar(&port, "port", "8084", "Port on which to run") db.Register("mongodb", &mongodb.Mongo{}) } From dcac88af0cb5f857c0689c3c5d81f358ea42a2d2 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 08:27:55 +0100 Subject: [PATCH 09/17] reloaded glide yaml and lock --- glide.lock | 121 ----------------------------------------------------- glide.yaml | 7 ++-- 2 files changed, 3 insertions(+), 125 deletions(-) delete mode 100644 glide.lock diff --git a/glide.lock b/glide.lock deleted file mode 100644 index 3045ab5c..00000000 --- a/glide.lock +++ /dev/null @@ -1,121 +0,0 @@ -hash: d7e1e9f32b8031156dc93516a91cdbf36da66d9c2c4fe7627cfe1ca1a6367aee -updated: 2016-12-20T12:20:18.268810406+01:00 -imports: -- name: github.com/apache/thrift - version: 0c27352179e0463bde1f68757f2d77e3c222f530 - subpackages: - - lib/go/thrift -- name: github.com/beorn7/perks - version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 - subpackages: - - quantile -- name: github.com/davecgh/go-spew - version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d - subpackages: - - spew -- name: github.com/eapache/go-resiliency - version: b86b1ec0dd4209a588dc1285cdd471e73525c0b3 - subpackages: - - breaker -- name: github.com/eapache/go-xerial-snappy - version: bb955e01b9346ac19dc29eb16586c90ded99a98c -- name: github.com/eapache/queue - version: 44cc805cf13205b55f69e14bcb69867d1ae92f98 -- name: github.com/go-kit/kit - version: 988c05d06d8ee3a9c13782f0e49b2c6e4726388d - subpackages: - - endpoint - - log - - metrics - - metrics/internal/lv - - metrics/prometheus - - tracing/opentracing - - transport/http -- name: github.com/go-logfmt/logfmt - version: d4327190ff838312623b09bfeb50d7c93c8d9c1d -- name: github.com/go-stack/stack - version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 -- name: github.com/gogo/protobuf - version: 06ec6c31ff1bac6ed4e205a547a3d72934813ef3 - subpackages: - - proto -- name: github.com/golang/protobuf - version: 1f49d83d9aa00e6ce4fc8258c71cc7786aec968a - subpackages: - - proto -- name: github.com/golang/snappy - version: d9eb7a3d35ec988b8585d4a0068e462c27d28380 -- name: github.com/gorilla/context - version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 -- name: github.com/gorilla/mux - version: cf79e51a62d8219d52060dfc1b4e810414ba2d15 -- name: github.com/klauspost/crc32 - version: cb6bfca970f6908083f26f39a79009d608efd5cd -- name: github.com/kr/logfmt - version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 -- name: github.com/matttproud/golang_protobuf_extensions - version: c12348ce28de40eed0136aa2b644d0ee0650e56c - subpackages: - - pbutil -- name: github.com/opentracing/opentracing-go - version: 0c3154a3c2ce79d3271985848659870599dfb77c - subpackages: - - ext - - log -- name: github.com/openzipkin/zipkin-go-opentracing - version: e877b8e9d1069eaedfe4f27e9b6a51cfe20073c9 - subpackages: - - _thrift/gen-go/scribe - - _thrift/gen-go/zipkincore - - flag - - types - - wire -- name: github.com/pierrec/lz4 - version: 5c9560bfa9ace2bf86080bf40d46b34ae44604df -- name: github.com/pierrec/xxHash - version: 5a004441f897722c627870a981d02b29924215fa - subpackages: - - xxHash32 -- name: github.com/prometheus/client_golang - version: 5636dc67ae776adf5590da7349e70fbb9559972d - subpackages: - - prometheus - - prometheus/promhttp -- name: github.com/prometheus/client_model - version: fa8ad6fec33561be4280a8f0514318c79d7f6cb6 - subpackages: - - go -- name: github.com/prometheus/common - version: 9a94032291f2192936512bab367bc45e77990d6a - subpackages: - - expfmt - - internal/bitbucket.org/ww/goautoneg - - model -- name: github.com/prometheus/procfs - version: abf152e5f3e97f2fafac028d2cc06c1feb87ffa5 -- name: github.com/rcrowley/go-metrics - version: 1f30fe9094a513ce4c700b9a54458bbb0c96996c -- name: github.com/Shopify/sarama - version: 9418d7c7189af6ea2df537692f9428efe1368368 -- name: golang.org/x/net - version: 7394c112eae4dba7e96bfcfe738e6373d61772b4 - subpackages: - - context - - context/ctxhttp - - internal/timeseries - - trace -- name: google.golang.org/grpc - version: 09aecb094ef6b9ebe49dd999f52c505beeeb402e - subpackages: - - metadata -- name: gopkg.in/mgo.v2 - version: 3f83fa5005286a7fe593b055f0d7771a7dce4655 - subpackages: - - bson - - dbtest - - internal/json - - internal/sasl - - internal/scram -- name: gopkg.in/tomb.v2 - version: 14b3d72120e8d10ea6e6b7f87f7175734b1faab8 -testImports: [] diff --git a/glide.yaml b/glide.yaml index 85f43ba8..03e5c555 100644 --- a/glide.yaml +++ b/glide.yaml @@ -6,8 +6,11 @@ import: - log - metrics - metrics/prometheus + - tracing/opentracing - transport/http - package: github.com/gorilla/mux +- package: github.com/opentracing/opentracing-go +- package: github.com/openzipkin/zipkin-go-opentracing - package: github.com/prometheus/client_golang subpackages: - prometheus @@ -19,7 +22,3 @@ import: subpackages: - bson - package: gopkg.in/tomb.v2 -- package: github.com/opentracing/opentracing-go - version: ^1.0.0 -- package: github.com/openzipkin/zipkin-go-opentracing - version: ^0.2.1 From e581a754996b9a35c24b17e22ed9c3a2f423bbc4 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 08:29:29 +0100 Subject: [PATCH 10/17] reset glide.lock --- glide.lock | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 glide.lock diff --git a/glide.lock b/glide.lock new file mode 100644 index 00000000..c0780de2 --- /dev/null +++ b/glide.lock @@ -0,0 +1,119 @@ +hash: 4ee4713d6c89f9f5c8bb53a9d7eda94c14d69ebc70a0f30f48801c416e002740 +updated: 2016-12-22T08:28:36.69998899+01:00 +imports: +- name: github.com/apache/thrift + version: 0c27352179e0463bde1f68757f2d77e3c222f530 + subpackages: + - lib/go/thrift +- name: github.com/beorn7/perks + version: 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 + subpackages: + - quantile +- name: github.com/davecgh/go-spew + version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d + subpackages: + - spew +- name: github.com/eapache/go-resiliency + version: b86b1ec0dd4209a588dc1285cdd471e73525c0b3 + subpackages: + - breaker +- name: github.com/eapache/go-xerial-snappy + version: bb955e01b9346ac19dc29eb16586c90ded99a98c +- name: github.com/eapache/queue + version: 44cc805cf13205b55f69e14bcb69867d1ae92f98 +- name: github.com/go-kit/kit + version: 988c05d06d8ee3a9c13782f0e49b2c6e4726388d + subpackages: + - endpoint + - log + - metrics + - metrics/internal/lv + - metrics/prometheus + - tracing/opentracing + - transport/http +- name: github.com/go-logfmt/logfmt + version: d4327190ff838312623b09bfeb50d7c93c8d9c1d +- name: github.com/go-stack/stack + version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 +- name: github.com/gogo/protobuf + version: 06ec6c31ff1bac6ed4e205a547a3d72934813ef3 + subpackages: + - proto +- name: github.com/golang/protobuf + version: 1f49d83d9aa00e6ce4fc8258c71cc7786aec968a + subpackages: + - proto +- name: github.com/golang/snappy + version: d9eb7a3d35ec988b8585d4a0068e462c27d28380 +- name: github.com/gorilla/context + version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42 +- name: github.com/gorilla/mux + version: cf79e51a62d8219d52060dfc1b4e810414ba2d15 +- name: github.com/klauspost/crc32 + version: cb6bfca970f6908083f26f39a79009d608efd5cd +- name: github.com/kr/logfmt + version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 +- name: github.com/matttproud/golang_protobuf_extensions + version: c12348ce28de40eed0136aa2b644d0ee0650e56c + subpackages: + - pbutil +- name: github.com/opentracing/opentracing-go + version: 0c3154a3c2ce79d3271985848659870599dfb77c + subpackages: + - ext + - log +- name: github.com/openzipkin/zipkin-go-opentracing + version: 594640b9ef7e5c994e8d9499359d693c032d738c + subpackages: + - _thrift/gen-go/scribe + - _thrift/gen-go/zipkincore + - flag + - types + - wire +- name: github.com/pierrec/lz4 + version: 5c9560bfa9ace2bf86080bf40d46b34ae44604df +- name: github.com/pierrec/xxHash + version: 5a004441f897722c627870a981d02b29924215fa + subpackages: + - xxHash32 +- name: github.com/prometheus/client_golang + version: 5636dc67ae776adf5590da7349e70fbb9559972d + subpackages: + - prometheus + - prometheus/promhttp +- name: github.com/prometheus/client_model + version: fa8ad6fec33561be4280a8f0514318c79d7f6cb6 + subpackages: + - go +- name: github.com/prometheus/common + version: 9a94032291f2192936512bab367bc45e77990d6a + subpackages: + - expfmt + - internal/bitbucket.org/ww/goautoneg + - model +- name: github.com/prometheus/procfs + version: abf152e5f3e97f2fafac028d2cc06c1feb87ffa5 +- name: github.com/rcrowley/go-metrics + version: 1f30fe9094a513ce4c700b9a54458bbb0c96996c +- name: github.com/Shopify/sarama + version: 9418d7c7189af6ea2df537692f9428efe1368368 +- name: golang.org/x/net + version: 7394c112eae4dba7e96bfcfe738e6373d61772b4 + subpackages: + - context + - context/ctxhttp +- name: google.golang.org/grpc + version: 09aecb094ef6b9ebe49dd999f52c505beeeb402e + subpackages: + - metadata +- name: gopkg.in/mgo.v2 + version: 3f83fa5005286a7fe593b055f0d7771a7dce4655 + subpackages: + - bson + - dbtest + - internal/json + - internal/sasl + - internal/scram +- name: gopkg.in/tomb.v2 + version: 14b3d72120e8d10ea6e6b7f87f7175734b1faab8 +testImports: [] From d8281b8e8c04742b2f736fab00199956ea40695d Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 08:52:33 +0100 Subject: [PATCH 11/17] removed dbtest, to see how mongodb tests run on travis --- glide.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/glide.lock b/glide.lock index c0780de2..1f451304 100644 --- a/glide.lock +++ b/glide.lock @@ -110,7 +110,6 @@ imports: version: 3f83fa5005286a7fe593b055f0d7771a7dce4655 subpackages: - bson - - dbtest - internal/json - internal/sasl - internal/scram From d7692e334db5aee004fd7b55aa33b4a73bba54a9 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 09:21:28 +0100 Subject: [PATCH 12/17] rolled zipkin lib back --- glide.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glide.lock b/glide.lock index 1f451304..fc740b54 100644 --- a/glide.lock +++ b/glide.lock @@ -63,7 +63,7 @@ imports: - ext - log - name: github.com/openzipkin/zipkin-go-opentracing - version: 594640b9ef7e5c994e8d9499359d693c032d738c + version: e877b8e9d1069eaedfe4f27e9b6a51cfe20073c9 subpackages: - _thrift/gen-go/scribe - _thrift/gen-go/zipkincore From 83fe47504893bf41afff742d98602f556d9ace41 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 09:36:11 +0100 Subject: [PATCH 13/17] updated mongo tests to retrun an exit code --- db/mongodb/mongodb_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/mongodb/mongodb_test.go b/db/mongodb/mongodb_test.go index 929b5dfa..5de7cca8 100644 --- a/db/mongodb/mongodb_test.go +++ b/db/mongodb/mongodb_test.go @@ -2,6 +2,7 @@ package mongodb import ( "fmt" + "os" "testing" "github.com/microservices-demo/user/users" @@ -33,13 +34,13 @@ func TestMain(m *testing.M) { TestMongo.Session = TestServer.Session() TestMongo.EnsureIndexes() TestMongo.Session.Close() - defer exitTest() - m.Run() + exitTest(m.Run()) } -func exitTest() { +func exitTest(i int) { TestServer.Wipe() TestServer.Stop() + os.Exit(i) } func TestInit(t *testing.T) { From b1e6e3f74493a1d62f0a5133ff24ca1af12edac4 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 13:50:47 +0100 Subject: [PATCH 14/17] added a check for flag to set noop tracer --- main.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 7ec7a801..d820e379 100644 --- a/main.go +++ b/main.go @@ -56,22 +56,26 @@ func main() { var tracer stdopentracing.Tracer { - logger := log.NewContext(logger).With("tracer", "Zipkin") - logger.Log("addr", zip) - collector, err := zipkin.NewHTTPCollector( - zip, - zipkin.HTTPLogger(logger), - ) - if err != nil { - logger.Log("err", err) - os.Exit(1) - } - tracer, err = zipkin.NewTracer( - zipkin.NewRecorder(collector, false, fmt.Sprintf("localhost:%v", port), ServiceName), - ) - if err != nil { - logger.Log("err", err) - os.Exit(1) + if zip == "" { + tracer = stdopentracing.NoopTracer{} + } else { + logger := log.NewContext(logger).With("tracer", "Zipkin") + logger.Log("addr", zip) + collector, err := zipkin.NewHTTPCollector( + zip, + zipkin.HTTPLogger(logger), + ) + if err != nil { + logger.Log("err", err) + os.Exit(1) + } + tracer, err = zipkin.NewTracer( + zipkin.NewRecorder(collector, false, fmt.Sprintf("localhost:%v", port), ServiceName), + ) + if err != nil { + logger.Log("err", err) + os.Exit(1) + } } stdopentracing.InitGlobalTracer(tracer) } From 6cf41c5d690478496b5b2ab8a15523600ceffd33 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 14:22:34 +0100 Subject: [PATCH 15/17] added zipkin info to README, pulled out txt file --- README.md | 21 +++++++++++++++++++++ zipkintest.txt | 1 + 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index d0d6590b..61e243ec 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,24 @@ curl http://localhost:8080/register ```bash make dockertravisbuild ``` + +## Test Zipkin + +To test with Zipkin + +``` +make +docker-compose -f docker-compose-zipkin.yml build +docker-compose -f docker-compose-zipkin.yml up +``` +It takes about 10 seconds to seed data + +you should see it at: +[http://localhost:9411/](http://localhost:9411) + +be sure to hit the "Find Traces" button. You may need to reload the page. + +when done you can run: +``` +docker-compose -f docker-compose-zipkin.yml down +``` diff --git a/zipkintest.txt b/zipkintest.txt index 6673ec9d..47e450d4 100644 --- a/zipkintest.txt +++ b/zipkintest.txt @@ -2,6 +2,7 @@ To see the data put into Zipkin do the following At the root of the directory run: +make docker-compose -f docker-compose-zipkin.yml build docker-compose -f docker-compose-zipkin.yml up From aec8297dc74633caf158c49fbb84636d395d90d3 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 14:24:55 +0100 Subject: [PATCH 16/17] removed txt file --- zipkintest.txt | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 zipkintest.txt diff --git a/zipkintest.txt b/zipkintest.txt deleted file mode 100644 index 47e450d4..00000000 --- a/zipkintest.txt +++ /dev/null @@ -1,18 +0,0 @@ -To see the data put into Zipkin do the following - -At the root of the directory run: - -make -docker-compose -f docker-compose-zipkin.yml build -docker-compose -f docker-compose-zipkin.yml up - -It takes about 10 seconds to seed data - -you should see it at: -http://localhost:9411/ - -be sure to hit the "Find Traces" button. You may need to reload the page. - -when done you can run: - -docker-compose -f docker-compose-zipkin.yml down From 6bc65ab9fd43a905a050906a026eae8847fed979 Mon Sep 17 00:00:00 2001 From: Jason Richard Smith Date: Thu, 22 Dec 2016 14:54:02 +0100 Subject: [PATCH 17/17] added missing l in login tag --- api/transport.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/transport.go b/api/transport.go index 84197655..df7cb8a1 100644 --- a/api/transport.go +++ b/api/transport.go @@ -40,7 +40,7 @@ func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger, tracer e.LoginEndpoint, decodeLoginRequest, encodeResponse, - append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /ogin", logger)))..., + append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /login", logger)))..., )) r.Methods("POST").Path("/register").Handler(httptransport.NewServer( ctx,