Fix build (#917)
* make go vet happy (renamed example function for syslog)
* adjust Zipkin OpenTracing example to use the new bridge version of zipkin-go-opentracing
* fix expected output from kit-gen due to change in gofmt handling of imports
Peter Bourgon authored 4 years ago
GitHub committed 4 years ago
0 | 0 | package endpoints |
1 | 1 | |
2 | import "context" | |
2 | import ( | |
3 | "context" | |
3 | 4 | |
4 | import "github.com/go-kit/kit/endpoint" | |
5 | ||
6 | import "github.com/go-kit/kit/cmd/kitgen/testdata/anonfields/default/service" | |
5 | "github.com/go-kit/kit/cmd/kitgen/testdata/anonfields/default/service" | |
6 | "github.com/go-kit/kit/endpoint" | |
7 | ) | |
7 | 8 | |
8 | 9 | type FooRequest struct { |
9 | 10 | I int |
0 | 0 | package http |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "net/http" | |
4 | 6 | |
5 | import "net/http" | |
6 | ||
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
8 | import "github.com/go-kit/kit/cmd/kitgen/testdata/anonfields/default/endpoints" | |
7 | "github.com/go-kit/kit/cmd/kitgen/testdata/anonfields/default/endpoints" | |
8 | httptransport "github.com/go-kit/kit/transport/http" | |
9 | ) | |
9 | 10 | |
10 | 11 | func NewHTTPHandler(endpoints endpoints.Endpoints) http.Handler { |
11 | 12 | m := http.NewServeMux() |
0 | 0 | package service |
1 | 1 | |
2 | import "context" | |
3 | ||
4 | import "errors" | |
2 | import ( | |
3 | "context" | |
4 | "errors" | |
5 | ) | |
5 | 6 | |
6 | 7 | type Service struct { |
7 | 8 | } |
0 | 0 | package foo |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
4 | import "errors" | |
5 | import "net/http" | |
6 | import "github.com/go-kit/kit/endpoint" | |
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "errors" | |
6 | "net/http" | |
7 | ||
8 | "github.com/go-kit/kit/endpoint" | |
9 | ||
10 | httptransport "github.com/go-kit/kit/transport/http" | |
11 | ) | |
8 | 12 | |
9 | 13 | type Service struct { |
10 | 14 | } |
0 | 0 | package endpoints |
1 | 1 | |
2 | import "context" | |
2 | import ( | |
3 | "context" | |
3 | 4 | |
4 | import "github.com/go-kit/kit/endpoint" | |
5 | ||
6 | import "github.com/go-kit/kit/cmd/kitgen/testdata/foo/default/service" | |
5 | "github.com/go-kit/kit/cmd/kitgen/testdata/foo/default/service" | |
6 | "github.com/go-kit/kit/endpoint" | |
7 | ) | |
7 | 8 | |
8 | 9 | type BarRequest struct { |
9 | 10 | I int |
0 | 0 | package http |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "net/http" | |
4 | 6 | |
5 | import "net/http" | |
6 | ||
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
8 | import "github.com/go-kit/kit/cmd/kitgen/testdata/foo/default/endpoints" | |
7 | "github.com/go-kit/kit/cmd/kitgen/testdata/foo/default/endpoints" | |
8 | httptransport "github.com/go-kit/kit/transport/http" | |
9 | ) | |
9 | 10 | |
10 | 11 | func NewHTTPHandler(endpoints endpoints.Endpoints) http.Handler { |
11 | 12 | m := http.NewServeMux() |
0 | 0 | package service |
1 | 1 | |
2 | import "context" | |
3 | ||
4 | import "errors" | |
2 | import ( | |
3 | "context" | |
4 | "errors" | |
5 | ) | |
5 | 6 | |
6 | 7 | type FooService struct { |
7 | 8 | } |
0 | 0 | package foo |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
4 | import "errors" | |
5 | import "net/http" | |
6 | import "github.com/go-kit/kit/endpoint" | |
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "errors" | |
6 | "net/http" | |
7 | ||
8 | "github.com/go-kit/kit/endpoint" | |
9 | ||
10 | httptransport "github.com/go-kit/kit/transport/http" | |
11 | ) | |
8 | 12 | |
9 | 13 | type FooService struct { |
10 | 14 | } |
0 | 0 | package endpoints |
1 | 1 | |
2 | import "context" | |
2 | import ( | |
3 | "context" | |
3 | 4 | |
4 | import "github.com/go-kit/kit/endpoint" | |
5 | ||
6 | import "github.com/go-kit/kit/cmd/kitgen/testdata/profilesvc/default/service" | |
5 | "github.com/go-kit/kit/cmd/kitgen/testdata/profilesvc/default/service" | |
6 | "github.com/go-kit/kit/endpoint" | |
7 | ) | |
7 | 8 | |
8 | 9 | type PostProfileRequest struct { |
9 | 10 | P service.Profile |
0 | 0 | package http |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "net/http" | |
4 | 6 | |
5 | import "net/http" | |
6 | ||
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
8 | import "github.com/go-kit/kit/cmd/kitgen/testdata/profilesvc/default/endpoints" | |
7 | "github.com/go-kit/kit/cmd/kitgen/testdata/profilesvc/default/endpoints" | |
8 | httptransport "github.com/go-kit/kit/transport/http" | |
9 | ) | |
9 | 10 | |
10 | 11 | func NewHTTPHandler(endpoints endpoints.Endpoints) http.Handler { |
11 | 12 | m := http.NewServeMux() |
0 | 0 | package service |
1 | 1 | |
2 | import "context" | |
3 | ||
4 | import "errors" | |
2 | import ( | |
3 | "context" | |
4 | "errors" | |
5 | ) | |
5 | 6 | |
6 | 7 | type Profile struct { |
7 | 8 | ID string `json:"id"` |
0 | 0 | package profilesvc |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
4 | import "errors" | |
5 | import "net/http" | |
6 | import "github.com/go-kit/kit/endpoint" | |
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "errors" | |
6 | "net/http" | |
7 | ||
8 | "github.com/go-kit/kit/endpoint" | |
9 | ||
10 | httptransport "github.com/go-kit/kit/transport/http" | |
11 | ) | |
8 | 12 | |
9 | 13 | type Profile struct { |
10 | 14 | ID string `json:"id"` |
0 | 0 | package endpoints |
1 | 1 | |
2 | import "context" | |
2 | import ( | |
3 | "context" | |
3 | 4 | |
4 | import "github.com/go-kit/kit/endpoint" | |
5 | ||
6 | import "github.com/go-kit/kit/cmd/kitgen/testdata/stringservice/default/service" | |
5 | "github.com/go-kit/kit/cmd/kitgen/testdata/stringservice/default/service" | |
6 | "github.com/go-kit/kit/endpoint" | |
7 | ) | |
7 | 8 | |
8 | 9 | type ConcatRequest struct { |
9 | 10 | A string |
0 | 0 | package http |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "net/http" | |
4 | 6 | |
5 | import "net/http" | |
6 | ||
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
8 | import "github.com/go-kit/kit/cmd/kitgen/testdata/stringservice/default/endpoints" | |
7 | "github.com/go-kit/kit/cmd/kitgen/testdata/stringservice/default/endpoints" | |
8 | httptransport "github.com/go-kit/kit/transport/http" | |
9 | ) | |
9 | 10 | |
10 | 11 | func NewHTTPHandler(endpoints endpoints.Endpoints) http.Handler { |
11 | 12 | m := http.NewServeMux() |
0 | 0 | package service |
1 | 1 | |
2 | import "context" | |
3 | ||
4 | import "errors" | |
2 | import ( | |
3 | "context" | |
4 | "errors" | |
5 | ) | |
5 | 6 | |
6 | 7 | type Service struct { |
7 | 8 | } |
0 | 0 | package foo |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
4 | import "errors" | |
5 | import "net/http" | |
6 | import "github.com/go-kit/kit/endpoint" | |
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "errors" | |
6 | "net/http" | |
7 | ||
8 | "github.com/go-kit/kit/endpoint" | |
9 | ||
10 | httptransport "github.com/go-kit/kit/transport/http" | |
11 | ) | |
8 | 12 | |
9 | 13 | type Service struct { |
10 | 14 | } |
0 | 0 | package endpoints |
1 | 1 | |
2 | import "context" | |
2 | import ( | |
3 | "context" | |
3 | 4 | |
4 | import "github.com/go-kit/kit/endpoint" | |
5 | ||
6 | import "github.com/go-kit/kit/cmd/kitgen/testdata/underscores/default/service" | |
5 | "github.com/go-kit/kit/cmd/kitgen/testdata/underscores/default/service" | |
6 | "github.com/go-kit/kit/endpoint" | |
7 | ) | |
7 | 8 | |
8 | 9 | type FooRequest struct { |
9 | 10 | I int |
0 | 0 | package http |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "net/http" | |
4 | 6 | |
5 | import "net/http" | |
6 | ||
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
8 | import "github.com/go-kit/kit/cmd/kitgen/testdata/underscores/default/endpoints" | |
7 | "github.com/go-kit/kit/cmd/kitgen/testdata/underscores/default/endpoints" | |
8 | httptransport "github.com/go-kit/kit/transport/http" | |
9 | ) | |
9 | 10 | |
10 | 11 | func NewHTTPHandler(endpoints endpoints.Endpoints) http.Handler { |
11 | 12 | m := http.NewServeMux() |
0 | 0 | package service |
1 | 1 | |
2 | import "context" | |
3 | ||
4 | import "errors" | |
2 | import ( | |
3 | "context" | |
4 | "errors" | |
5 | ) | |
5 | 6 | |
6 | 7 | type Service struct { |
7 | 8 | } |
0 | 0 | package underscores |
1 | 1 | |
2 | import "context" | |
3 | import "encoding/json" | |
4 | import "errors" | |
5 | import "net/http" | |
6 | import "github.com/go-kit/kit/endpoint" | |
7 | import httptransport "github.com/go-kit/kit/transport/http" | |
2 | import ( | |
3 | "context" | |
4 | "encoding/json" | |
5 | "errors" | |
6 | "net/http" | |
7 | ||
8 | "github.com/go-kit/kit/endpoint" | |
9 | ||
10 | httptransport "github.com/go-kit/kit/transport/http" | |
11 | ) | |
8 | 12 | |
9 | 13 | type Service struct { |
10 | 14 | } |
42 | 42 | thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson") |
43 | 43 | thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered") |
44 | 44 | thriftFramed = fs.Bool("thrift-framed", false, "true to enable framing") |
45 | zipkinV2URL = fs.String("zipkin-url", "", "Enable Zipkin v2 tracing (zipkin-go) via HTTP Reporter URL e.g. http://localhost:9411/api/v2/spans") | |
46 | zipkinV1URL = fs.String("zipkin-v1-url", "", "Enable Zipkin v1 tracing (zipkin-go-opentracing) via a collector URL e.g. http://localhost:9411/api/v1/spans") | |
45 | zipkinURL = fs.String("zipkin-url", "", "Enable Zipkin tracing via HTTP reporter URL e.g. http://localhost:9411/api/v2/spans") | |
46 | zipkinBridge = fs.Bool("zipkin-ot-bridge", false, "Use Zipkin OpenTracing bridge instead of native implementation") | |
47 | 47 | lightstepToken = fs.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token") |
48 | 48 | appdashAddr = fs.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port") |
49 | 49 | method = fs.String("method", "sum", "sum, concat") |
55 | 55 | os.Exit(1) |
56 | 56 | } |
57 | 57 | |
58 | // This is a demonstration of the native Zipkin tracing client. If using | |
59 | // Zipkin this is the more idiomatic client over OpenTracing. | |
60 | var zipkinTracer *zipkin.Tracer | |
61 | { | |
62 | if *zipkinURL != "" { | |
63 | var ( | |
64 | err error | |
65 | hostPort = "" // if host:port is unknown we can keep this empty | |
66 | serviceName = "addsvc-cli" | |
67 | reporter = zipkinhttp.NewReporter(*zipkinURL) | |
68 | ) | |
69 | defer reporter.Close() | |
70 | zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) | |
71 | zipkinTracer, err = zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(zEP)) | |
72 | if err != nil { | |
73 | fmt.Fprintf(os.Stderr, "unable to create zipkin tracer: %s\n", err.Error()) | |
74 | os.Exit(1) | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
58 | 79 | // This is a demonstration client, which supports multiple tracers. |
59 | 80 | // Your clients will probably just use one tracer. |
60 | 81 | var otTracer stdopentracing.Tracer |
61 | 82 | { |
62 | if *zipkinV1URL != "" && *zipkinV2URL == "" { | |
63 | collector, err := zipkinot.NewHTTPCollector(*zipkinV1URL) | |
64 | if err != nil { | |
65 | fmt.Fprintln(os.Stderr, err.Error()) | |
66 | os.Exit(1) | |
67 | } | |
68 | defer collector.Close() | |
69 | var ( | |
70 | debug = false | |
71 | hostPort = "localhost:0" | |
72 | serviceName = "addsvc-cli" | |
73 | ) | |
74 | recorder := zipkinot.NewRecorder(collector, debug, hostPort, serviceName) | |
75 | otTracer, err = zipkinot.NewTracer(recorder) | |
76 | if err != nil { | |
77 | fmt.Fprintln(os.Stderr, err.Error()) | |
78 | os.Exit(1) | |
79 | } | |
83 | if *zipkinBridge && zipkinTracer != nil { | |
84 | otTracer = zipkinot.Wrap(zipkinTracer) | |
85 | zipkinTracer = nil // do not instrument with both native and ot bridge | |
80 | 86 | } else if *lightstepToken != "" { |
81 | 87 | otTracer = lightstep.NewTracer(lightstep.Options{ |
82 | 88 | AccessToken: *lightstepToken, |
86 | 92 | otTracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr)) |
87 | 93 | } else { |
88 | 94 | otTracer = stdopentracing.GlobalTracer() // no-op |
89 | } | |
90 | } | |
91 | ||
92 | // This is a demonstration of the native Zipkin tracing client. If using | |
93 | // Zipkin this is the more idiomatic client over OpenTracing. | |
94 | var zipkinTracer *zipkin.Tracer | |
95 | { | |
96 | var ( | |
97 | err error | |
98 | hostPort = "" // if host:port is unknown we can keep this empty | |
99 | serviceName = "addsvc-cli" | |
100 | useNoopTracer = (*zipkinV2URL == "") | |
101 | reporter = zipkinhttp.NewReporter(*zipkinV2URL) | |
102 | ) | |
103 | defer reporter.Close() | |
104 | zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) | |
105 | zipkinTracer, err = zipkin.NewTracer( | |
106 | reporter, zipkin.WithLocalEndpoint(zEP), zipkin.WithNoopTracer(useNoopTracer), | |
107 | ) | |
108 | if err != nil { | |
109 | fmt.Fprintf(os.Stderr, "unable to create zipkin tracer: %s\n", err.Error()) | |
110 | os.Exit(1) | |
111 | 95 | } |
112 | 96 | } |
113 | 97 |
48 | 48 | thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson") |
49 | 49 | thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered") |
50 | 50 | thriftFramed = fs.Bool("thrift-framed", false, "true to enable framing") |
51 | zipkinV2URL = fs.String("zipkin-url", "", "Enable Zipkin v2 tracing (zipkin-go) using a Reporter URL e.g. http://localhost:9411/api/v2/spans") | |
52 | zipkinV1URL = fs.String("zipkin-v1-url", "", "Enable Zipkin v1 tracing (zipkin-go-opentracing) using a collector URL e.g. http://localhost:9411/api/v1/spans") | |
51 | zipkinURL = fs.String("zipkin-url", "", "Enable Zipkin tracing via HTTP reporter URL e.g. http://localhost:9411/api/v2/spans") | |
52 | zipkinBridge = fs.Bool("zipkin-ot-bridge", false, "Use Zipkin OpenTracing bridge instead of native implementation") | |
53 | 53 | lightstepToken = fs.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token") |
54 | 54 | appdashAddr = fs.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port") |
55 | 55 | ) |
64 | 64 | logger = log.With(logger, "caller", log.DefaultCaller) |
65 | 65 | } |
66 | 66 | |
67 | var zipkinTracer *zipkin.Tracer | |
68 | { | |
69 | if *zipkinURL != "" { | |
70 | var ( | |
71 | err error | |
72 | hostPort = "localhost:80" | |
73 | serviceName = "addsvc" | |
74 | reporter = zipkinhttp.NewReporter(*zipkinURL) | |
75 | ) | |
76 | defer reporter.Close() | |
77 | zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) | |
78 | zipkinTracer, err = zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(zEP)) | |
79 | if err != nil { | |
80 | logger.Log("err", err) | |
81 | os.Exit(1) | |
82 | } | |
83 | if !(*zipkinBridge) { | |
84 | logger.Log("tracer", "Zipkin", "type", "Native", "URL", *zipkinURL) | |
85 | } | |
86 | } | |
87 | } | |
88 | ||
67 | 89 | // Determine which OpenTracing tracer to use. We'll pass the tracer to all the |
68 | 90 | // components that use it, as a dependency. |
69 | 91 | var tracer stdopentracing.Tracer |
70 | 92 | { |
71 | if *zipkinV1URL != "" && *zipkinV2URL == "" { | |
72 | logger.Log("tracer", "Zipkin", "type", "OpenTracing", "URL", *zipkinV1URL) | |
73 | collector, err := zipkinot.NewHTTPCollector(*zipkinV1URL) | |
74 | if err != nil { | |
75 | logger.Log("err", err) | |
76 | os.Exit(1) | |
77 | } | |
78 | defer collector.Close() | |
79 | var ( | |
80 | debug = false | |
81 | hostPort = "localhost:80" | |
82 | serviceName = "addsvc" | |
83 | ) | |
84 | recorder := zipkinot.NewRecorder(collector, debug, hostPort, serviceName) | |
85 | tracer, err = zipkinot.NewTracer(recorder) | |
86 | if err != nil { | |
87 | logger.Log("err", err) | |
88 | os.Exit(1) | |
89 | } | |
93 | if *zipkinBridge && zipkinTracer != nil { | |
94 | logger.Log("tracer", "Zipkin", "type", "OpenTracing", "URL", *zipkinURL) | |
95 | tracer = zipkinot.Wrap(zipkinTracer) | |
96 | zipkinTracer = nil // do not instrument with both native tracer and opentracing bridge | |
90 | 97 | } else if *lightstepToken != "" { |
91 | 98 | logger.Log("tracer", "LightStep") // probably don't want to print out the token :) |
92 | 99 | tracer = lightstep.NewTracer(lightstep.Options{ |
98 | 105 | tracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr)) |
99 | 106 | } else { |
100 | 107 | tracer = stdopentracing.GlobalTracer() // no-op |
101 | } | |
102 | } | |
103 | ||
104 | var zipkinTracer *zipkin.Tracer | |
105 | { | |
106 | var ( | |
107 | err error | |
108 | hostPort = "localhost:80" | |
109 | serviceName = "addsvc" | |
110 | useNoopTracer = (*zipkinV2URL == "") | |
111 | reporter = zipkinhttp.NewReporter(*zipkinV2URL) | |
112 | ) | |
113 | defer reporter.Close() | |
114 | zEP, _ := zipkin.NewEndpoint(serviceName, hostPort) | |
115 | zipkinTracer, err = zipkin.NewTracer( | |
116 | reporter, zipkin.WithLocalEndpoint(zEP), zipkin.WithNoopTracer(useNoopTracer), | |
117 | ) | |
118 | if err != nil { | |
119 | logger.Log("err", err) | |
120 | os.Exit(1) | |
121 | } | |
122 | if !useNoopTracer { | |
123 | logger.Log("tracer", "Zipkin", "type", "Native", "URL", *zipkinV2URL) | |
124 | 108 | } |
125 | 109 | } |
126 | 110 |
37 | 37 | sumEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 1))(sumEndpoint) |
38 | 38 | sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(sumEndpoint) |
39 | 39 | sumEndpoint = opentracing.TraceServer(otTracer, "Sum")(sumEndpoint) |
40 | sumEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Sum")(sumEndpoint) | |
40 | if zipkinTracer != nil { | |
41 | sumEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Sum")(sumEndpoint) | |
42 | } | |
41 | 43 | sumEndpoint = LoggingMiddleware(log.With(logger, "method", "Sum"))(sumEndpoint) |
42 | 44 | sumEndpoint = InstrumentingMiddleware(duration.With("method", "Sum"))(sumEndpoint) |
43 | 45 | } |
47 | 49 | concatEndpoint = ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100))(concatEndpoint) |
48 | 50 | concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{}))(concatEndpoint) |
49 | 51 | concatEndpoint = opentracing.TraceServer(otTracer, "Concat")(concatEndpoint) |
50 | concatEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Concat")(concatEndpoint) | |
52 | if zipkinTracer != nil { | |
53 | concatEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Concat")(concatEndpoint) | |
54 | } | |
51 | 55 | concatEndpoint = LoggingMiddleware(log.With(logger, "method", "Concat"))(concatEndpoint) |
52 | 56 | concatEndpoint = InstrumentingMiddleware(duration.With("method", "Concat"))(concatEndpoint) |
53 | 57 | } |
32 | 32 | |
33 | 33 | // NewGRPCServer makes a set of endpoints available as a gRPC AddServer. |
34 | 34 | func NewGRPCServer(endpoints addendpoint.Set, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) pb.AddServer { |
35 | // Zipkin GRPC Server Trace can either be instantiated per gRPC method with a | |
36 | // provided operation name or a global tracing service can be instantiated | |
37 | // without an operation name and fed to each Go kit gRPC server as a | |
38 | // ServerOption. | |
39 | // In the latter case, the operation name will be the endpoint's grpc method | |
40 | // path if used in combination with the Go kit gRPC Interceptor. | |
41 | // | |
42 | // In this example, we demonstrate a global Zipkin tracing service with | |
43 | // Go kit gRPC Interceptor. | |
44 | zipkinServer := zipkin.GRPCServerTrace(zipkinTracer) | |
45 | ||
46 | 35 | options := []grpctransport.ServerOption{ |
47 | 36 | grpctransport.ServerErrorHandler(transport.NewLogErrorHandler(logger)), |
48 | zipkinServer, | |
37 | } | |
38 | ||
39 | if zipkinTracer != nil { | |
40 | // Zipkin GRPC Server Trace can either be instantiated per gRPC method with a | |
41 | // provided operation name or a global tracing service can be instantiated | |
42 | // without an operation name and fed to each Go kit gRPC server as a | |
43 | // ServerOption. | |
44 | // In the latter case, the operation name will be the endpoint's grpc method | |
45 | // path if used in combination with the Go kit gRPC Interceptor. | |
46 | // | |
47 | // In this example, we demonstrate a global Zipkin tracing service with | |
48 | // Go kit gRPC Interceptor. | |
49 | options = append(options, zipkin.GRPCServerTrace(zipkinTracer)) | |
49 | 50 | } |
50 | 51 | |
51 | 52 | return &grpcServer{ |
92 | 93 | // for the entire remote instance, too. |
93 | 94 | limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) |
94 | 95 | |
95 | // Zipkin GRPC Client Trace can either be instantiated per gRPC method with a | |
96 | // provided operation name or a global tracing client can be instantiated | |
97 | // without an operation name and fed to each Go kit client as ClientOption. | |
98 | // In the latter case, the operation name will be the endpoint's grpc method | |
99 | // path. | |
100 | // | |
101 | // In this example, we demonstrace a global tracing client. | |
102 | zipkinClient := zipkin.GRPCClientTrace(zipkinTracer) | |
103 | ||
104 | 96 | // global client middlewares |
105 | options := []grpctransport.ClientOption{ | |
106 | zipkinClient, | |
107 | } | |
108 | ||
97 | var options []grpctransport.ClientOption | |
98 | ||
99 | if zipkinTracer != nil { | |
100 | // Zipkin GRPC Client Trace can either be instantiated per gRPC method with a | |
101 | // provided operation name or a global tracing client can be instantiated | |
102 | // without an operation name and fed to each Go kit client as ClientOption. | |
103 | // In the latter case, the operation name will be the endpoint's grpc method | |
104 | // path. | |
105 | // | |
106 | // In this example, we demonstrace a global tracing client. | |
107 | options = append(options, zipkin.GRPCClientTrace(zipkinTracer)) | |
108 | ||
109 | } | |
109 | 110 | // Each individual endpoint is an grpc/transport.Client (which implements |
110 | 111 | // endpoint.Endpoint) that gets wrapped with various middlewares. If you |
111 | 112 | // made your own client library, you'd do this work there, so your server |
32 | 32 | // NewHTTPHandler returns an HTTP handler that makes a set of endpoints |
33 | 33 | // available on predefined paths. |
34 | 34 | func NewHTTPHandler(endpoints addendpoint.Set, otTracer stdopentracing.Tracer, zipkinTracer *stdzipkin.Tracer, logger log.Logger) http.Handler { |
35 | // Zipkin HTTP Server Trace can either be instantiated per endpoint with a | |
36 | // provided operation name or a global tracing service can be instantiated | |
37 | // without an operation name and fed to each Go kit endpoint as ServerOption. | |
38 | // In the latter case, the operation name will be the endpoint's http method. | |
39 | // We demonstrate a global tracing service here. | |
40 | zipkinServer := zipkin.HTTPServerTrace(zipkinTracer) | |
41 | ||
42 | 35 | options := []httptransport.ServerOption{ |
43 | 36 | httptransport.ServerErrorEncoder(errorEncoder), |
44 | 37 | httptransport.ServerErrorHandler(transport.NewLogErrorHandler(logger)), |
45 | zipkinServer, | |
38 | } | |
39 | ||
40 | if zipkinTracer != nil { | |
41 | // Zipkin HTTP Server Trace can either be instantiated per endpoint with a | |
42 | // provided operation name or a global tracing service can be instantiated | |
43 | // without an operation name and fed to each Go kit endpoint as ServerOption. | |
44 | // In the latter case, the operation name will be the endpoint's http method. | |
45 | // We demonstrate a global tracing service here. | |
46 | options = append(options, zipkin.HTTPServerTrace(zipkinTracer)) | |
46 | 47 | } |
47 | 48 | |
48 | 49 | m := http.NewServeMux() |
82 | 83 | // for the entire remote instance, too. |
83 | 84 | limiter := ratelimit.NewErroringLimiter(rate.NewLimiter(rate.Every(time.Second), 100)) |
84 | 85 | |
85 | // Zipkin HTTP Client Trace can either be instantiated per endpoint with a | |
86 | // provided operation name or a global tracing client can be instantiated | |
87 | // without an operation name and fed to each Go kit endpoint as ClientOption. | |
88 | // In the latter case, the operation name will be the endpoint's http method. | |
89 | zipkinClient := zipkin.HTTPClientTrace(zipkinTracer) | |
90 | ||
91 | 86 | // global client middlewares |
92 | options := []httptransport.ClientOption{ | |
93 | zipkinClient, | |
87 | var options []httptransport.ClientOption | |
88 | ||
89 | if zipkinTracer != nil { | |
90 | // Zipkin HTTP Client Trace can either be instantiated per endpoint with a | |
91 | // provided operation name or a global tracing client can be instantiated | |
92 | // without an operation name and fed to each Go kit endpoint as ClientOption. | |
93 | // In the latter case, the operation name will be the endpoint's http method. | |
94 | options = append(options, zipkin.HTTPClientTrace(zipkinTracer)) | |
94 | 95 | } |
95 | 96 | |
96 | 97 | // Each individual endpoint is an http/transport.Client (which implements |
107 | 108 | append(options, httptransport.ClientBefore(opentracing.ContextToHTTP(otTracer, logger)))..., |
108 | 109 | ).Endpoint() |
109 | 110 | sumEndpoint = opentracing.TraceClient(otTracer, "Sum")(sumEndpoint) |
110 | sumEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Sum")(sumEndpoint) | |
111 | if zipkinTracer != nil { | |
112 | sumEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Sum")(sumEndpoint) | |
113 | } | |
111 | 114 | sumEndpoint = limiter(sumEndpoint) |
112 | 115 | sumEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ |
113 | 116 | Name: "Sum", |
127 | 130 | append(options, httptransport.ClientBefore(opentracing.ContextToHTTP(otTracer, logger)))..., |
128 | 131 | ).Endpoint() |
129 | 132 | concatEndpoint = opentracing.TraceClient(otTracer, "Concat")(concatEndpoint) |
130 | concatEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Concat")(concatEndpoint) | |
133 | if zipkinTracer != nil { | |
134 | concatEndpoint = zipkin.TraceEndpoint(zipkinTracer, "Concat")(concatEndpoint) | |
135 | } | |
131 | 136 | concatEndpoint = limiter(concatEndpoint) |
132 | 137 | concatEndpoint = circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{ |
133 | 138 | Name: "Concat", |