From 1ee77b5f7bfd87e2f39eca9c4ab18cdb5895ed48 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 16:48:02 +0300 Subject: [PATCH 01/16] init commit --- reporter/amqp/amqp.go | 201 +++++++++++++++++++++++++++++++++++++ reporter/amqp/amqp_test.go | 150 +++++++++++++++++++++++++++ 2 files changed, 351 insertions(+) create mode 100644 reporter/amqp/amqp.go create mode 100644 reporter/amqp/amqp_test.go diff --git a/reporter/amqp/amqp.go b/reporter/amqp/amqp.go new file mode 100644 index 0000000..4db8c11 --- /dev/null +++ b/reporter/amqp/amqp.go @@ -0,0 +1,201 @@ +/* +Package amqp implements a RabbitMq reporter to send spans to a Rabbit server/cluster. +*/ +package amqp + +import ( + "encoding/json" + "fmt" + "log" + "os" + + "github.com/streadway/amqp" + + "github.com/openzipkin/zipkin-go/model" + "github.com/openzipkin/zipkin-go/reporter" +) + +// defaultRmqRoutingKey/Exchange/Kind sets the standard RabbitMQ queue our Reporter will publish on. +const ( + defaultRmqRoutingKey = "zipkin" + defaultRmqExchange = "zipkin" + defaultExchangeKind = "direct" +) + +// rmqReporter implements Reporter by publishing spans to a RabbitMQ exchange +type rmqReporter struct { + e chan error + channel *amqp.Channel + conn *amqp.Connection + exchange string + queue string + logger *log.Logger +} + +// ReporterOption sets a parameter for the rmqReporter +type ReporterOption func(c *rmqReporter) + +// Logger sets the logger used to report errors in the collection +// process. +func Logger(logger *log.Logger) ReporterOption { + return func(c *rmqReporter) { + c.logger = logger + } +} + +// Exchange sets the Exchange used to send messages ( +// see https://github.com/openzipkin/zipkin/tree/master/zipkin-collector/rabbitmq +// if want to change default routing key or exchange +func Exchange(exchange string) ReporterOption { + return func(c *rmqReporter) { + c.exchange = exchange + } +} + +// Queue sets the Queue used to send messages +func Queue(queue string) ReporterOption { + return func(c *rmqReporter) { + c.queue = queue + } +} + +// Channel sets the Channel used to send messages +func Channel(ch *amqp.Channel) ReporterOption { + return func(c *rmqReporter) { + c.channel = ch + } +} + +// Connection sets the Connection used to send messages +func Connection(conn *amqp.Connection) ReporterOption { + return func(c *rmqReporter) { + c.conn = conn + } +} + +// NewReporter returns a new RabbitMq-backed Reporter. address should be as described here: https://www.rabbitmq.com/uri-spec.html +func NewReporter(address string, options ...ReporterOption) (reporter.Reporter, error) { + r := &rmqReporter{ + logger: log.New(os.Stderr, "", log.LstdFlags), + queue: defaultRmqRoutingKey, + exchange: defaultRmqExchange, + e: make(chan error), + } + + for _, option := range options { + option(r) + } + + checks := []func() error{ + r.queueVerify, + r.exchangeVerify, + r.queueBindVerify, + } + + var err error + + if r.conn == nil { + r.conn, err = amqp.Dial(address) + if err != nil { + return nil, err + } + } + + if r.channel == nil { + r.channel, err = r.conn.Channel() + if err != nil { + return nil, err + } + } + + for i := 0; i < len(checks); i++ { + if err := checks[i](); err != nil { + return nil, err + } + } + + go r.logErrors() + + return r, nil +} + +func (r *rmqReporter) logErrors() { + for err := range r.e { + r.logger.Print("msg", err.Error()) + } +} + +func (r *rmqReporter) Send(s model.SpanModel) { + // Zipkin expects the message to be wrapped in an array + ss := []model.SpanModel{s} + m, err := json.Marshal(ss) + if err != nil { + r.e <- fmt.Errorf("failed when marshalling the span: %s\n", err.Error()) + return + } + + msg := amqp.Publishing{ + Body: m, + } + + err = r.channel.Publish(defaultRmqExchange, defaultRmqRoutingKey, false, false, msg) + if err != nil { + r.e <- fmt.Errorf("failed when publishing the span: %s\n", err.Error()) + } +} + +func (r *rmqReporter) queueBindVerify() error { + return r.channel.QueueBind( + defaultRmqRoutingKey, + defaultRmqRoutingKey, + defaultRmqExchange, + false, + nil) +} + +func (r *rmqReporter) exchangeVerify() error { + err := r.channel.ExchangeDeclare( + defaultRmqExchange, + defaultExchangeKind, + true, + false, + false, + false, + nil, + ) + + if err != nil { + return err + } + + return nil +} + +func (r *rmqReporter) queueVerify() error { + _, err := r.channel.QueueDeclare( + defaultRmqExchange, + true, + false, + false, + false, + nil, + ) + if err != nil { + return err + } + + return nil +} + +func (r *rmqReporter) Close() error { + err := r.channel.Close() + if err != nil { + return err + } + + err = r.conn.Close() + if err != nil { + return err + } + return nil +} \ No newline at end of file diff --git a/reporter/amqp/amqp_test.go b/reporter/amqp/amqp_test.go new file mode 100644 index 0000000..c9afde6 --- /dev/null +++ b/reporter/amqp/amqp_test.go @@ -0,0 +1,150 @@ +package amqp_test + +import ( + "encoding/json" + "testing" + "time" + + "github.com/openzipkin/zipkin-go/model" + zipkinamqp "github.com/openzipkin/zipkin-go/reporter/amqp" + "github.com/streadway/amqp" +) + +var spans = []model.SpanModel{ + makeNewSpan("avg", 123, 456, 0, true), + makeNewSpan("sum", 123, 789, 456, true), + makeNewSpan("div", 123, 101112, 456, true), +} + +func TestRabbitProduce(t *testing.T) { + address := "amqp://guest:guest@localhost:5672/" + _, ch, closeFunc := setupRabbit(t, address) + defer closeFunc() + + c, err := zipkinamqp.NewReporter(address, zipkinamqp.Channel(ch)) + if err != nil { + t.Fatal(err) + } + + msgs := setupConsume(t, ch) + + for _, s := range spans { + c.Send(s) + } + + for _, s := range spans { + msg := <-msgs + ds := decodeSpan(t, msg.Body) + testEqual(t, s, ds) + } +} + +func TestRabbitClose(t *testing.T) { + address := "amqp://guest:guest@localhost:5672/" + conn, ch, closeFunc := setupRabbit(t, address) + defer closeFunc() + + cl1 := ch.NotifyClose(make(chan *amqp.Error)) + cl2 := conn.NotifyClose(make(chan *amqp.Error)) + + r, err := zipkinamqp.NewReporter(address, zipkinamqp.Channel(ch), zipkinamqp.Connection(conn)) + if err != nil { + t.Fatal(err) + } + if err = r.Close(); err != nil { + t.Fatal(err) + } + checkClose(t, cl1) + checkClose(t, cl2) + +} + +func checkClose(t *testing.T, ch <-chan *amqp.Error) { + select { + case err := <-ch: + if err != nil { + t.Fatal(err) + } + default: + t.Fatal("channel not closed") + } +} + +func setupRabbit(t *testing.T, address string) (conn *amqp.Connection, ch *amqp.Channel, close func()) { + var err error + conn, err = amqp.Dial(address) + failOnError(t, err, "Failed to connect to RabbitMQ") + + ch, err = conn.Channel() + failOnError(t, err, "Failed to open a channel") + + close = func() { + conn.Close() + ch.Close() + } + return +} + +func setupConsume(t *testing.T, ch *amqp.Channel) <-chan amqp.Delivery { + csm, err := ch.Consume( + "zipkin", // queue + "", // consumer + true, // auto-ack + false, // exclusive + false, // no-local + false, // no-wait + nil, // args + ) + failOnError(t, err, "Failed to register a consumer") + return csm +} + +func decodeSpan(t *testing.T, data []byte) model.SpanModel { + var receivedSpans []model.SpanModel + err := json.Unmarshal(data, &receivedSpans) + if err != nil { + t.Fatal(err) + } + return receivedSpans[0] +} + +func failOnError(t *testing.T, err error, msg string) { + if err != nil { + t.Fatalf("%s: %s", msg, err) + } +} + +func testEqual(t *testing.T, want model.SpanModel, have model.SpanModel) { + if have.TraceID != want.TraceID { + t.Errorf("incorrect trace_id. have %d, want %d", have.TraceID, want.TraceID) + } + if have.ID != want.ID { + t.Errorf("incorrect id. have %d, want %d", have.ID, want.ID) + } + if have.ParentID == nil { + if want.ParentID != nil { + t.Errorf("incorrect parent_id. have %d, want %d", have.ParentID, want.ParentID) + } + } else if have.ParentID != want.ParentID { + t.Errorf("incorrect parent_id. have %d, want %d", have.ParentID, want.ParentID) + } +} + +func makeNewSpan(methodName string, traceID, spanID, parentSpanID uint64, debug bool) model.SpanModel { + timestamp := time.Now() + var parentID = new(model.ID) + if parentSpanID != 0 { + *parentID = model.ID(parentSpanID) + } + + return model.SpanModel{ + SpanContext: model.SpanContext{ + TraceID: model.TraceID{Low: traceID}, + ID: model.ID(spanID), + ParentID: parentID, + Debug: debug, + }, + Name: methodName, + Timestamp: timestamp, + } +} \ No newline at end of file From 8f5c13276fbcc297ab2fd1d586de697bd19f108f Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 16:50:31 +0300 Subject: [PATCH 02/16] include rabbit into travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 09ff7d0..1d9c942 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: go +services: + - rabbitmq + sudo: false matrix: From e7b4920776807f2ecf9c7493e62bd78283526ee9 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 17:31:28 +0300 Subject: [PATCH 03/16] update travis, go.mod, go.sum --- .travis.yml | 2 +- go.mod | 2 +- go.sum | 16 +++------------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1d9c942..8a476b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_install: - go get github.com/mattn/goveralls install: - - go get -d -t ./... + - go mod download - go get -u golang.org/x/lint/golint script: diff --git a/go.mod b/go.mod index f82f9ab..f7f97d9 100644 --- a/go.mod +++ b/go.mod @@ -12,11 +12,11 @@ require ( github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect github.com/gorilla/context v1.1.1 // indirect github.com/gorilla/mux v1.6.2 - github.com/kisielk/gotool v1.0.0 // indirect github.com/onsi/ginkgo v1.7.0 github.com/onsi/gomega v1.4.3 github.com/pierrec/lz4 v2.0.5+incompatible // indirect github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect + github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94 golang.org/x/net v0.0.0-20190311183353-d8887717615a golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect google.golang.org/grpc v1.20.0 diff --git a/go.sum b/go.sum index ff8d7a5..4e7be59 100644 --- a/go.sum +++ b/go.sum @@ -32,7 +32,6 @@ github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= @@ -43,34 +42,26 @@ github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94 h1:0ngsPmuP6XIjiFRNFYlvKwSr5zff2v+uPHaffZ6/M4k= +github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk= -google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.20.0 h1:DlsSIrgEBuZAUFJcta2B5i/lzeHHbnfkNFAfFXLVFYQ= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= @@ -81,5 +72,4 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From f74d79ec620c17893388bcb35a275dfaaa96a505 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 17:55:29 +0300 Subject: [PATCH 04/16] fix tests --- reporter/amqp/amqp_test.go | 48 +++++++++++++------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/reporter/amqp/amqp_test.go b/reporter/amqp/amqp_test.go index c9afde6..331ed2e 100644 --- a/reporter/amqp/amqp_test.go +++ b/reporter/amqp/amqp_test.go @@ -10,7 +10,7 @@ import ( "github.com/streadway/amqp" ) -var spans = []model.SpanModel{ +var spans = []*model.SpanModel{ makeNewSpan("avg", 123, 456, 0, true), makeNewSpan("sum", 123, 789, 456, true), makeNewSpan("div", 123, 101112, 456, true), @@ -29,12 +29,12 @@ func TestRabbitProduce(t *testing.T) { msgs := setupConsume(t, ch) for _, s := range spans { - c.Send(s) + c.Send(*s) } for _, s := range spans { msg := <-msgs - ds := decodeSpan(t, msg.Body) + ds := deserializeSpan(t, msg.Body) testEqual(t, s, ds) } } @@ -44,9 +44,6 @@ func TestRabbitClose(t *testing.T) { conn, ch, closeFunc := setupRabbit(t, address) defer closeFunc() - cl1 := ch.NotifyClose(make(chan *amqp.Error)) - cl2 := conn.NotifyClose(make(chan *amqp.Error)) - r, err := zipkinamqp.NewReporter(address, zipkinamqp.Channel(ch), zipkinamqp.Connection(conn)) if err != nil { t.Fatal(err) @@ -54,21 +51,8 @@ func TestRabbitClose(t *testing.T) { if err = r.Close(); err != nil { t.Fatal(err) } - checkClose(t, cl1) - checkClose(t, cl2) - } -func checkClose(t *testing.T, ch <-chan *amqp.Error) { - select { - case err := <-ch: - if err != nil { - t.Fatal(err) - } - default: - t.Fatal("channel not closed") - } -} func setupRabbit(t *testing.T, address string) (conn *amqp.Connection, ch *amqp.Channel, close func()) { var err error @@ -87,25 +71,25 @@ func setupRabbit(t *testing.T, address string) (conn *amqp.Connection, ch *amqp. func setupConsume(t *testing.T, ch *amqp.Channel) <-chan amqp.Delivery { csm, err := ch.Consume( - "zipkin", // queue - "", // consumer - true, // auto-ack - false, // exclusive - false, // no-local - false, // no-wait - nil, // args + "zipkin", + "", + true, + false, + false, + false, + nil, ) failOnError(t, err, "Failed to register a consumer") return csm } -func decodeSpan(t *testing.T, data []byte) model.SpanModel { +func deserializeSpan(t *testing.T, data []byte) *model.SpanModel { var receivedSpans []model.SpanModel err := json.Unmarshal(data, &receivedSpans) if err != nil { t.Fatal(err) } - return receivedSpans[0] + return &receivedSpans[0] } func failOnError(t *testing.T, err error, msg string) { @@ -114,7 +98,7 @@ func failOnError(t *testing.T, err error, msg string) { } } -func testEqual(t *testing.T, want model.SpanModel, have model.SpanModel) { +func testEqual(t *testing.T, want *model.SpanModel, have *model.SpanModel) { if have.TraceID != want.TraceID { t.Errorf("incorrect trace_id. have %d, want %d", have.TraceID, want.TraceID) } @@ -125,19 +109,19 @@ func testEqual(t *testing.T, want model.SpanModel, have model.SpanModel) { if want.ParentID != nil { t.Errorf("incorrect parent_id. have %d, want %d", have.ParentID, want.ParentID) } - } else if have.ParentID != want.ParentID { + } else if *have.ParentID != *want.ParentID { t.Errorf("incorrect parent_id. have %d, want %d", have.ParentID, want.ParentID) } } -func makeNewSpan(methodName string, traceID, spanID, parentSpanID uint64, debug bool) model.SpanModel { +func makeNewSpan(methodName string, traceID, spanID, parentSpanID uint64, debug bool) *model.SpanModel { timestamp := time.Now() var parentID = new(model.ID) if parentSpanID != 0 { *parentID = model.ID(parentSpanID) } - return model.SpanModel{ + return &model.SpanModel{ SpanContext: model.SpanContext{ TraceID: model.TraceID{Low: traceID}, ID: model.ID(spanID), From 2bf361f07d17968d1a7d9a98859d49924be755c6 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 18:02:15 +0300 Subject: [PATCH 05/16] revert temporary fix in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8a476b4..1d9c942 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_install: - go get github.com/mattn/goveralls install: - - go mod download + - go get -d -t ./... - go get -u golang.org/x/lint/golint script: From b7fe8d32fff41384cbed6d23585df6ea171183a8 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 18:36:52 +0300 Subject: [PATCH 06/16] gofmt --- reporter/amqp/amqp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporter/amqp/amqp.go b/reporter/amqp/amqp.go index 4db8c11..5aca7f1 100644 --- a/reporter/amqp/amqp.go +++ b/reporter/amqp/amqp.go @@ -198,4 +198,4 @@ func (r *rmqReporter) Close() error { return err } return nil -} \ No newline at end of file +} From 021bb4b6e0105a5d3e01b450e71f7733c9861cbb Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 18:39:00 +0300 Subject: [PATCH 07/16] fmt --- reporter/amqp/amqp_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reporter/amqp/amqp_test.go b/reporter/amqp/amqp_test.go index 331ed2e..6674e38 100644 --- a/reporter/amqp/amqp_test.go +++ b/reporter/amqp/amqp_test.go @@ -53,7 +53,6 @@ func TestRabbitClose(t *testing.T) { } } - func setupRabbit(t *testing.T, address string) (conn *amqp.Connection, ch *amqp.Channel, close func()) { var err error conn, err = amqp.Dial(address) @@ -131,4 +130,4 @@ func makeNewSpan(methodName string, traceID, spanID, parentSpanID uint64, debug Name: methodName, Timestamp: timestamp, } -} \ No newline at end of file +} From 7d42ecf94822f9807b5f5187ca83b4bdd81ab492 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 19:22:18 +0300 Subject: [PATCH 08/16] attemp to fix appveyor --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index a567463..57489e7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,7 @@ environment: GOFLAGS: -mod=readonly install: + - choco install rabbitmq --ignoredependencies -y - echo %PATH% - echo %GOPATH% - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% From b6e9cdd5e4c6f77bf59ac226d6b4f3e879c0dc25 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 13 Jun 2019 19:29:53 +0300 Subject: [PATCH 09/16] attemp to fix appveyor --- reporter/amqp/amqp_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reporter/amqp/amqp_test.go b/reporter/amqp/amqp_test.go index 6674e38..d4d36c1 100644 --- a/reporter/amqp/amqp_test.go +++ b/reporter/amqp/amqp_test.go @@ -17,7 +17,7 @@ var spans = []*model.SpanModel{ } func TestRabbitProduce(t *testing.T) { - address := "amqp://guest:guest@localhost:5672/" + address := "amqp://guest:guest@127.0.0.1:5672/" _, ch, closeFunc := setupRabbit(t, address) defer closeFunc() @@ -40,7 +40,7 @@ func TestRabbitProduce(t *testing.T) { } func TestRabbitClose(t *testing.T) { - address := "amqp://guest:guest@localhost:5672/" + address := "amqp://guest:guest@127.0.0.1:5672/" conn, ch, closeFunc := setupRabbit(t, address) defer closeFunc() From f0a8dd021878b8a5b4344586203dbaa5bd0971ad Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 14 Jun 2019 16:52:14 +0300 Subject: [PATCH 10/16] fix appveyor, attempt 3 --- appveyor.yml | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 57489e7..2918ddf 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,12 +5,55 @@ platform: x64 clone_folder: c:\gopath\src\github.com\openzipkin\zipkin-go environment: + erlang_download_url: "http://erlang.org/download/otp_win64_22.0.exe" + erlang_exe_path: "C:\\Users\\appveyor\\erlang_22.0.exe" + erlang_home_dir: "C:\\Users\\appveyor\\erlang" + erlang_erts_version: "erts-10.4" + + rabbitmq_version: 3.7.4 + rabbitmq_installer_download_url: "https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-3.7.15.exe" + rabbitmq_installer_path: "C:\\Users\\appveyor\\rabbitmq-server-3.7.15.exe" + GOPATH: c:\gopath GO111MODULE: on GOFLAGS: -mod=readonly +before_test: + - ps: $webclient=New-Object System.Net.WebClient + + - ECHO Downloading Erlang... + - ps: if (-Not (Test-Path "$env:erlang_exe_path")) { $webclient.DownloadFile("$env:erlang_download_url", "$env:erlang_exe_path") } else { Write-Host "Found" $env:erlang_exe_path "in cache." } + + - ECHO Installing Erlang... + - start /B /WAIT %erlang_exe_path% /S /D=%erlang_home_dir% + - set ERLANG_HOME=%erlang_home_dir% + + - ECHO Downloading RabbitMQ... + - ps: if (-Not (Test-Path "$env:rabbitmq_installer_path")) { $webclient.DownloadFile("$env:rabbitmq_installer_download_url", "$env:rabbitmq_installer_path") } else { Write-Host "Found" $env:rabbitmq_installer_path "in cache." } + + - ECHO Creating directory %AppData%\RabbitMQ... + - ps: New-Item -ItemType Directory -ErrorAction Continue -Path "$env:AppData/RabbitMQ" + + - ECHO Creating RabbitMQ configuration file in %AppData%\RabbitMQ... + - ps: Get-Content C:/Projects/pika/testdata/rabbitmq.conf.in | %{ $_ -replace 'PIKA_DIR', 'C:/projects/pika' } | Set-Content -Path "$env:AppData/RabbitMQ/rabbitmq.conf" + - ps: Get-Content "$env:AppData/RabbitMQ/rabbitmq.conf" + + - ECHO Creating Erlang cookie files... + - ps: '[System.IO.File]::WriteAllText("C:\Users\appveyor\.erlang.cookie", "PIKAISTHEBEST", [System.Text.Encoding]::ASCII)' + - ps: '[System.IO.File]::WriteAllText("C:\Windows\System32\config\systemprofile\.erlang.cookie", "PIKAISTHEBEST", [System.Text.Encoding]::ASCII)' + + - ECHO Installing and starting RabbitMQ with default config... + - start /B /WAIT %rabbitmq_installer_path% /S + - ps: (Get-Service -Name RabbitMQ).Status + + - ECHO Waiting for epmd to report that RabbitMQ has started... + - ps: 'C:\projects\pika\testdata\wait-epmd.ps1' + - ps: 'C:\projects\pika\testdata\wait-rabbitmq.ps1' + + - ECHO Getting RabbitMQ status... + - cmd /c "C:\Program Files\RabbitMQ Server\rabbitmq_server-%rabbitmq_version%\sbin\rabbitmqctl.bat" status + install: - - choco install rabbitmq --ignoredependencies -y - echo %PATH% - echo %GOPATH% - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% From 9b6c758ac94df8e21590f3a9b464e51d24ea09a4 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 14 Jun 2019 16:55:36 +0300 Subject: [PATCH 11/16] fix appveyor, attempt 4 --- appveyor.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 2918ddf..b278b1a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,7 +18,7 @@ environment: GO111MODULE: on GOFLAGS: -mod=readonly -before_test: +install: - ps: $webclient=New-Object System.Net.WebClient - ECHO Downloading Erlang... @@ -52,8 +52,6 @@ before_test: - ECHO Getting RabbitMQ status... - cmd /c "C:\Program Files\RabbitMQ Server\rabbitmq_server-%rabbitmq_version%\sbin\rabbitmqctl.bat" status - -install: - echo %PATH% - echo %GOPATH% - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% From f249eb944092e41e8b2bca428956bd35465364df Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 14 Jun 2019 17:34:57 +0300 Subject: [PATCH 12/16] fix appveyor, attempt 5 --- appveyor.yml | 47 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b278b1a..a39250c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,53 +5,32 @@ platform: x64 clone_folder: c:\gopath\src\github.com\openzipkin\zipkin-go environment: - erlang_download_url: "http://erlang.org/download/otp_win64_22.0.exe" - erlang_exe_path: "C:\\Users\\appveyor\\erlang_22.0.exe" - erlang_home_dir: "C:\\Users\\appveyor\\erlang" - erlang_erts_version: "erts-10.4" - - rabbitmq_version: 3.7.4 - rabbitmq_installer_download_url: "https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-3.7.15.exe" - rabbitmq_installer_path: "C:\\Users\\appveyor\\rabbitmq-server-3.7.15.exe" - GOPATH: c:\gopath GO111MODULE: on GOFLAGS: -mod=readonly install: - - ps: $webclient=New-Object System.Net.WebClient - - - ECHO Downloading Erlang... - - ps: if (-Not (Test-Path "$env:erlang_exe_path")) { $webclient.DownloadFile("$env:erlang_download_url", "$env:erlang_exe_path") } else { Write-Host "Found" $env:erlang_exe_path "in cache." } + - Write-Host "Installing RabbitMQ..." -ForegroundColor Cyan - - ECHO Installing Erlang... - - start /B /WAIT %erlang_exe_path% /S /D=%erlang_home_dir% - - set ERLANG_HOME=%erlang_home_dir% + - Write-Host "Downloading..." + - $exePath = "$($env:USERPROFILE)\rabbitmq-server-3.7.15.exe" + - (New-Object Net.WebClient).DownloadFile('https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-3.7.15.exe', $exePath) - - ECHO Downloading RabbitMQ... - - ps: if (-Not (Test-Path "$env:rabbitmq_installer_path")) { $webclient.DownloadFile("$env:rabbitmq_installer_download_url", "$env:rabbitmq_installer_path") } else { Write-Host "Found" $env:rabbitmq_installer_path "in cache." } + - Write-Host "Installing..." + - cmd /c start /wait $exePath /S - - ECHO Creating directory %AppData%\RabbitMQ... - - ps: New-Item -ItemType Directory -ErrorAction Continue -Path "$env:AppData/RabbitMQ" + - $rabbitPath = 'C:\Program Files (x86)\RabbitMQ Server\rabbitmq-server-3.7.15' - - ECHO Creating RabbitMQ configuration file in %AppData%\RabbitMQ... - - ps: Get-Content C:/Projects/pika/testdata/rabbitmq.conf.in | %{ $_ -replace 'PIKA_DIR', 'C:/projects/pika' } | Set-Content -Path "$env:AppData/RabbitMQ/rabbitmq.conf" - - ps: Get-Content "$env:AppData/RabbitMQ/rabbitmq.conf" + - Write-Host "Installing service..." + - Start-Process -Wait "$rabbitPath\sbin\rabbitmq-service.bat" "install" - - ECHO Creating Erlang cookie files... - - ps: '[System.IO.File]::WriteAllText("C:\Users\appveyor\.erlang.cookie", "PIKAISTHEBEST", [System.Text.Encoding]::ASCII)' - - ps: '[System.IO.File]::WriteAllText("C:\Windows\System32\config\systemprofile\.erlang.cookie", "PIKAISTHEBEST", [System.Text.Encoding]::ASCII)' + - Write-Host "Starting service..." + - Start-Process -Wait "$rabbitPath\sbin\rabbitmq-service.bat" "start" - - ECHO Installing and starting RabbitMQ with default config... - - start /B /WAIT %rabbitmq_installer_path% /S - - ps: (Get-Service -Name RabbitMQ).Status + - Get-Service "RabbitMQ" - - ECHO Waiting for epmd to report that RabbitMQ has started... - - ps: 'C:\projects\pika\testdata\wait-epmd.ps1' - - ps: 'C:\projects\pika\testdata\wait-rabbitmq.ps1' + - Write-Host "RabbitMQ installed and started" -ForegroundColor Green - - ECHO Getting RabbitMQ status... - - cmd /c "C:\Program Files\RabbitMQ Server\rabbitmq_server-%rabbitmq_version%\sbin\rabbitmqctl.bat" status - echo %PATH% - echo %GOPATH% - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% From f30bd8daa3c699b75ed130aad2506e83ad7f3eca Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 14 Jun 2019 17:37:26 +0300 Subject: [PATCH 13/16] fix appveyor, attempt 6 --- appveyor.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a39250c..eef0d37 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,26 +10,26 @@ environment: GOFLAGS: -mod=readonly install: - - Write-Host "Installing RabbitMQ..." -ForegroundColor Cyan + - ps: Write-Host "Installing RabbitMQ..." -ForegroundColor Cyan - - Write-Host "Downloading..." - - $exePath = "$($env:USERPROFILE)\rabbitmq-server-3.7.15.exe" - - (New-Object Net.WebClient).DownloadFile('https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-3.7.15.exe', $exePath) + - ECHO Write-Host "Downloading..." + - ps: $exePath = "$($env:USERPROFILE)\rabbitmq-server-3.7.15.exe" + - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-3.7.15.exe', $exePath) - - Write-Host "Installing..." + - ECHO Write-Host "Installing..." - cmd /c start /wait $exePath /S - - $rabbitPath = 'C:\Program Files (x86)\RabbitMQ Server\rabbitmq-server-3.7.15' + - ps: $rabbitPath = 'C:\Program Files (x86)\RabbitMQ Server\rabbitmq-server-3.7.15' - - Write-Host "Installing service..." - - Start-Process -Wait "$rabbitPath\sbin\rabbitmq-service.bat" "install" + - ECHO Write-Host "Installing service..." + - ps: Start-Process -Wait "$rabbitPath\sbin\rabbitmq-service.bat" "install" - - Write-Host "Starting service..." - - Start-Process -Wait "$rabbitPath\sbin\rabbitmq-service.bat" "start" + - ECHO Write-Host "Starting service..." + - ps: Start-Process -Wait "$rabbitPath\sbin\rabbitmq-service.bat" "start" - - Get-Service "RabbitMQ" + - ps: Get-Service "RabbitMQ" - - Write-Host "RabbitMQ installed and started" -ForegroundColor Green + - ECHO Write-Host "RabbitMQ installed and started" -ForegroundColor Green - echo %PATH% - echo %GOPATH% From c403281c57e19ecde480d9fb5c52326d34111cc8 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 14 Jun 2019 17:48:22 +0300 Subject: [PATCH 14/16] fix appveyor, attempt 6 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index eef0d37..0729573 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,7 +17,7 @@ install: - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-3.7.15.exe', $exePath) - ECHO Write-Host "Installing..." - - cmd /c start /wait $exePath /S + - ps: cmd /c start /wait $exePath /S - ps: $rabbitPath = 'C:\Program Files (x86)\RabbitMQ Server\rabbitmq-server-3.7.15' From 226ae9738ead9d035e4ab659255e8f2a3a9bb2df Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 14 Jun 2019 19:36:39 +0300 Subject: [PATCH 15/16] add installing rabbit via choco --- appveyor.yml | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 0729573..57489e7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,27 +10,7 @@ environment: GOFLAGS: -mod=readonly install: - - ps: Write-Host "Installing RabbitMQ..." -ForegroundColor Cyan - - - ECHO Write-Host "Downloading..." - - ps: $exePath = "$($env:USERPROFILE)\rabbitmq-server-3.7.15.exe" - - ps: (New-Object Net.WebClient).DownloadFile('https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-3.7.15.exe', $exePath) - - - ECHO Write-Host "Installing..." - - ps: cmd /c start /wait $exePath /S - - - ps: $rabbitPath = 'C:\Program Files (x86)\RabbitMQ Server\rabbitmq-server-3.7.15' - - - ECHO Write-Host "Installing service..." - - ps: Start-Process -Wait "$rabbitPath\sbin\rabbitmq-service.bat" "install" - - - ECHO Write-Host "Starting service..." - - ps: Start-Process -Wait "$rabbitPath\sbin\rabbitmq-service.bat" "start" - - - ps: Get-Service "RabbitMQ" - - - ECHO Write-Host "RabbitMQ installed and started" -ForegroundColor Green - + - choco install rabbitmq --ignoredependencies -y - echo %PATH% - echo %GOPATH% - set PATH=%GOPATH%\bin;c:\go\bin;%PATH% From e2f0d1be400bdfba4dc2b5edbe3d18fe7e0926f2 Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Tue, 18 Jun 2019 17:07:20 +0200 Subject: [PATCH 16/16] add build tag to ignore amqp test on windows ci (appveyor) --- reporter/amqp/amqp_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reporter/amqp/amqp_test.go b/reporter/amqp/amqp_test.go index d4d36c1..5371be5 100644 --- a/reporter/amqp/amqp_test.go +++ b/reporter/amqp/amqp_test.go @@ -1,3 +1,5 @@ +// +build !windows + package amqp_test import (