From 0f2a4631cb30faaaff38efa00aec1f9adaf2c697 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Wed, 8 May 2019 18:46:13 +0300 Subject: [PATCH 01/35] Add jaeger tracing feature. --- benchmark/cmd/thanosbench/main.go | 2 +- benchmark/cmd/thanosbench/resources.go | 2 +- cmd/thanos/main.go | 23 +- go.mod | 6 +- go.sum | 13 +- pkg/tracing/factory.go | 46 ++++ pkg/tracing/factory/factory.go | 13 + pkg/tracing/factory_config.go | 17 ++ pkg/tracing/gcloud/factory.go | 26 ++ pkg/tracing/gcloud/gcloud.go | 131 ++++++++++ pkg/tracing/gct.go | 154 ++++++------ pkg/tracing/http.go | 3 +- pkg/tracing/jaeger/factory.go | 44 ++++ pkg/tracing/tracing.go | 54 ----- pkg/tracing/tracing_test.go | 322 ++++++++++++------------- 15 files changed, 553 insertions(+), 303 deletions(-) create mode 100644 pkg/tracing/factory.go create mode 100644 pkg/tracing/factory/factory.go create mode 100644 pkg/tracing/factory_config.go create mode 100644 pkg/tracing/gcloud/factory.go create mode 100644 pkg/tracing/gcloud/gcloud.go create mode 100644 pkg/tracing/jaeger/factory.go diff --git a/benchmark/cmd/thanosbench/main.go b/benchmark/cmd/thanosbench/main.go index d38907f866..c412e11718 100644 --- a/benchmark/cmd/thanosbench/main.go +++ b/benchmark/cmd/thanosbench/main.go @@ -7,7 +7,7 @@ import ( "github.com/go-kit/kit/log" "github.com/prometheus/common/version" - "gopkg.in/alecthomas/kingpin.v2" + kingpin "gopkg.in/alecthomas/kingpin.v2" "k8s.io/client-go/tools/clientcmd" ) diff --git a/benchmark/cmd/thanosbench/resources.go b/benchmark/cmd/thanosbench/resources.go index 44626d14e0..c76cac5f48 100644 --- a/benchmark/cmd/thanosbench/resources.go +++ b/benchmark/cmd/thanosbench/resources.go @@ -10,7 +10,7 @@ import ( "github.com/pkg/errors" "github.com/prometheus/common/model" prom "github.com/prometheus/prometheus/config" - "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v2" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 2dbbad88a3..ff0150c6a9 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -65,10 +65,20 @@ func main() { logFormat := app.Flag("log.format", "Log format to use."). Default(logFormatLogfmt).Enum(logFormatLogfmt, logFormatJson) - gcloudTraceProject := app.Flag("gcloudtrace.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled."). - String() - gcloudTraceSampleFactor := app.Flag("gcloudtrace.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details."). - Default("1").Uint64() + // tracerFactory := tracing.Newfactory(tracing.FactoryConfigFromKingPin(app)) + // tracerConfig := tracing.FactoryConfigFromKingPin(app) + //tracingFactory, _ := tracing.NewFactory(tracing.FactoryConfigFromKingpin(app)) + tracingFactory := tracing.NewFactory(tracing.FactoryConfigFromKingpin(app)) + tracingFactory.RegisterKingpinFlags(app) + + // tracing.ParseFlags(app) + // tracer.Configure(app) + // tracingType := app.Flag("tracing.type", "gcloud/jaeger.").Default("gcloud").String() + + // gcloudTraceProject := app.Flag("gcloudtrace.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled."). + // String() + // gcloudTraceSampleFactor := app.Flag("gcloudtrace.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details."). + // Default("1").Uint64() cmds := map[string]setupFunc{} registerSidecar(cmds, app, "sidecar") @@ -144,7 +154,10 @@ func main() { ctx := context.Background() var closeFn func() error - tracer, closeFn = tracing.NewOptionalGCloudTracer(ctx, logger, *gcloudTraceProject, *gcloudTraceSampleFactor, *debugName) + + tracer, closeFn = tracingFactory.Create(ctx, logger) + + // tracer, closeFn = tracing.NewOptionalGCloudTracer(ctx, logger, *gcloudTraceProject, *gcloudTraceSampleFactor, *debugName) // This is bad, but Prometheus does not support any other tracer injections than just global one. // TODO(bplotka): Work with basictracer to handle gracefully tracker mismatches, and also with Prometheus to allow diff --git a/go.mod b/go.mod index 044c0d0441..28e94d6b58 100644 --- a/go.mod +++ b/go.mod @@ -31,13 +31,17 @@ require ( github.com/olekukonko/tablewriter v0.0.1 github.com/opentracing-contrib/go-stdlib v0.0.0-20170113013457-1de4cc2120e7 github.com/opentracing/basictracer-go v1.0.0 - github.com/opentracing/opentracing-go v1.0.2 + github.com/opentracing/opentracing-go v1.1.0 github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v0.9.2 github.com/prometheus/common v0.0.0-20181218105931-67670fe90761 github.com/prometheus/prometheus v0.0.0-20190328180107-4d60eb36dcbe github.com/prometheus/tsdb v0.6.1 + github.com/uber-go/atomic v1.4.0 // indirect + github.com/uber/jaeger-client-go v2.16.0+incompatible + github.com/uber/jaeger-lib v2.0.0+incompatible go.opencensus.io v0.19.0 // indirect + go.uber.org/atomic v1.4.0 // indirect golang.org/x/net v0.0.0-20190213061140-3a22650c66bd golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 diff --git a/go.sum b/go.sum index ca3bbf0664..cb4c34740b 100644 --- a/go.sum +++ b/go.sum @@ -36,6 +36,7 @@ github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMe github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292/go.mod h1:qRiX68mZX1lGBkTWyp3CLcenw9I94W2dLeRvMzcn9N4= github.com/cockroachdb/cockroach v0.0.0-20170608034007-84bc9597164f/go.mod h1:xeT/CQ0qZHangbYbWShlCGAx31aV4AjGswDUjhKS6HQ= github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk= +github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -196,8 +197,8 @@ github.com/opentracing-contrib/go-stdlib v0.0.0-20170113013457-1de4cc2120e7/go.m github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7lZWlQw5UXuoo= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.1/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= -github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs= @@ -255,10 +256,18 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/uber-go/atomic v1.4.0 h1:yOuPqEq4ovnhEjpHmfFwsqBXDYbQeT6Nb0bwD6XnD5o= +github.com/uber-go/atomic v1.4.0/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= +github.com/uber/jaeger-client-go v2.16.0+incompatible h1:Q2Pp6v3QYiocMxomCaJuwQGFt7E53bPYqEgug/AoBtY= +github.com/uber/jaeger-client-go v2.16.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.0.0+incompatible h1:iMSCV0rmXEogjNWPh2D0xk9YVKvrtGoHJNe9ebLu/pw= +github.com/uber/jaeger-lib v2.0.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.18.1-0.20181204023538-aab39bd6a98b/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.19.0 h1:+jrnNy8MR4GZXvwF9PEuSyHxA4NaTf6601oNRwCSXq0= go.opencensus.io v0.19.0/go.mod h1:AYeH0+ZxYyghG8diqaaIq/9P3VgCCt5GF2ldCY4dkFg= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190128193316-c7b33c32a30b h1:Ib/yptP38nXZFMwqWSip+OKuMP9OkyDe3p+DssP8n9w= golang.org/x/crypto v0.0.0-20190128193316-c7b33c32a30b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= diff --git a/pkg/tracing/factory.go b/pkg/tracing/factory.go new file mode 100644 index 0000000000..abf39b098c --- /dev/null +++ b/pkg/tracing/factory.go @@ -0,0 +1,46 @@ +package tracing + +import ( + "context" + "github.com/improbable-eng/thanos/pkg/tracing/gcloud" + "github.com/improbable-eng/thanos/pkg/tracing/jaeger" + "gopkg.in/alecthomas/kingpin.v2" + "github.com/go-kit/kit/log" + "github.com/improbable-eng/thanos/pkg/tracing/factory" + "github.com/opentracing/opentracing-go" +) + +const ( + jaegerTracingType = "jaeger" + gcloudTracingType = "gcloud" +) + +// Factory - tracer factory. +type Factory struct { + FactoryConfig + factories map[string]factory.Factory +} + +// NewFactory return new tracer factory. +func NewFactory(config FactoryConfig) (*Factory) { + f := &Factory{ + FactoryConfig: config, + } + f.factories = make(map[string]factory.Factory) + + f.factories[jaegerTracingType] = jaeger.NewFactory() + f.factories[gcloudTracingType] = gcloud.NewFactory() + + return f +} + +// Create implement factoty.Factory +func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { + return f.factories[*f.FactoryConfig.TracingType].Create(ctx, logger) +} + +func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { + for _, t := range f.factories { + t.RegisterKingpinFlags(app) + } +} \ No newline at end of file diff --git a/pkg/tracing/factory/factory.go b/pkg/tracing/factory/factory.go new file mode 100644 index 0000000000..1077d1b53b --- /dev/null +++ b/pkg/tracing/factory/factory.go @@ -0,0 +1,13 @@ +package factory + +import ( + "context" + "github.com/go-kit/kit/log" + "github.com/opentracing/opentracing-go" + "gopkg.in/alecthomas/kingpin.v2" +) + +type Factory interface { + Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) + RegisterKingpinFlags(app *kingpin.Application) +} \ No newline at end of file diff --git a/pkg/tracing/factory_config.go b/pkg/tracing/factory_config.go new file mode 100644 index 0000000000..80c23bdeb7 --- /dev/null +++ b/pkg/tracing/factory_config.go @@ -0,0 +1,17 @@ +package tracing + +import "gopkg.in/alecthomas/kingpin.v2" + +// FactoryConfig save main trace configs. +type FactoryConfig struct { + TracingType *string +} + +// FactoryConfigFromKingpin create FactoryConfig from kingpin app +func FactoryConfigFromKingpin(app *kingpin.Application) FactoryConfig { + tracingType := app.Flag("tracing.type", "gcloud/jaeger.").Default("gcloud").String() + + return FactoryConfig{ + TracingType: tracingType, + } +} diff --git a/pkg/tracing/gcloud/factory.go b/pkg/tracing/gcloud/factory.go new file mode 100644 index 0000000000..63e41003c9 --- /dev/null +++ b/pkg/tracing/gcloud/factory.go @@ -0,0 +1,26 @@ +package gcloud + +import ( + "context" + "github.com/go-kit/kit/log" + "github.com/opentracing/opentracing-go" + "gopkg.in/alecthomas/kingpin.v2" +) + +type Factory struct { + gcloudTraceProjectID *string + sampleFactor *uint64 +} + +func NewFactory() *Factory { + return &Factory{} +} + +func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { + return NewOptionalGCloudTracer(ctx, logger, *f.gcloudTraceProjectID, *f.sampleFactor, "thanos-test") +} + +func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { + f.gcloudTraceProjectID = app.Flag("gcloudtrace.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled.").Default("").String() + f.sampleFactor = app.Flag("gcloudtrace.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details.").Default("1").Uint64() +} \ No newline at end of file diff --git a/pkg/tracing/gcloud/gcloud.go b/pkg/tracing/gcloud/gcloud.go new file mode 100644 index 0000000000..cbdeea4881 --- /dev/null +++ b/pkg/tracing/gcloud/gcloud.go @@ -0,0 +1,131 @@ +package gcloud + +import ( + "context" + "github.com/prometheus/common/version" + "os" + + "fmt" + + "cloud.google.com/go/trace/apiv1" + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" + "github.com/lovoo/gcloud-opentracing" + "github.com/opentracing/basictracer-go" + "github.com/opentracing/opentracing-go" +) + +const ForceTracingBaggageKey = "X-Thanos-Force-Tracing" + +type tracer struct { + debugName string + wrapped opentracing.Tracer +} + +func (t *tracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { + span := t.wrapped.StartSpan(operationName, opts...) + + if t.debugName != "" { + span.SetTag("service_name", t.debugName) + } + + // Set common tags. + if hostname := os.Getenv("HOSTNAME"); hostname != "" { + span.SetTag("hostname", hostname) + } + + span.SetTag("binary_revision", version.Revision) + if len(os.Args) > 1 { + span.SetTag("binary_cmd", os.Args[1]) + } + + return span +} + +func (t *tracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error) { + return t.wrapped.Extract(format, carrier) +} + +func (t *tracer) Inject(sm opentracing.SpanContext, format interface{}, carrier interface{}) error { + return t.wrapped.Inject(sm, format, carrier) +} + +type forceRecorder struct { + wrapped basictracer.SpanRecorder +} + +// RecordSpan invokes wrapper SpanRecorder only if Sampled field is true or ForceTracingBaggageKey item is set in span's context. +// NOTE(bplotka): Currently only HTTP supports ForceTracingBaggageKey injection on ForceTracingBaggageKey header existence. +func (r *forceRecorder) RecordSpan(sp basictracer.RawSpan) { + if force := sp.Context.Baggage[ForceTracingBaggageKey]; force != "" { + sp.Context.Sampled = true + } + + // All recorder implementation should support handling sp.Context.Sampled. + r.wrapped.RecordSpan(sp) +} + + +type gcloudRecorderLogger struct { + logger log.Logger +} + +func (l *gcloudRecorderLogger) Infof(format string, args ...interface{}) { + level.Info(l.logger).Log("msg", fmt.Sprintf(format, args...)) +} + +func (l *gcloudRecorderLogger) Errorf(format string, args ...interface{}) { + level.Error(l.logger).Log("msg", fmt.Sprintf(format, args...)) +} + +// NewOptionalGCloudTracer returns GoogleCloudTracer Tracer. In case of error it log warning and returns noop tracer. +func NewOptionalGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error) { + if gcloudTraceProjectID == "" { + level.Warn(logger).Log("msg", "gcloudtrace.project is empty. Google Cloud Tracer. Tracing will be disabled") + return &opentracing.NoopTracer{}, func() error { return nil } + } + + tracer, closeFn, err := newGCloudTracer(ctx, logger, gcloudTraceProjectID, sampleFactor, debugName) + if err != nil { + level.Warn(logger).Log("msg", "failed to init Google Cloud Tracer. Tracing will be disabled", "err", err) + return &opentracing.NoopTracer{}, func() error { return nil } + } + + level.Info(logger).Log("msg", "initiated Google Cloud Tracer. Tracing will be enabled", "err", err) + return tracer, closeFn +} + +func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error, error) { + traceClient, err := trace.NewClient(ctx) + if err != nil { + return nil, nil, err + } + + r, err := gcloudtracer.NewRecorder( + ctx, + gcloudTraceProjectID, + traceClient, + gcloudtracer.WithLogger(&gcloudRecorderLogger{logger: logger})) + if err != nil { + return nil, traceClient.Close, err + } + + shouldSample := func(traceID uint64) bool { + // Set the sampling rate. + return traceID%sampleFactor == 0 + } + if sampleFactor < 1 { + level.Debug(logger).Log("msg", "Tracing is enabled, but sampling is 0 which means only spans with 'force tracing' baggage will enable tracing.") + shouldSample = func(_ uint64) bool { + return false + } + } + return &tracer{ + debugName: debugName, + wrapped: basictracer.NewWithOptions(basictracer.Options{ + ShouldSample: shouldSample, + Recorder: &forceRecorder{wrapped: r}, + MaxLogsPerSpan: 100, + }), + }, r.Close, nil +} \ No newline at end of file diff --git a/pkg/tracing/gct.go b/pkg/tracing/gct.go index 4a2872bb25..bb851b46e5 100644 --- a/pkg/tracing/gct.go +++ b/pkg/tracing/gct.go @@ -1,78 +1,78 @@ -// Package gct contains initialization for Google Cloud Trace opentracing.Tracer. +//// Package gct contains initialization for Google Cloud Trace opentracing.Tracer. package tracing - -import ( - "context" - - "fmt" - - trace "cloud.google.com/go/trace/apiv1" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" - gcloudtracer "github.com/lovoo/gcloud-opentracing" - "github.com/opentracing/basictracer-go" - "github.com/opentracing/opentracing-go" -) - -type gcloudRecorderLogger struct { - logger log.Logger -} - -func (l *gcloudRecorderLogger) Infof(format string, args ...interface{}) { - level.Info(l.logger).Log("msg", fmt.Sprintf(format, args...)) -} - -func (l *gcloudRecorderLogger) Errorf(format string, args ...interface{}) { - level.Error(l.logger).Log("msg", fmt.Sprintf(format, args...)) -} - -// NewOptionalGCloudTracer returns GoogleCloudTracer Tracer. In case of error it log warning and returns noop tracer. -func NewOptionalGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error) { - if gcloudTraceProjectID == "" { - return &opentracing.NoopTracer{}, func() error { return nil } - } - - tracer, closeFn, err := newGCloudTracer(ctx, logger, gcloudTraceProjectID, sampleFactor, debugName) - if err != nil { - level.Warn(logger).Log("msg", "failed to init Google Cloud Tracer. Tracing will be disabled", "err", err) - return &opentracing.NoopTracer{}, func() error { return nil } - } - - level.Info(logger).Log("msg", "initiated Google Cloud Tracer. Tracing will be enabled", "err", err) - return tracer, closeFn -} - -func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error, error) { - traceClient, err := trace.NewClient(ctx) - if err != nil { - return nil, nil, err - } - - r, err := gcloudtracer.NewRecorder( - ctx, - gcloudTraceProjectID, - traceClient, - gcloudtracer.WithLogger(&gcloudRecorderLogger{logger: logger})) - if err != nil { - return nil, traceClient.Close, err - } - - shouldSample := func(traceID uint64) bool { - // Set the sampling rate. - return traceID%sampleFactor == 0 - } - if sampleFactor < 1 { - level.Debug(logger).Log("msg", "Tracing is enabled, but sampling is 0 which means only spans with 'force tracing' baggage will enable tracing.") - shouldSample = func(_ uint64) bool { - return false - } - } - return &tracer{ - debugName: debugName, - wrapped: basictracer.NewWithOptions(basictracer.Options{ - ShouldSample: shouldSample, - Recorder: &forceRecorder{wrapped: r}, - MaxLogsPerSpan: 100, - }), - }, r.Close, nil -} +// +//import ( +// "context" +// +// "fmt" +// +// trace "cloud.google.com/go/trace/apiv1" +// "github.com/go-kit/kit/log" +// "github.com/go-kit/kit/log/level" +// gcloudtracer "github.com/lovoo/gcloud-opentracing" +// "github.com/opentracing/basictracer-go" +// "github.com/opentracing/opentracing-go" +//) +// +//type gcloudRecorderLogger struct { +// logger log.Logger +//} +// +//func (l *gcloudRecorderLogger) Infof(format string, args ...interface{}) { +// level.Info(l.logger).Log("msg", fmt.Sprintf(format, args...)) +//} +// +//func (l *gcloudRecorderLogger) Errorf(format string, args ...interface{}) { +// level.Error(l.logger).Log("msg", fmt.Sprintf(format, args...)) +//} +// +//// NewOptionalGCloudTracer returns GoogleCloudTracer Tracer. In case of error it log warning and returns noop tracer. +//func NewOptionalGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error) { +// if gcloudTraceProjectID == "" { +// return &opentracing.NoopTracer{}, func() error { return nil } +// } +// +// tracer, closeFn, err := newGCloudTracer(ctx, logger, gcloudTraceProjectID, sampleFactor, debugName) +// if err != nil { +// level.Warn(logger).Log("msg", "failed to init Google Cloud Tracer. Tracing will be disabled", "err", err) +// return &opentracing.NoopTracer{}, func() error { return nil } +// } +// +// level.Info(logger).Log("msg", "initiated Google Cloud Tracer. Tracing will be enabled", "err", err) +// return tracer, closeFn +//} +// +//func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error, error) { +// traceClient, err := trace.NewClient(ctx) +// if err != nil { +// return nil, nil, err +// } +// +// r, err := gcloudtracer.NewRecorder( +// ctx, +// gcloudTraceProjectID, +// traceClient, +// gcloudtracer.WithLogger(&gcloudRecorderLogger{logger: logger})) +// if err != nil { +// return nil, traceClient.Close, err +// } +// +// shouldSample := func(traceID uint64) bool { +// // Set the sampling rate. +// return traceID%sampleFactor == 0 +// } +// if sampleFactor < 1 { +// level.Debug(logger).Log("msg", "Tracing is enabled, but sampling is 0 which means only spans with 'force tracing' baggage will enable tracing.") +// shouldSample = func(_ uint64) bool { +// return false +// } +// } +// return &tracer{ +// debugName: debugName, +// wrapped: basictracer.NewWithOptions(basictracer.Options{ +// ShouldSample: shouldSample, +// Recorder: &forceRecorder{wrapped: r}, +// MaxLogsPerSpan: 100, +// }), +// }, r.Close, nil +//} diff --git a/pkg/tracing/http.go b/pkg/tracing/http.go index 3020e2caa9..9eef63d1ba 100644 --- a/pkg/tracing/http.go +++ b/pkg/tracing/http.go @@ -10,6 +10,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" + "github.com/improbable-eng/thanos/pkg/tracing/gcloud" ) // HTTPMiddleware returns HTTP handler that injects given tracer and starts new server span. If any client span is fetched @@ -32,7 +33,7 @@ func HTTPMiddleware(tracer opentracing.Tracer, name string, logger log.Logger, n ext.HTTPUrl.Set(span, r.URL.String()) // If client specified ForceTracingBaggageKey header, ensure span includes it to force tracing. - span.SetBaggageItem(ForceTracingBaggageKey, r.Header.Get(ForceTracingBaggageKey)) + span.SetBaggageItem(gcloud.ForceTracingBaggageKey, r.Header.Get(gcloud.ForceTracingBaggageKey)) next.ServeHTTP(w, r.WithContext(opentracing.ContextWithSpan(ContextWithTracer(r.Context(), tracer), span))) span.Finish() diff --git a/pkg/tracing/jaeger/factory.go b/pkg/tracing/jaeger/factory.go new file mode 100644 index 0000000000..0ab596b491 --- /dev/null +++ b/pkg/tracing/jaeger/factory.go @@ -0,0 +1,44 @@ +package jaeger + +import ( + "context" + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" + "github.com/opentracing/opentracing-go" + "github.com/uber/jaeger-client-go/config" + "github.com/uber/jaeger-lib/metrics/prometheus" + "gopkg.in/alecthomas/kingpin.v2" + jaeger_log "github.com/uber/jaeger-client-go/log" +) + +type Factory struct { + serviceName *string +} + +func NewFactory() *Factory { + return &Factory{} +} + +func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { + cfg, err := config.FromEnv() + cfg.Sampler.Type = "const" + cfg.Sampler.Param = 1 + cfg.Reporter.LogSpans = true + cfg.ServiceName = *f.serviceName + + jLogger := jaeger_log.StdLogger + jMetricsFactory := prometheus.New() + tracer, closer, err := cfg.NewTracer( + config.Metrics(jMetricsFactory), + config.Logger(jLogger), + ) + if err != nil { + level.Warn(logger).Log("msg", "failed to init Jaeger Tracer. Tracing will be disabled", "err", err) + return &opentracing.NoopTracer{}, func() error { return nil } + } + return tracer, closer.Close +} + +func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { + f.serviceName = app.Flag("jaeger.service-name", "Jaeger service_name. If empty, tracing will be disabled.").Default("").String() +} \ No newline at end of file diff --git a/pkg/tracing/tracing.go b/pkg/tracing/tracing.go index 22b394bfbb..e582e9ff9d 100644 --- a/pkg/tracing/tracing.go +++ b/pkg/tracing/tracing.go @@ -1,17 +1,11 @@ package tracing import ( - "os" - "context" - "github.com/opentracing/basictracer-go" "github.com/opentracing/opentracing-go" - "github.com/prometheus/common/version" ) -const ForceTracingBaggageKey = "X-Thanos-Force-Tracing" - type contextKey struct{} var tracerKey = contextKey{} @@ -45,51 +39,3 @@ func StartSpan(ctx context.Context, operationName string, opts ...opentracing.St span = tracer.StartSpan(operationName, opts...) return span, opentracing.ContextWithSpan(ctx, span) } - -type tracer struct { - debugName string - wrapped opentracing.Tracer -} - -func (t *tracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { - span := t.wrapped.StartSpan(operationName, opts...) - - if t.debugName != "" { - span.SetTag("service_name", t.debugName) - } - - // Set common tags. - if hostname := os.Getenv("HOSTNAME"); hostname != "" { - span.SetTag("hostname", hostname) - } - - span.SetTag("binary_revision", version.Revision) - if len(os.Args) > 1 { - span.SetTag("binary_cmd", os.Args[1]) - } - - return span -} - -func (t *tracer) Extract(format interface{}, carrier interface{}) (opentracing.SpanContext, error) { - return t.wrapped.Extract(format, carrier) -} - -func (t *tracer) Inject(sm opentracing.SpanContext, format interface{}, carrier interface{}) error { - return t.wrapped.Inject(sm, format, carrier) -} - -type forceRecorder struct { - wrapped basictracer.SpanRecorder -} - -// RecordSpan invokes wrapper SpanRecorder only if Sampled field is true or ForceTracingBaggageKey item is set in span's context. -// NOTE(bplotka): Currently only HTTP supports ForceTracingBaggageKey injection on ForceTracingBaggageKey header existence. -func (r *forceRecorder) RecordSpan(sp basictracer.RawSpan) { - if force := sp.Context.Baggage[ForceTracingBaggageKey]; force != "" { - sp.Context.Sampled = true - } - - // All recorder implementation should support handling sp.Context.Sampled. - r.wrapped.RecordSpan(sp) -} diff --git a/pkg/tracing/tracing_test.go b/pkg/tracing/tracing_test.go index 7516137e0d..599706c7b9 100644 --- a/pkg/tracing/tracing_test.go +++ b/pkg/tracing/tracing_test.go @@ -1,162 +1,162 @@ -// This file includes unit tests that test only tiny logic in this package, but are here mainly as a showcase on how tracing can -// be configured. - +//// This file includes unit tests that test only tiny logic in this package, but are here mainly as a showcase on how tracing can +//// be configured. +// package tracing - -import ( - "testing" - - "context" - - "time" - - "github.com/fortytw2/leaktest" - "github.com/improbable-eng/thanos/pkg/testutil" - "github.com/opentracing/basictracer-go" -) - -// This test shows that if sample factor will enable tracing on client process, even when it would be disabled on server -// it will be still enabled for all spans within this span. -func TestContextTracing_ClientEnablesTracing(t *testing.T) { - defer leaktest.CheckTimeout(t, 10*time.Second)() - - m := &basictracer.InMemorySpanRecorder{} - r := &forceRecorder{wrapped: m} - - clientTracer := &tracer{ - debugName: "Test", - wrapped: basictracer.NewWithOptions(basictracer.Options{ - ShouldSample: func(traceID uint64) bool { - return true - }, - Recorder: r, - MaxLogsPerSpan: 100, - }), - } - - clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") - - // Simulate Server process with different tracer, but with client span in context. - srvTracer := &tracer{ - debugName: "Test", - wrapped: basictracer.NewWithOptions(basictracer.Options{ - ShouldSample: func(traceID uint64) bool { - return false - }, - Recorder: r, - MaxLogsPerSpan: 100, - }), - } - srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") - srvChild, _ := StartSpan(srvCtx, "bb") - testutil.Equals(t, 0, len(m.GetSpans())) - - srvChild.Finish() - testutil.Equals(t, 1, len(m.GetSpans())) - testutil.Equals(t, 1, len(m.GetSampledSpans())) - - srvRoot.Finish() - testutil.Equals(t, 2, len(m.GetSpans())) - testutil.Equals(t, 2, len(m.GetSampledSpans())) - - clientRoot.Finish() - testutil.Equals(t, 3, len(m.GetSpans())) - testutil.Equals(t, 3, len(m.GetSampledSpans())) -} - -// This test shows that if sample factor will disable tracing on client process, even when it would be enabled on server -// it will be still disabled for all spans within this span. -func TestContextTracing_ClientDisablesTracing(t *testing.T) { - m := &basictracer.InMemorySpanRecorder{} - r := &forceRecorder{wrapped: m} - - clientTracer := &tracer{ - debugName: "Test", - wrapped: basictracer.NewWithOptions(basictracer.Options{ - ShouldSample: func(traceID uint64) bool { - return false - }, - Recorder: r, - MaxLogsPerSpan: 100, - }), - } - - clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") - - // Simulate Server process with different tracer, but with client span in context. - srvTracer := &tracer{ - debugName: "Test", - wrapped: basictracer.NewWithOptions(basictracer.Options{ - ShouldSample: func(traceID uint64) bool { - return true - }, - Recorder: r, - MaxLogsPerSpan: 100, - }), - } - srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") - srvChild, _ := StartSpan(srvCtx, "bb") - testutil.Equals(t, 0, len(m.GetSpans())) - - srvChild.Finish() - testutil.Equals(t, 1, len(m.GetSpans())) - testutil.Equals(t, 0, len(m.GetSampledSpans())) - - srvRoot.Finish() - testutil.Equals(t, 2, len(m.GetSpans())) - testutil.Equals(t, 0, len(m.GetSampledSpans())) - - clientRoot.Finish() - testutil.Equals(t, 3, len(m.GetSpans())) - testutil.Equals(t, 0, len(m.GetSampledSpans())) -} - -// This test shows that if span will contain special baggage (for example from special HTTP header), even when sample -// factor will disable client & server tracing, it will be still enabled for all spans within this span. -func TestContextTracing_ForceTracing(t *testing.T) { - m := &basictracer.InMemorySpanRecorder{} - r := &forceRecorder{wrapped: m} - - clientTracer := &tracer{ - debugName: "Test", - wrapped: basictracer.NewWithOptions(basictracer.Options{ - ShouldSample: func(traceID uint64) bool { - return false - }, - Recorder: r, - MaxLogsPerSpan: 100, - }), - } - - clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") - - // Force tracing for this span and its children. - clientRoot.SetBaggageItem(ForceTracingBaggageKey, "Go for it") - - // Simulate Server process with different tracer, but with client span in context. - srvTracer := &tracer{ - debugName: "Test", - wrapped: basictracer.NewWithOptions(basictracer.Options{ - ShouldSample: func(traceID uint64) bool { - return false - }, - Recorder: r, - MaxLogsPerSpan: 100, - }), - } - srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") - srvChild, _ := StartSpan(srvCtx, "bb") - testutil.Equals(t, 0, len(m.GetSpans())) - - srvChild.Finish() - testutil.Equals(t, 1, len(m.GetSpans())) - testutil.Equals(t, 1, len(m.GetSampledSpans())) - - srvRoot.Finish() - testutil.Equals(t, 2, len(m.GetSpans())) - testutil.Equals(t, 2, len(m.GetSampledSpans())) - - clientRoot.Finish() - testutil.Equals(t, 3, len(m.GetSpans())) - testutil.Equals(t, 3, len(m.GetSampledSpans())) -} +// +//import ( +// "testing" +// +// "context" +// +// "time" +// +// "github.com/fortytw2/leaktest" +// "github.com/improbable-eng/thanos/pkg/testutil" +// "github.com/opentracing/basictracer-go" +//) +// +//// This test shows that if sample factor will enable tracing on client process, even when it would be disabled on server +//// it will be still enabled for all spans within this span. +//func TestContextTracing_ClientEnablesTracing(t *testing.T) { +// defer leaktest.CheckTimeout(t, 10*time.Second)() +// +// m := &basictracer.InMemorySpanRecorder{} +// r := &forceRecorder{wrapped: m} +// +// clientTracer := &tracer{ +// debugName: "Test", +// wrapped: basictracer.NewWithOptions(basictracer.Options{ +// ShouldSample: func(traceID uint64) bool { +// return true +// }, +// Recorder: r, +// MaxLogsPerSpan: 100, +// }), +// } +// +// clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") +// +// // Simulate Server process with different tracer, but with client span in context. +// srvTracer := &tracer{ +// debugName: "Test", +// wrapped: basictracer.NewWithOptions(basictracer.Options{ +// ShouldSample: func(traceID uint64) bool { +// return false +// }, +// Recorder: r, +// MaxLogsPerSpan: 100, +// }), +// } +// srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") +// srvChild, _ := StartSpan(srvCtx, "bb") +// testutil.Equals(t, 0, len(m.GetSpans())) +// +// srvChild.Finish() +// testutil.Equals(t, 1, len(m.GetSpans())) +// testutil.Equals(t, 1, len(m.GetSampledSpans())) +// +// srvRoot.Finish() +// testutil.Equals(t, 2, len(m.GetSpans())) +// testutil.Equals(t, 2, len(m.GetSampledSpans())) +// +// clientRoot.Finish() +// testutil.Equals(t, 3, len(m.GetSpans())) +// testutil.Equals(t, 3, len(m.GetSampledSpans())) +//} +// +//// This test shows that if sample factor will disable tracing on client process, even when it would be enabled on server +//// it will be still disabled for all spans within this span. +//func TestContextTracing_ClientDisablesTracing(t *testing.T) { +// m := &basictracer.InMemorySpanRecorder{} +// r := &forceRecorder{wrapped: m} +// +// clientTracer := &tracer{ +// debugName: "Test", +// wrapped: basictracer.NewWithOptions(basictracer.Options{ +// ShouldSample: func(traceID uint64) bool { +// return false +// }, +// Recorder: r, +// MaxLogsPerSpan: 100, +// }), +// } +// +// clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") +// +// // Simulate Server process with different tracer, but with client span in context. +// srvTracer := &tracer{ +// debugName: "Test", +// wrapped: basictracer.NewWithOptions(basictracer.Options{ +// ShouldSample: func(traceID uint64) bool { +// return true +// }, +// Recorder: r, +// MaxLogsPerSpan: 100, +// }), +// } +// srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") +// srvChild, _ := StartSpan(srvCtx, "bb") +// testutil.Equals(t, 0, len(m.GetSpans())) +// +// srvChild.Finish() +// testutil.Equals(t, 1, len(m.GetSpans())) +// testutil.Equals(t, 0, len(m.GetSampledSpans())) +// +// srvRoot.Finish() +// testutil.Equals(t, 2, len(m.GetSpans())) +// testutil.Equals(t, 0, len(m.GetSampledSpans())) +// +// clientRoot.Finish() +// testutil.Equals(t, 3, len(m.GetSpans())) +// testutil.Equals(t, 0, len(m.GetSampledSpans())) +//} +// +//// This test shows that if span will contain special baggage (for example from special HTTP header), even when sample +//// factor will disable client & server tracing, it will be still enabled for all spans within this span. +//func TestContextTracing_ForceTracing(t *testing.T) { +// m := &basictracer.InMemorySpanRecorder{} +// r := &forceRecorder{wrapped: m} +// +// clientTracer := &tracer{ +// debugName: "Test", +// wrapped: basictracer.NewWithOptions(basictracer.Options{ +// ShouldSample: func(traceID uint64) bool { +// return false +// }, +// Recorder: r, +// MaxLogsPerSpan: 100, +// }), +// } +// +// clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") +// +// // Force tracing for this span and its children. +// clientRoot.SetBaggageItem(ForceTracingBaggageKey, "Go for it") +// +// // Simulate Server process with different tracer, but with client span in context. +// srvTracer := &tracer{ +// debugName: "Test", +// wrapped: basictracer.NewWithOptions(basictracer.Options{ +// ShouldSample: func(traceID uint64) bool { +// return false +// }, +// Recorder: r, +// MaxLogsPerSpan: 100, +// }), +// } +// srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") +// srvChild, _ := StartSpan(srvCtx, "bb") +// testutil.Equals(t, 0, len(m.GetSpans())) +// +// srvChild.Finish() +// testutil.Equals(t, 1, len(m.GetSpans())) +// testutil.Equals(t, 1, len(m.GetSampledSpans())) +// +// srvRoot.Finish() +// testutil.Equals(t, 2, len(m.GetSpans())) +// testutil.Equals(t, 2, len(m.GetSampledSpans())) +// +// clientRoot.Finish() +// testutil.Equals(t, 3, len(m.GetSpans())) +// testutil.Equals(t, 3, len(m.GetSampledSpans())) +//} From 0e3f2eb53bac302faafacd8af23192556183fe5b Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Wed, 8 May 2019 18:50:07 +0300 Subject: [PATCH 02/35] Remove comments --- cmd/thanos/main.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index ff0150c6a9..613d1b7307 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -65,21 +65,9 @@ func main() { logFormat := app.Flag("log.format", "Log format to use."). Default(logFormatLogfmt).Enum(logFormatLogfmt, logFormatJson) - // tracerFactory := tracing.Newfactory(tracing.FactoryConfigFromKingPin(app)) - // tracerConfig := tracing.FactoryConfigFromKingPin(app) - //tracingFactory, _ := tracing.NewFactory(tracing.FactoryConfigFromKingpin(app)) tracingFactory := tracing.NewFactory(tracing.FactoryConfigFromKingpin(app)) tracingFactory.RegisterKingpinFlags(app) - // tracing.ParseFlags(app) - // tracer.Configure(app) - // tracingType := app.Flag("tracing.type", "gcloud/jaeger.").Default("gcloud").String() - - // gcloudTraceProject := app.Flag("gcloudtrace.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled."). - // String() - // gcloudTraceSampleFactor := app.Flag("gcloudtrace.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details."). - // Default("1").Uint64() - cmds := map[string]setupFunc{} registerSidecar(cmds, app, "sidecar") registerStore(cmds, app, "store") @@ -157,8 +145,6 @@ func main() { tracer, closeFn = tracingFactory.Create(ctx, logger) - // tracer, closeFn = tracing.NewOptionalGCloudTracer(ctx, logger, *gcloudTraceProject, *gcloudTraceSampleFactor, *debugName) - // This is bad, but Prometheus does not support any other tracer injections than just global one. // TODO(bplotka): Work with basictracer to handle gracefully tracker mismatches, and also with Prometheus to allow // tracer injection. From 39e9bcb1adb117abb8667d179a1f940d5082dd2e Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Wed, 8 May 2019 18:50:52 +0300 Subject: [PATCH 03/35] Remove comments --- pkg/tracing/gct.go | 78 ---------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 pkg/tracing/gct.go diff --git a/pkg/tracing/gct.go b/pkg/tracing/gct.go deleted file mode 100644 index bb851b46e5..0000000000 --- a/pkg/tracing/gct.go +++ /dev/null @@ -1,78 +0,0 @@ -//// Package gct contains initialization for Google Cloud Trace opentracing.Tracer. -package tracing -// -//import ( -// "context" -// -// "fmt" -// -// trace "cloud.google.com/go/trace/apiv1" -// "github.com/go-kit/kit/log" -// "github.com/go-kit/kit/log/level" -// gcloudtracer "github.com/lovoo/gcloud-opentracing" -// "github.com/opentracing/basictracer-go" -// "github.com/opentracing/opentracing-go" -//) -// -//type gcloudRecorderLogger struct { -// logger log.Logger -//} -// -//func (l *gcloudRecorderLogger) Infof(format string, args ...interface{}) { -// level.Info(l.logger).Log("msg", fmt.Sprintf(format, args...)) -//} -// -//func (l *gcloudRecorderLogger) Errorf(format string, args ...interface{}) { -// level.Error(l.logger).Log("msg", fmt.Sprintf(format, args...)) -//} -// -//// NewOptionalGCloudTracer returns GoogleCloudTracer Tracer. In case of error it log warning and returns noop tracer. -//func NewOptionalGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error) { -// if gcloudTraceProjectID == "" { -// return &opentracing.NoopTracer{}, func() error { return nil } -// } -// -// tracer, closeFn, err := newGCloudTracer(ctx, logger, gcloudTraceProjectID, sampleFactor, debugName) -// if err != nil { -// level.Warn(logger).Log("msg", "failed to init Google Cloud Tracer. Tracing will be disabled", "err", err) -// return &opentracing.NoopTracer{}, func() error { return nil } -// } -// -// level.Info(logger).Log("msg", "initiated Google Cloud Tracer. Tracing will be enabled", "err", err) -// return tracer, closeFn -//} -// -//func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error, error) { -// traceClient, err := trace.NewClient(ctx) -// if err != nil { -// return nil, nil, err -// } -// -// r, err := gcloudtracer.NewRecorder( -// ctx, -// gcloudTraceProjectID, -// traceClient, -// gcloudtracer.WithLogger(&gcloudRecorderLogger{logger: logger})) -// if err != nil { -// return nil, traceClient.Close, err -// } -// -// shouldSample := func(traceID uint64) bool { -// // Set the sampling rate. -// return traceID%sampleFactor == 0 -// } -// if sampleFactor < 1 { -// level.Debug(logger).Log("msg", "Tracing is enabled, but sampling is 0 which means only spans with 'force tracing' baggage will enable tracing.") -// shouldSample = func(_ uint64) bool { -// return false -// } -// } -// return &tracer{ -// debugName: debugName, -// wrapped: basictracer.NewWithOptions(basictracer.Options{ -// ShouldSample: shouldSample, -// Recorder: &forceRecorder{wrapped: r}, -// MaxLogsPerSpan: 100, -// }), -// }, r.Close, nil -//} From 304f4daa454708bdd76381aa851fcb7efe8a9373 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Mon, 13 May 2019 13:13:44 +0300 Subject: [PATCH 04/35] Refactoring tracing --- cmd/thanos/main.go | 3 +- pkg/tracing/factory.go | 41 ++--------------- pkg/tracing/factory/factory.go | 13 ------ pkg/tracing/http.go | 2 +- pkg/tracing/provider/factory.go | 46 ++++++++++++++++++++ pkg/tracing/{ => provider}/factory_config.go | 2 +- pkg/tracing/{ => provider}/gcloud/factory.go | 0 pkg/tracing/{ => provider}/gcloud/gcloud.go | 0 pkg/tracing/{ => provider}/jaeger/factory.go | 4 +- 9 files changed, 57 insertions(+), 54 deletions(-) delete mode 100644 pkg/tracing/factory/factory.go create mode 100644 pkg/tracing/provider/factory.go rename pkg/tracing/{ => provider}/factory_config.go (96%) rename pkg/tracing/{ => provider}/gcloud/factory.go (100%) rename pkg/tracing/{ => provider}/gcloud/gcloud.go (100%) rename pkg/tracing/{ => provider}/jaeger/factory.go (94%) diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 613d1b7307..05932b3d1b 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -27,6 +27,7 @@ import ( grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/improbable-eng/thanos/pkg/runutil" "github.com/improbable-eng/thanos/pkg/tracing" + "github.com/improbable-eng/thanos/pkg/tracing/provider" "github.com/oklog/run" "github.com/opentracing/opentracing-go" "github.com/pkg/errors" @@ -65,7 +66,7 @@ func main() { logFormat := app.Flag("log.format", "Log format to use."). Default(logFormatLogfmt).Enum(logFormatLogfmt, logFormatJson) - tracingFactory := tracing.NewFactory(tracing.FactoryConfigFromKingpin(app)) + tracingFactory := provider.NewFactory(provider.FactoryConfigFromKingpin(app)) tracingFactory.RegisterKingpinFlags(app) cmds := map[string]setupFunc{} diff --git a/pkg/tracing/factory.go b/pkg/tracing/factory.go index abf39b098c..f0c7973898 100644 --- a/pkg/tracing/factory.go +++ b/pkg/tracing/factory.go @@ -2,45 +2,12 @@ package tracing import ( "context" - "github.com/improbable-eng/thanos/pkg/tracing/gcloud" - "github.com/improbable-eng/thanos/pkg/tracing/jaeger" - "gopkg.in/alecthomas/kingpin.v2" "github.com/go-kit/kit/log" - "github.com/improbable-eng/thanos/pkg/tracing/factory" "github.com/opentracing/opentracing-go" + "gopkg.in/alecthomas/kingpin.v2" ) -const ( - jaegerTracingType = "jaeger" - gcloudTracingType = "gcloud" -) - -// Factory - tracer factory. -type Factory struct { - FactoryConfig - factories map[string]factory.Factory -} - -// NewFactory return new tracer factory. -func NewFactory(config FactoryConfig) (*Factory) { - f := &Factory{ - FactoryConfig: config, - } - f.factories = make(map[string]factory.Factory) - - f.factories[jaegerTracingType] = jaeger.NewFactory() - f.factories[gcloudTracingType] = gcloud.NewFactory() - - return f -} - -// Create implement factoty.Factory -func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { - return f.factories[*f.FactoryConfig.TracingType].Create(ctx, logger) -} - -func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { - for _, t := range f.factories { - t.RegisterKingpinFlags(app) - } +type Factory interface { + Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) + RegisterKingpinFlags(app *kingpin.Application) } \ No newline at end of file diff --git a/pkg/tracing/factory/factory.go b/pkg/tracing/factory/factory.go deleted file mode 100644 index 1077d1b53b..0000000000 --- a/pkg/tracing/factory/factory.go +++ /dev/null @@ -1,13 +0,0 @@ -package factory - -import ( - "context" - "github.com/go-kit/kit/log" - "github.com/opentracing/opentracing-go" - "gopkg.in/alecthomas/kingpin.v2" -) - -type Factory interface { - Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) - RegisterKingpinFlags(app *kingpin.Application) -} \ No newline at end of file diff --git a/pkg/tracing/http.go b/pkg/tracing/http.go index 9eef63d1ba..3676394e30 100644 --- a/pkg/tracing/http.go +++ b/pkg/tracing/http.go @@ -10,7 +10,7 @@ import ( "github.com/go-kit/kit/log/level" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" - "github.com/improbable-eng/thanos/pkg/tracing/gcloud" + "github.com/improbable-eng/thanos/pkg/tracing/provider/gcloud" ) // HTTPMiddleware returns HTTP handler that injects given tracer and starts new server span. If any client span is fetched diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go new file mode 100644 index 0000000000..5fd1ac914a --- /dev/null +++ b/pkg/tracing/provider/factory.go @@ -0,0 +1,46 @@ +package provider + +import ( + "context" + "github.com/improbable-eng/thanos/pkg/tracing" + "github.com/improbable-eng/thanos/pkg/tracing/provider/gcloud" + "github.com/improbable-eng/thanos/pkg/tracing/provider/jaeger" + "gopkg.in/alecthomas/kingpin.v2" + "github.com/go-kit/kit/log" + "github.com/opentracing/opentracing-go" +) + +const ( + jaegerTracingType = "jaeger" + gcloudTracingType = "gcloud" +) + +// Factory - tracer factory. +type Factory struct { + FactoryConfig + factories map[string]tracing.Factory +} + +// NewFactory return new tracer factory. +func NewFactory(config FactoryConfig) (*Factory) { + f := &Factory{ + FactoryConfig: config, + } + f.factories = make(map[string]tracing.Factory) + + f.factories[jaegerTracingType] = jaeger.NewFactory() + f.factories[gcloudTracingType] = gcloud.NewFactory() + + return f +} + +// Create implement factoty.Factory +func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { + return f.factories[*f.FactoryConfig.TracingType].Create(ctx, logger) +} + +func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { + for _, t := range f.factories { + t.RegisterKingpinFlags(app) + } +} \ No newline at end of file diff --git a/pkg/tracing/factory_config.go b/pkg/tracing/provider/factory_config.go similarity index 96% rename from pkg/tracing/factory_config.go rename to pkg/tracing/provider/factory_config.go index 80c23bdeb7..2ccf4a8de4 100644 --- a/pkg/tracing/factory_config.go +++ b/pkg/tracing/provider/factory_config.go @@ -1,4 +1,4 @@ -package tracing +package provider import "gopkg.in/alecthomas/kingpin.v2" diff --git a/pkg/tracing/gcloud/factory.go b/pkg/tracing/provider/gcloud/factory.go similarity index 100% rename from pkg/tracing/gcloud/factory.go rename to pkg/tracing/provider/gcloud/factory.go diff --git a/pkg/tracing/gcloud/gcloud.go b/pkg/tracing/provider/gcloud/gcloud.go similarity index 100% rename from pkg/tracing/gcloud/gcloud.go rename to pkg/tracing/provider/gcloud/gcloud.go diff --git a/pkg/tracing/jaeger/factory.go b/pkg/tracing/provider/jaeger/factory.go similarity index 94% rename from pkg/tracing/jaeger/factory.go rename to pkg/tracing/provider/jaeger/factory.go index 0ab596b491..6c639b5e8e 100644 --- a/pkg/tracing/jaeger/factory.go +++ b/pkg/tracing/provider/jaeger/factory.go @@ -24,7 +24,9 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tr cfg.Sampler.Type = "const" cfg.Sampler.Param = 1 cfg.Reporter.LogSpans = true - cfg.ServiceName = *f.serviceName + if *f.serviceName != "" { + cfg.ServiceName = *f.serviceName + } jLogger := jaeger_log.StdLogger jMetricsFactory := prometheus.New() From bb5fa34d6c295ae13607e311b9a681d8ed68d889 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Mon, 13 May 2019 14:05:30 +0300 Subject: [PATCH 05/35] Implementing jaeger logger. --- pkg/tracing/provider/jaeger/factory.go | 5 +++-- pkg/tracing/provider/jaeger/logger.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 pkg/tracing/provider/jaeger/logger.go diff --git a/pkg/tracing/provider/jaeger/factory.go b/pkg/tracing/provider/jaeger/factory.go index 6c639b5e8e..6948ff1945 100644 --- a/pkg/tracing/provider/jaeger/factory.go +++ b/pkg/tracing/provider/jaeger/factory.go @@ -8,7 +8,6 @@ import ( "github.com/uber/jaeger-client-go/config" "github.com/uber/jaeger-lib/metrics/prometheus" "gopkg.in/alecthomas/kingpin.v2" - jaeger_log "github.com/uber/jaeger-client-go/log" ) type Factory struct { @@ -28,7 +27,9 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tr cfg.ServiceName = *f.serviceName } - jLogger := jaeger_log.StdLogger + jLogger := &jaegerLogger{ + logger: logger, + } jMetricsFactory := prometheus.New() tracer, closer, err := cfg.NewTracer( config.Metrics(jMetricsFactory), diff --git a/pkg/tracing/provider/jaeger/logger.go b/pkg/tracing/provider/jaeger/logger.go new file mode 100644 index 0000000000..6fe1912e36 --- /dev/null +++ b/pkg/tracing/provider/jaeger/logger.go @@ -0,0 +1,19 @@ +package jaeger + +import ( + "fmt" + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" +) + +type jaegerLogger struct{ + logger log.Logger +} + +func (l *jaegerLogger) Infof(format string, args ...interface{}) { + level.Info(l.logger).Log("msg", fmt.Sprintf(format, args...)) +} + +func (l *jaegerLogger) Error(msg string) { + level.Error(l.logger).Log("msg", msg) +} \ No newline at end of file From a97415a23eadc84b7c776585819ddbd548ded7f0 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Mon, 13 May 2019 14:43:58 +0300 Subject: [PATCH 06/35] Add jaeger force tracing header. --- pkg/tracing/http.go | 3 +-- pkg/tracing/provider/gcloud/gcloud.go | 5 ++--- pkg/tracing/provider/jaeger/factory.go | 10 +++++++--- pkg/tracing/tracing.go | 2 ++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/tracing/http.go b/pkg/tracing/http.go index 3676394e30..3020e2caa9 100644 --- a/pkg/tracing/http.go +++ b/pkg/tracing/http.go @@ -10,7 +10,6 @@ import ( "github.com/go-kit/kit/log/level" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" - "github.com/improbable-eng/thanos/pkg/tracing/provider/gcloud" ) // HTTPMiddleware returns HTTP handler that injects given tracer and starts new server span. If any client span is fetched @@ -33,7 +32,7 @@ func HTTPMiddleware(tracer opentracing.Tracer, name string, logger log.Logger, n ext.HTTPUrl.Set(span, r.URL.String()) // If client specified ForceTracingBaggageKey header, ensure span includes it to force tracing. - span.SetBaggageItem(gcloud.ForceTracingBaggageKey, r.Header.Get(gcloud.ForceTracingBaggageKey)) + span.SetBaggageItem(ForceTracingBaggageKey, r.Header.Get(ForceTracingBaggageKey)) next.ServeHTTP(w, r.WithContext(opentracing.ContextWithSpan(ContextWithTracer(r.Context(), tracer), span))) span.Finish() diff --git a/pkg/tracing/provider/gcloud/gcloud.go b/pkg/tracing/provider/gcloud/gcloud.go index cbdeea4881..f9642a44ed 100644 --- a/pkg/tracing/provider/gcloud/gcloud.go +++ b/pkg/tracing/provider/gcloud/gcloud.go @@ -2,6 +2,7 @@ package gcloud import ( "context" + "github.com/improbable-eng/thanos/pkg/tracing" "github.com/prometheus/common/version" "os" @@ -15,8 +16,6 @@ import ( "github.com/opentracing/opentracing-go" ) -const ForceTracingBaggageKey = "X-Thanos-Force-Tracing" - type tracer struct { debugName string wrapped opentracing.Tracer @@ -57,7 +56,7 @@ type forceRecorder struct { // RecordSpan invokes wrapper SpanRecorder only if Sampled field is true or ForceTracingBaggageKey item is set in span's context. // NOTE(bplotka): Currently only HTTP supports ForceTracingBaggageKey injection on ForceTracingBaggageKey header existence. func (r *forceRecorder) RecordSpan(sp basictracer.RawSpan) { - if force := sp.Context.Baggage[ForceTracingBaggageKey]; force != "" { + if force := sp.Context.Baggage[tracing.ForceTracingBaggageKey]; force != "" { sp.Context.Sampled = true } diff --git a/pkg/tracing/provider/jaeger/factory.go b/pkg/tracing/provider/jaeger/factory.go index 6948ff1945..108b686fc9 100644 --- a/pkg/tracing/provider/jaeger/factory.go +++ b/pkg/tracing/provider/jaeger/factory.go @@ -4,7 +4,9 @@ import ( "context" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" + "github.com/improbable-eng/thanos/pkg/tracing" "github.com/opentracing/opentracing-go" + "github.com/uber/jaeger-client-go" "github.com/uber/jaeger-client-go/config" "github.com/uber/jaeger-lib/metrics/prometheus" "gopkg.in/alecthomas/kingpin.v2" @@ -20,9 +22,10 @@ func NewFactory() *Factory { func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { cfg, err := config.FromEnv() - cfg.Sampler.Type = "const" - cfg.Sampler.Param = 1 - cfg.Reporter.LogSpans = true + cfg.Headers = &jaeger.HeadersConfig{ + JaegerDebugHeader: tracing.ForceTracingBaggageKey, + } + cfg.Headers.ApplyDefaults() if *f.serviceName != "" { cfg.ServiceName = *f.serviceName } @@ -39,6 +42,7 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tr level.Warn(logger).Log("msg", "failed to init Jaeger Tracer. Tracing will be disabled", "err", err) return &opentracing.NoopTracer{}, func() error { return nil } } + level.Info(logger).Log("msg", "initiated Jaeger Tracer. Tracing will be enabled", "err", err) return tracer, closer.Close } diff --git a/pkg/tracing/tracing.go b/pkg/tracing/tracing.go index e582e9ff9d..31c9ae486d 100644 --- a/pkg/tracing/tracing.go +++ b/pkg/tracing/tracing.go @@ -6,6 +6,8 @@ import ( "github.com/opentracing/opentracing-go" ) +const ForceTracingBaggageKey = "X-Thanos-Force-Tracing" + type contextKey struct{} var tracerKey = contextKey{} From 38d252cb9919cffeda11e92f8bff905e43dbf335 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Mon, 13 May 2019 16:13:50 +0300 Subject: [PATCH 07/35] Use debugName for tracing service-name --- cmd/thanos/main.go | 2 +- pkg/tracing/factory.go | 2 +- pkg/tracing/provider/factory.go | 4 ++-- pkg/tracing/provider/gcloud/factory.go | 4 ++-- pkg/tracing/provider/jaeger/factory.go | 8 +++----- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 05932b3d1b..26a3642d73 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -144,7 +144,7 @@ func main() { var closeFn func() error - tracer, closeFn = tracingFactory.Create(ctx, logger) + tracer, closeFn = tracingFactory.Create(ctx, logger, *debugName) // This is bad, but Prometheus does not support any other tracer injections than just global one. // TODO(bplotka): Work with basictracer to handle gracefully tracker mismatches, and also with Prometheus to allow diff --git a/pkg/tracing/factory.go b/pkg/tracing/factory.go index f0c7973898..b2fe4a5fc5 100644 --- a/pkg/tracing/factory.go +++ b/pkg/tracing/factory.go @@ -8,6 +8,6 @@ import ( ) type Factory interface { - Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) + Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) RegisterKingpinFlags(app *kingpin.Application) } \ No newline at end of file diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index 5fd1ac914a..e865cd746c 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -35,8 +35,8 @@ func NewFactory(config FactoryConfig) (*Factory) { } // Create implement factoty.Factory -func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { - return f.factories[*f.FactoryConfig.TracingType].Create(ctx, logger) +func (f *Factory) Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) { + return f.factories[*f.FactoryConfig.TracingType].Create(ctx, logger, debugName) } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { diff --git a/pkg/tracing/provider/gcloud/factory.go b/pkg/tracing/provider/gcloud/factory.go index 63e41003c9..74acda3be2 100644 --- a/pkg/tracing/provider/gcloud/factory.go +++ b/pkg/tracing/provider/gcloud/factory.go @@ -16,8 +16,8 @@ func NewFactory() *Factory { return &Factory{} } -func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { - return NewOptionalGCloudTracer(ctx, logger, *f.gcloudTraceProjectID, *f.sampleFactor, "thanos-test") +func (f *Factory) Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) { + return NewOptionalGCloudTracer(ctx, logger, *f.gcloudTraceProjectID, *f.sampleFactor, debugName) } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { diff --git a/pkg/tracing/provider/jaeger/factory.go b/pkg/tracing/provider/jaeger/factory.go index 108b686fc9..d7c6611530 100644 --- a/pkg/tracing/provider/jaeger/factory.go +++ b/pkg/tracing/provider/jaeger/factory.go @@ -13,21 +13,20 @@ import ( ) type Factory struct { - serviceName *string } func NewFactory() *Factory { return &Factory{} } -func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tracer, func() error) { +func (f *Factory) Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) { cfg, err := config.FromEnv() cfg.Headers = &jaeger.HeadersConfig{ JaegerDebugHeader: tracing.ForceTracingBaggageKey, } cfg.Headers.ApplyDefaults() - if *f.serviceName != "" { - cfg.ServiceName = *f.serviceName + if debugName != "" { + cfg.ServiceName = debugName } jLogger := &jaegerLogger{ @@ -47,5 +46,4 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger) (opentracing.Tr } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { - f.serviceName = app.Flag("jaeger.service-name", "Jaeger service_name. If empty, tracing will be disabled.").Default("").String() } \ No newline at end of file From 4c03137adcccfad00938831a21baf32934f977fa Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Mon, 13 May 2019 16:50:46 +0300 Subject: [PATCH 08/35] RemoveFactory config --- cmd/thanos/main.go | 2 +- pkg/tracing/provider/factory.go | 11 +++++------ pkg/tracing/provider/factory_config.go | 17 ----------------- 3 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 pkg/tracing/provider/factory_config.go diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 26a3642d73..6968cfd515 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -66,7 +66,7 @@ func main() { logFormat := app.Flag("log.format", "Log format to use."). Default(logFormatLogfmt).Enum(logFormatLogfmt, logFormatJson) - tracingFactory := provider.NewFactory(provider.FactoryConfigFromKingpin(app)) + tracingFactory := provider.NewFactory() tracingFactory.RegisterKingpinFlags(app) cmds := map[string]setupFunc{} diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index e865cd746c..6352949edf 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -17,15 +17,13 @@ const ( // Factory - tracer factory. type Factory struct { - FactoryConfig + tracingType *string factories map[string]tracing.Factory } // NewFactory return new tracer factory. -func NewFactory(config FactoryConfig) (*Factory) { - f := &Factory{ - FactoryConfig: config, - } +func NewFactory() (*Factory) { + f := &Factory{} f.factories = make(map[string]tracing.Factory) f.factories[jaegerTracingType] = jaeger.NewFactory() @@ -36,10 +34,11 @@ func NewFactory(config FactoryConfig) (*Factory) { // Create implement factoty.Factory func (f *Factory) Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) { - return f.factories[*f.FactoryConfig.TracingType].Create(ctx, logger, debugName) + return f.factories[*f.tracingType].Create(ctx, logger, debugName) } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { + f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default("jaeger").String() for _, t := range f.factories { t.RegisterKingpinFlags(app) } diff --git a/pkg/tracing/provider/factory_config.go b/pkg/tracing/provider/factory_config.go deleted file mode 100644 index 2ccf4a8de4..0000000000 --- a/pkg/tracing/provider/factory_config.go +++ /dev/null @@ -1,17 +0,0 @@ -package provider - -import "gopkg.in/alecthomas/kingpin.v2" - -// FactoryConfig save main trace configs. -type FactoryConfig struct { - TracingType *string -} - -// FactoryConfigFromKingpin create FactoryConfig from kingpin app -func FactoryConfigFromKingpin(app *kingpin.Application) FactoryConfig { - tracingType := app.Flag("tracing.type", "gcloud/jaeger.").Default("gcloud").String() - - return FactoryConfig{ - TracingType: tracingType, - } -} From 3869ce40820da96d7cfb0a7b1b99f00510d33f1c Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 14 May 2019 14:07:49 +0300 Subject: [PATCH 09/35] Formatting fix; Use io.Closer intead func() error --- benchmark/cmd/thanosbench/main.go | 2 +- benchmark/cmd/thanosbench/resources.go | 2 +- cmd/thanos/main.go | 8 ++-- go.sum | 1 + pkg/tracing/factory.go | 6 ++- pkg/tracing/provider/factory.go | 29 +++++++----- pkg/tracing/provider/gcloud/factory.go | 26 +++++++++-- .../provider/gcloud/{gcloud.go => tracer.go} | 44 ++++++------------- pkg/tracing/provider/jaeger/factory.go | 21 ++++++--- pkg/tracing/provider/jaeger/logger.go | 5 ++- pkg/tracing/provider/noop/factory.go | 25 +++++++++++ pkg/tracing/provider/noop/tracer.go | 11 +++++ 12 files changed, 118 insertions(+), 62 deletions(-) rename pkg/tracing/provider/gcloud/{gcloud.go => tracer.go} (70%) create mode 100644 pkg/tracing/provider/noop/factory.go create mode 100644 pkg/tracing/provider/noop/tracer.go diff --git a/benchmark/cmd/thanosbench/main.go b/benchmark/cmd/thanosbench/main.go index c412e11718..d38907f866 100644 --- a/benchmark/cmd/thanosbench/main.go +++ b/benchmark/cmd/thanosbench/main.go @@ -7,7 +7,7 @@ import ( "github.com/go-kit/kit/log" "github.com/prometheus/common/version" - kingpin "gopkg.in/alecthomas/kingpin.v2" + "gopkg.in/alecthomas/kingpin.v2" "k8s.io/client-go/tools/clientcmd" ) diff --git a/benchmark/cmd/thanosbench/resources.go b/benchmark/cmd/thanosbench/resources.go index c76cac5f48..44626d14e0 100644 --- a/benchmark/cmd/thanosbench/resources.go +++ b/benchmark/cmd/thanosbench/resources.go @@ -10,7 +10,7 @@ import ( "github.com/pkg/errors" "github.com/prometheus/common/model" prom "github.com/prometheus/prometheus/config" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 6968cfd515..72d4f2e295 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -16,6 +16,7 @@ import ( "runtime" "runtime/debug" "syscall" + "io" gmetrics "github.com/armon/go-metrics" @@ -142,9 +143,10 @@ func main() { { ctx := context.Background() - var closeFn func() error + //var closeFn func() error + var closer io.Closer - tracer, closeFn = tracingFactory.Create(ctx, logger, *debugName) + tracer, closer = tracingFactory.Create(ctx, logger, *debugName) // This is bad, but Prometheus does not support any other tracer injections than just global one. // TODO(bplotka): Work with basictracer to handle gracefully tracker mismatches, and also with Prometheus to allow @@ -156,7 +158,7 @@ func main() { <-ctx.Done() return ctx.Err() }, func(error) { - if err := closeFn(); err != nil { + if err := closer.Close(); err != nil { level.Warn(logger).Log("msg", "closing tracer failed", "err", err) } cancel() diff --git a/go.sum b/go.sum index cb4c34740b..9b29f403c0 100644 --- a/go.sum +++ b/go.sum @@ -300,6 +300,7 @@ golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/time v0.0.0-20170424234030-8be79e1e0910 h1:bCMaBn7ph495H+x72gEvgcv+mDRd9dElbzo/mVCMxX4= golang.org/x/time v0.0.0-20170424234030-8be79e1e0910/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181023010539-40a48ad93fbe/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/pkg/tracing/factory.go b/pkg/tracing/factory.go index b2fe4a5fc5..41ec1433ef 100644 --- a/pkg/tracing/factory.go +++ b/pkg/tracing/factory.go @@ -2,12 +2,14 @@ package tracing import ( "context" + "io" + "github.com/go-kit/kit/log" "github.com/opentracing/opentracing-go" "gopkg.in/alecthomas/kingpin.v2" ) type Factory interface { - Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) + Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) RegisterKingpinFlags(app *kingpin.Application) -} \ No newline at end of file +} diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index 6352949edf..756d229e78 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -2,44 +2,49 @@ package provider import ( "context" + "io" + + "github.com/go-kit/kit/log" "github.com/improbable-eng/thanos/pkg/tracing" "github.com/improbable-eng/thanos/pkg/tracing/provider/gcloud" "github.com/improbable-eng/thanos/pkg/tracing/provider/jaeger" - "gopkg.in/alecthomas/kingpin.v2" - "github.com/go-kit/kit/log" + "github.com/improbable-eng/thanos/pkg/tracing/provider/noop" "github.com/opentracing/opentracing-go" + "gopkg.in/alecthomas/kingpin.v2" ) const ( - jaegerTracingType = "jaeger" - gcloudTracingType = "gcloud" + jaegerTraceType = "jaeger" + gcloudTraceType = "gcloud" + noopTraceType = "noop" ) // Factory - tracer factory. type Factory struct { tracingType *string - factories map[string]tracing.Factory + factories map[string]tracing.Factory } // NewFactory return new tracer factory. -func NewFactory() (*Factory) { +func NewFactory() *Factory { f := &Factory{} f.factories = make(map[string]tracing.Factory) - f.factories[jaegerTracingType] = jaeger.NewFactory() - f.factories[gcloudTracingType] = gcloud.NewFactory() + f.factories[jaegerTraceType] = jaeger.NewFactory() + f.factories[gcloudTraceType] = gcloud.NewFactory() + f.factories[noopTraceType] = noop.NewFactory() return f } // Create implement factoty.Factory -func (f *Factory) Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) { - return f.factories[*f.tracingType].Create(ctx, logger, debugName) +func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { + return f.factories[*f.tracingType].Create(ctx, logger, serviceName) } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { - f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default("jaeger").String() + f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default("noop").String() for _, t := range f.factories { t.RegisterKingpinFlags(app) } -} \ No newline at end of file +} diff --git a/pkg/tracing/provider/gcloud/factory.go b/pkg/tracing/provider/gcloud/factory.go index 74acda3be2..2bfda31534 100644 --- a/pkg/tracing/provider/gcloud/factory.go +++ b/pkg/tracing/provider/gcloud/factory.go @@ -2,25 +2,43 @@ package gcloud import ( "context" + "io" + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" + "github.com/improbable-eng/thanos/pkg/tracing/provider/noop" "github.com/opentracing/opentracing-go" "gopkg.in/alecthomas/kingpin.v2" ) type Factory struct { gcloudTraceProjectID *string - sampleFactor *uint64 + sampleFactor *uint64 } func NewFactory() *Factory { return &Factory{} } -func (f *Factory) Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) { - return NewOptionalGCloudTracer(ctx, logger, *f.gcloudTraceProjectID, *f.sampleFactor, debugName) +func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { + if *f.gcloudTraceProjectID == "" { + level.Warn(logger).Log("msg", "gcloudtrace.project is empty. Google Cloud Tracer. Tracing will be disabled") + t := &noop.Tracer{} + return t, t + } + + tracer, closer, err := newGCloudTracer(ctx, logger, *f.gcloudTraceProjectID, *f.sampleFactor, serviceName) + if err != nil { + level.Warn(logger).Log("msg", "failed to init Google Cloud Tracer. Tracing will be disabled", "err", err) + t := &noop.Tracer{} + return t, t + } + + level.Info(logger).Log("msg", "initiated Google Cloud Tracer. Tracing will be enabled", "err", err) + return tracer, closer } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { f.gcloudTraceProjectID = app.Flag("gcloudtrace.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled.").Default("").String() f.sampleFactor = app.Flag("gcloudtrace.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details.").Default("1").Uint64() -} \ No newline at end of file +} diff --git a/pkg/tracing/provider/gcloud/gcloud.go b/pkg/tracing/provider/gcloud/tracer.go similarity index 70% rename from pkg/tracing/provider/gcloud/gcloud.go rename to pkg/tracing/provider/gcloud/tracer.go index f9642a44ed..fb14d4b9bb 100644 --- a/pkg/tracing/provider/gcloud/gcloud.go +++ b/pkg/tracing/provider/gcloud/tracer.go @@ -2,30 +2,30 @@ package gcloud import ( "context" - "github.com/improbable-eng/thanos/pkg/tracing" - "github.com/prometheus/common/version" - "os" - "fmt" + "io" + "os" "cloud.google.com/go/trace/apiv1" + "github.com/lovoo/gcloud-opentracing" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" - "github.com/lovoo/gcloud-opentracing" + "github.com/improbable-eng/thanos/pkg/tracing" "github.com/opentracing/basictracer-go" "github.com/opentracing/opentracing-go" + "github.com/prometheus/common/version" ) type tracer struct { - debugName string + serviceName string wrapped opentracing.Tracer } func (t *tracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { span := t.wrapped.StartSpan(operationName, opts...) - if t.debugName != "" { - span.SetTag("service_name", t.debugName) + if t.serviceName != "" { + span.SetTag("service_name", t.serviceName) } // Set common tags. @@ -64,7 +64,6 @@ func (r *forceRecorder) RecordSpan(sp basictracer.RawSpan) { r.wrapped.RecordSpan(sp) } - type gcloudRecorderLogger struct { logger log.Logger } @@ -77,24 +76,7 @@ func (l *gcloudRecorderLogger) Errorf(format string, args ...interface{}) { level.Error(l.logger).Log("msg", fmt.Sprintf(format, args...)) } -// NewOptionalGCloudTracer returns GoogleCloudTracer Tracer. In case of error it log warning and returns noop tracer. -func NewOptionalGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error) { - if gcloudTraceProjectID == "" { - level.Warn(logger).Log("msg", "gcloudtrace.project is empty. Google Cloud Tracer. Tracing will be disabled") - return &opentracing.NoopTracer{}, func() error { return nil } - } - - tracer, closeFn, err := newGCloudTracer(ctx, logger, gcloudTraceProjectID, sampleFactor, debugName) - if err != nil { - level.Warn(logger).Log("msg", "failed to init Google Cloud Tracer. Tracing will be disabled", "err", err) - return &opentracing.NoopTracer{}, func() error { return nil } - } - - level.Info(logger).Log("msg", "initiated Google Cloud Tracer. Tracing will be enabled", "err", err) - return tracer, closeFn -} - -func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, debugName string) (opentracing.Tracer, func() error, error) { +func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectID string, sampleFactor uint64, serviceName string) (opentracing.Tracer, io.Closer, error) { traceClient, err := trace.NewClient(ctx) if err != nil { return nil, nil, err @@ -106,7 +88,7 @@ func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectI traceClient, gcloudtracer.WithLogger(&gcloudRecorderLogger{logger: logger})) if err != nil { - return nil, traceClient.Close, err + return nil, traceClient, err } shouldSample := func(traceID uint64) bool { @@ -120,11 +102,11 @@ func newGCloudTracer(ctx context.Context, logger log.Logger, gcloudTraceProjectI } } return &tracer{ - debugName: debugName, + serviceName: serviceName, wrapped: basictracer.NewWithOptions(basictracer.Options{ ShouldSample: shouldSample, Recorder: &forceRecorder{wrapped: r}, MaxLogsPerSpan: 100, }), - }, r.Close, nil -} \ No newline at end of file + }, r, nil +} diff --git a/pkg/tracing/provider/jaeger/factory.go b/pkg/tracing/provider/jaeger/factory.go index d7c6611530..f0f5d0e559 100644 --- a/pkg/tracing/provider/jaeger/factory.go +++ b/pkg/tracing/provider/jaeger/factory.go @@ -2,9 +2,12 @@ package jaeger import ( "context" + "io" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/improbable-eng/thanos/pkg/tracing" + "github.com/improbable-eng/thanos/pkg/tracing/provider/noop" "github.com/opentracing/opentracing-go" "github.com/uber/jaeger-client-go" "github.com/uber/jaeger-client-go/config" @@ -19,14 +22,19 @@ func NewFactory() *Factory { return &Factory{} } -func (f *Factory) Create(ctx context.Context, logger log.Logger, debugName string) (opentracing.Tracer, func() error) { +func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { cfg, err := config.FromEnv() + if err != nil { + level.Warn(logger).Log("msg", "failed to init Jaeger Tracer from Environment variables. Tracing will be disabled", "err", err) + t := &noop.Tracer{} + return t, t + } cfg.Headers = &jaeger.HeadersConfig{ JaegerDebugHeader: tracing.ForceTracingBaggageKey, } cfg.Headers.ApplyDefaults() - if debugName != "" { - cfg.ServiceName = debugName + if serviceName != "" { + cfg.ServiceName = serviceName } jLogger := &jaegerLogger{ @@ -39,11 +47,12 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger, debugName strin ) if err != nil { level.Warn(logger).Log("msg", "failed to init Jaeger Tracer. Tracing will be disabled", "err", err) - return &opentracing.NoopTracer{}, func() error { return nil } + t := &noop.Tracer{} + return t, t } level.Info(logger).Log("msg", "initiated Jaeger Tracer. Tracing will be enabled", "err", err) - return tracer, closer.Close + return tracer, closer } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { -} \ No newline at end of file +} diff --git a/pkg/tracing/provider/jaeger/logger.go b/pkg/tracing/provider/jaeger/logger.go index 6fe1912e36..50b000197c 100644 --- a/pkg/tracing/provider/jaeger/logger.go +++ b/pkg/tracing/provider/jaeger/logger.go @@ -2,11 +2,12 @@ package jaeger import ( "fmt" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" ) -type jaegerLogger struct{ +type jaegerLogger struct { logger log.Logger } @@ -16,4 +17,4 @@ func (l *jaegerLogger) Infof(format string, args ...interface{}) { func (l *jaegerLogger) Error(msg string) { level.Error(l.logger).Log("msg", msg) -} \ No newline at end of file +} diff --git a/pkg/tracing/provider/noop/factory.go b/pkg/tracing/provider/noop/factory.go new file mode 100644 index 0000000000..c19902730e --- /dev/null +++ b/pkg/tracing/provider/noop/factory.go @@ -0,0 +1,25 @@ +package noop + +import ( + "context" + "io" + + "github.com/go-kit/kit/log" + "github.com/opentracing/opentracing-go" + "gopkg.in/alecthomas/kingpin.v2" +) + +type Factory struct { +} + +func NewFactory() *Factory { + return &Factory{} +} + +func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { + t := &Tracer{} + return t, t +} + +func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { +} diff --git a/pkg/tracing/provider/noop/tracer.go b/pkg/tracing/provider/noop/tracer.go new file mode 100644 index 0000000000..dd6f0bc464 --- /dev/null +++ b/pkg/tracing/provider/noop/tracer.go @@ -0,0 +1,11 @@ +package noop + +import "github.com/opentracing/opentracing-go" + +type Tracer struct { + opentracing.NoopTracer +} + +func (t *Tracer) Close() error { + return nil +} From cede9a416b261d6a025c595a40d095b71b3ee8df Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 14 May 2019 14:18:06 +0300 Subject: [PATCH 10/35] Rename gcloud => stackdriver --- pkg/tracing/provider/factory.go | 27 ++++++++++--------- .../{gcloud => stackdriver}/factory.go | 2 +- .../{gcloud => stackdriver}/tracer.go | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) rename pkg/tracing/provider/{gcloud => stackdriver}/factory.go (98%) rename pkg/tracing/provider/{gcloud => stackdriver}/tracer.go (99%) diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index 756d229e78..2caa7cdeb4 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -6,17 +6,19 @@ import ( "github.com/go-kit/kit/log" "github.com/improbable-eng/thanos/pkg/tracing" - "github.com/improbable-eng/thanos/pkg/tracing/provider/gcloud" "github.com/improbable-eng/thanos/pkg/tracing/provider/jaeger" "github.com/improbable-eng/thanos/pkg/tracing/provider/noop" + "github.com/improbable-eng/thanos/pkg/tracing/provider/stackdriver" "github.com/opentracing/opentracing-go" "gopkg.in/alecthomas/kingpin.v2" ) const ( - jaegerTraceType = "jaeger" - gcloudTraceType = "gcloud" - noopTraceType = "noop" + jaegerTraceType = "jaeger" + stackdriverTraceType = "stackdriver" + noopTraceType = "noop" + + envVarTraceType = "THANOS_TRACE_TYPE" ) // Factory - tracer factory. @@ -27,14 +29,13 @@ type Factory struct { // NewFactory return new tracer factory. func NewFactory() *Factory { - f := &Factory{} - f.factories = make(map[string]tracing.Factory) - - f.factories[jaegerTraceType] = jaeger.NewFactory() - f.factories[gcloudTraceType] = gcloud.NewFactory() - f.factories[noopTraceType] = noop.NewFactory() - - return f + return &Factory{ + factories: map[string]tracing.Factory{ + jaegerTraceType: jaeger.NewFactory(), + stackdriverTraceType: stackdriver.NewFactory(), + noopTraceType: noop.NewFactory(), + }, + } } // Create implement factoty.Factory @@ -43,7 +44,7 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName str } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { - f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default("noop").String() + f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default(noopTraceType).Envar(envVarTraceType).String() for _, t := range f.factories { t.RegisterKingpinFlags(app) } diff --git a/pkg/tracing/provider/gcloud/factory.go b/pkg/tracing/provider/stackdriver/factory.go similarity index 98% rename from pkg/tracing/provider/gcloud/factory.go rename to pkg/tracing/provider/stackdriver/factory.go index 2bfda31534..422c987888 100644 --- a/pkg/tracing/provider/gcloud/factory.go +++ b/pkg/tracing/provider/stackdriver/factory.go @@ -1,4 +1,4 @@ -package gcloud +package stackdriver import ( "context" diff --git a/pkg/tracing/provider/gcloud/tracer.go b/pkg/tracing/provider/stackdriver/tracer.go similarity index 99% rename from pkg/tracing/provider/gcloud/tracer.go rename to pkg/tracing/provider/stackdriver/tracer.go index fb14d4b9bb..e6e91f9263 100644 --- a/pkg/tracing/provider/gcloud/tracer.go +++ b/pkg/tracing/provider/stackdriver/tracer.go @@ -1,4 +1,4 @@ -package gcloud +package stackdriver import ( "context" From 27f3ef0f9571149e403f8c6bbf27f52ea7752580 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 14 May 2019 15:30:58 +0300 Subject: [PATCH 11/35] Refactoring google tracing testing. --- .../provider/stackdriver/tracer_test.go | 160 +++++++++++++++++ pkg/tracing/tracing_test.go | 162 ------------------ 2 files changed, 160 insertions(+), 162 deletions(-) create mode 100644 pkg/tracing/provider/stackdriver/tracer_test.go delete mode 100644 pkg/tracing/tracing_test.go diff --git a/pkg/tracing/provider/stackdriver/tracer_test.go b/pkg/tracing/provider/stackdriver/tracer_test.go new file mode 100644 index 0000000000..ad288d0c88 --- /dev/null +++ b/pkg/tracing/provider/stackdriver/tracer_test.go @@ -0,0 +1,160 @@ +// This file includes unit tests that test only tiny logic in this package, but are here mainly as a showcase on how tracing can +// be configured. + +package stackdriver + +import ( + "testing" + "context" + "time" + "github.com/fortytw2/leaktest" + "github.com/improbable-eng/thanos/pkg/testutil" + "github.com/improbable-eng/thanos/pkg/tracing" + "github.com/opentracing/basictracer-go" +) + +// This test shows that if sample factor will enable tracing on client process, even when it would be disabled on server +// it will be still enabled for all spans within this span. +func TestContextTracing_ClientEnablesTracing(t *testing.T) { + defer leaktest.CheckTimeout(t, 10*time.Second)() + + m := &basictracer.InMemorySpanRecorder{} + r := &forceRecorder{wrapped: m} + + clientTracer := &tracer{ + serviceName: "Test", + wrapped: basictracer.NewWithOptions(basictracer.Options{ + ShouldSample: func(traceID uint64) bool { + return true + }, + Recorder: r, + MaxLogsPerSpan: 100, + }), + } + + clientRoot, clientCtx := tracing.StartSpan(tracing.ContextWithTracer(context.Background(), clientTracer), "a") + + // Simulate Server process with different tracer, but with client span in context. + srvTracer := &tracer{ + serviceName: "Test", + wrapped: basictracer.NewWithOptions(basictracer.Options{ + ShouldSample: func(traceID uint64) bool { + return false + }, + Recorder: r, + MaxLogsPerSpan: 100, + }), + } + srvRoot, srvCtx := tracing.StartSpan(tracing.ContextWithTracer(clientCtx, srvTracer), "b") + srvChild, _ := tracing.StartSpan(srvCtx, "bb") + testutil.Equals(t, 0, len(m.GetSpans())) + + srvChild.Finish() + testutil.Equals(t, 1, len(m.GetSpans())) + testutil.Equals(t, 1, len(m.GetSampledSpans())) + + srvRoot.Finish() + testutil.Equals(t, 2, len(m.GetSpans())) + testutil.Equals(t, 2, len(m.GetSampledSpans())) + + clientRoot.Finish() + testutil.Equals(t, 3, len(m.GetSpans())) + testutil.Equals(t, 3, len(m.GetSampledSpans())) +} + +// This test shows that if sample factor will disable tracing on client process, when it would be enabled on server +// it will be still disabled for all spans within this span. +func TestContextTracing_ClientDisablesTracing(t *testing.T) { + m := &basictracer.InMemorySpanRecorder{} + r := &forceRecorder{wrapped: m} + + clientTracer := &tracer{ + serviceName: "Test", + wrapped: basictracer.NewWithOptions(basictracer.Options{ + ShouldSample: func(traceID uint64) bool { + return false + }, + Recorder: r, + MaxLogsPerSpan: 100, + }), + } + + clientRoot, clientCtx := tracing.StartSpan(tracing.ContextWithTracer(context.Background(), clientTracer), "a") + + // Simulate Server process with different tracer, but with client span in context. + srvTracer := &tracer{ + serviceName: "Test", + wrapped: basictracer.NewWithOptions(basictracer.Options{ + ShouldSample: func(traceID uint64) bool { + return true + }, + Recorder: r, + MaxLogsPerSpan: 100, + }), + } + srvRoot, srvCtx := tracing.StartSpan(tracing.ContextWithTracer(clientCtx, srvTracer), "b") + srvChild, _ := tracing.StartSpan(srvCtx, "bb") + testutil.Equals(t, 0, len(m.GetSpans())) + + srvChild.Finish() + testutil.Equals(t, 1, len(m.GetSpans())) + testutil.Equals(t, 0, len(m.GetSampledSpans())) + + srvRoot.Finish() + testutil.Equals(t, 2, len(m.GetSpans())) + testutil.Equals(t, 0, len(m.GetSampledSpans())) + + clientRoot.Finish() + testutil.Equals(t, 3, len(m.GetSpans())) + testutil.Equals(t, 0, len(m.GetSampledSpans())) +} + +// This test shows that if span will contain special baggage (for example from special HTTP header), even when sample +// factor will disable client & server tracing, it will be still enabled for all spans within this span. +func TestContextTracing_ForceTracing(t *testing.T) { + m := &basictracer.InMemorySpanRecorder{} + r := &forceRecorder{wrapped: m} + + clientTracer := &tracer{ + serviceName: "Test", + wrapped: basictracer.NewWithOptions(basictracer.Options{ + ShouldSample: func(traceID uint64) bool { + return false + }, + Recorder: r, + MaxLogsPerSpan: 100, + }), + } + + clientRoot, clientCtx := tracing.StartSpan(tracing.ContextWithTracer(context.Background(), clientTracer), "a") + + // Force tracing for this span and its children. + clientRoot.SetBaggageItem(tracing.ForceTracingBaggageKey, "Go for it") + + // Simulate Server process with different tracer, but with client span in context. + srvTracer := &tracer{ + serviceName: "Test", + wrapped: basictracer.NewWithOptions(basictracer.Options{ + ShouldSample: func(traceID uint64) bool { + return false + }, + Recorder: r, + MaxLogsPerSpan: 100, + }), + } + srvRoot, srvCtx := tracing.StartSpan(tracing.ContextWithTracer(clientCtx, srvTracer), "b") + srvChild, _ := tracing.StartSpan(srvCtx, "bb") + testutil.Equals(t, 0, len(m.GetSpans())) + + srvChild.Finish() + testutil.Equals(t, 1, len(m.GetSpans())) + testutil.Equals(t, 1, len(m.GetSampledSpans())) + + srvRoot.Finish() + testutil.Equals(t, 2, len(m.GetSpans())) + testutil.Equals(t, 2, len(m.GetSampledSpans())) + + clientRoot.Finish() + testutil.Equals(t, 3, len(m.GetSpans())) + testutil.Equals(t, 3, len(m.GetSampledSpans())) +} diff --git a/pkg/tracing/tracing_test.go b/pkg/tracing/tracing_test.go deleted file mode 100644 index 599706c7b9..0000000000 --- a/pkg/tracing/tracing_test.go +++ /dev/null @@ -1,162 +0,0 @@ -//// This file includes unit tests that test only tiny logic in this package, but are here mainly as a showcase on how tracing can -//// be configured. -// -package tracing -// -//import ( -// "testing" -// -// "context" -// -// "time" -// -// "github.com/fortytw2/leaktest" -// "github.com/improbable-eng/thanos/pkg/testutil" -// "github.com/opentracing/basictracer-go" -//) -// -//// This test shows that if sample factor will enable tracing on client process, even when it would be disabled on server -//// it will be still enabled for all spans within this span. -//func TestContextTracing_ClientEnablesTracing(t *testing.T) { -// defer leaktest.CheckTimeout(t, 10*time.Second)() -// -// m := &basictracer.InMemorySpanRecorder{} -// r := &forceRecorder{wrapped: m} -// -// clientTracer := &tracer{ -// debugName: "Test", -// wrapped: basictracer.NewWithOptions(basictracer.Options{ -// ShouldSample: func(traceID uint64) bool { -// return true -// }, -// Recorder: r, -// MaxLogsPerSpan: 100, -// }), -// } -// -// clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") -// -// // Simulate Server process with different tracer, but with client span in context. -// srvTracer := &tracer{ -// debugName: "Test", -// wrapped: basictracer.NewWithOptions(basictracer.Options{ -// ShouldSample: func(traceID uint64) bool { -// return false -// }, -// Recorder: r, -// MaxLogsPerSpan: 100, -// }), -// } -// srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") -// srvChild, _ := StartSpan(srvCtx, "bb") -// testutil.Equals(t, 0, len(m.GetSpans())) -// -// srvChild.Finish() -// testutil.Equals(t, 1, len(m.GetSpans())) -// testutil.Equals(t, 1, len(m.GetSampledSpans())) -// -// srvRoot.Finish() -// testutil.Equals(t, 2, len(m.GetSpans())) -// testutil.Equals(t, 2, len(m.GetSampledSpans())) -// -// clientRoot.Finish() -// testutil.Equals(t, 3, len(m.GetSpans())) -// testutil.Equals(t, 3, len(m.GetSampledSpans())) -//} -// -//// This test shows that if sample factor will disable tracing on client process, even when it would be enabled on server -//// it will be still disabled for all spans within this span. -//func TestContextTracing_ClientDisablesTracing(t *testing.T) { -// m := &basictracer.InMemorySpanRecorder{} -// r := &forceRecorder{wrapped: m} -// -// clientTracer := &tracer{ -// debugName: "Test", -// wrapped: basictracer.NewWithOptions(basictracer.Options{ -// ShouldSample: func(traceID uint64) bool { -// return false -// }, -// Recorder: r, -// MaxLogsPerSpan: 100, -// }), -// } -// -// clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") -// -// // Simulate Server process with different tracer, but with client span in context. -// srvTracer := &tracer{ -// debugName: "Test", -// wrapped: basictracer.NewWithOptions(basictracer.Options{ -// ShouldSample: func(traceID uint64) bool { -// return true -// }, -// Recorder: r, -// MaxLogsPerSpan: 100, -// }), -// } -// srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") -// srvChild, _ := StartSpan(srvCtx, "bb") -// testutil.Equals(t, 0, len(m.GetSpans())) -// -// srvChild.Finish() -// testutil.Equals(t, 1, len(m.GetSpans())) -// testutil.Equals(t, 0, len(m.GetSampledSpans())) -// -// srvRoot.Finish() -// testutil.Equals(t, 2, len(m.GetSpans())) -// testutil.Equals(t, 0, len(m.GetSampledSpans())) -// -// clientRoot.Finish() -// testutil.Equals(t, 3, len(m.GetSpans())) -// testutil.Equals(t, 0, len(m.GetSampledSpans())) -//} -// -//// This test shows that if span will contain special baggage (for example from special HTTP header), even when sample -//// factor will disable client & server tracing, it will be still enabled for all spans within this span. -//func TestContextTracing_ForceTracing(t *testing.T) { -// m := &basictracer.InMemorySpanRecorder{} -// r := &forceRecorder{wrapped: m} -// -// clientTracer := &tracer{ -// debugName: "Test", -// wrapped: basictracer.NewWithOptions(basictracer.Options{ -// ShouldSample: func(traceID uint64) bool { -// return false -// }, -// Recorder: r, -// MaxLogsPerSpan: 100, -// }), -// } -// -// clientRoot, clientCtx := StartSpan(ContextWithTracer(context.Background(), clientTracer), "a") -// -// // Force tracing for this span and its children. -// clientRoot.SetBaggageItem(ForceTracingBaggageKey, "Go for it") -// -// // Simulate Server process with different tracer, but with client span in context. -// srvTracer := &tracer{ -// debugName: "Test", -// wrapped: basictracer.NewWithOptions(basictracer.Options{ -// ShouldSample: func(traceID uint64) bool { -// return false -// }, -// Recorder: r, -// MaxLogsPerSpan: 100, -// }), -// } -// srvRoot, srvCtx := StartSpan(ContextWithTracer(clientCtx, srvTracer), "b") -// srvChild, _ := StartSpan(srvCtx, "bb") -// testutil.Equals(t, 0, len(m.GetSpans())) -// -// srvChild.Finish() -// testutil.Equals(t, 1, len(m.GetSpans())) -// testutil.Equals(t, 1, len(m.GetSampledSpans())) -// -// srvRoot.Finish() -// testutil.Equals(t, 2, len(m.GetSpans())) -// testutil.Equals(t, 2, len(m.GetSampledSpans())) -// -// clientRoot.Finish() -// testutil.Equals(t, 3, len(m.GetSpans())) -// testutil.Equals(t, 3, len(m.GetSampledSpans())) -//} From 3d12afe283edbf3178465cd52a51747bc03370b4 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 14 May 2019 15:32:46 +0300 Subject: [PATCH 12/35] Delete comments. --- cmd/thanos/main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 72d4f2e295..90fd3d5a51 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -143,9 +143,7 @@ func main() { { ctx := context.Background() - //var closeFn func() error var closer io.Closer - tracer, closer = tracingFactory.Create(ctx, logger, *debugName) // This is bad, but Prometheus does not support any other tracer injections than just global one. From d24e376836bcd5b232a1a943a79f496f94aac5bc Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 14 May 2019 15:39:56 +0300 Subject: [PATCH 13/35] Rename gcloud flags => stackdriver. --- pkg/tracing/provider/stackdriver/factory.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/tracing/provider/stackdriver/factory.go b/pkg/tracing/provider/stackdriver/factory.go index 422c987888..0335ef3c54 100644 --- a/pkg/tracing/provider/stackdriver/factory.go +++ b/pkg/tracing/provider/stackdriver/factory.go @@ -39,6 +39,6 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName str } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { - f.gcloudTraceProjectID = app.Flag("gcloudtrace.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled.").Default("").String() - f.sampleFactor = app.Flag("gcloudtrace.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details.").Default("1").Uint64() + f.gcloudTraceProjectID = app.Flag("stackdriver.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled.").Default("").String() + f.sampleFactor = app.Flag("stackdriver.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details.").Default("1").Uint64() } From eed06c60c9fe9a3be2b8cb3ea781fda4d2b307d9 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 14 May 2019 15:48:58 +0300 Subject: [PATCH 14/35] Update tracing docs. --- docs/components/bucket.md | 5 +++-- docs/components/compact.md | 5 +++-- docs/components/query.md | 5 +++-- docs/components/rule.md | 5 +++-- docs/components/sidecar.md | 5 +++-- docs/components/store.md | 5 +++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/components/bucket.md b/docs/components/bucket.md index 380f24d222..080921c0a7 100644 --- a/docs/components/bucket.md +++ b/docs/components/bucket.md @@ -42,10 +42,11 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT + --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). + --stackdriver.project=GCLOUDTRACE.PROJECT GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 + --stackdriver.sample-factor=1 How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for diff --git a/docs/components/compact.md b/docs/components/compact.md index 439adc520b..634880e767 100644 --- a/docs/components/compact.md +++ b/docs/components/compact.md @@ -42,10 +42,11 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT + --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). + --stackdriver.project=GCLOUDTRACE.PROJECT GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 + --stackdriver.sample-factor=1 How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See diff --git a/docs/components/query.md b/docs/components/query.md index 7ce69b9d50..86a58e1a95 100644 --- a/docs/components/query.md +++ b/docs/components/query.md @@ -174,10 +174,11 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT + --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). + --stackdriver.project=GCLOUDTRACE.PROJECT GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 + --stackdriver.sample-factor=1 How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See diff --git a/docs/components/rule.md b/docs/components/rule.md index 5e607c1740..d0f28f8457 100644 --- a/docs/components/rule.md +++ b/docs/components/rule.md @@ -156,10 +156,11 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT + --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). + --stackdriver.project=GCLOUDTRACE.PROJECT GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 + --stackdriver.sample-factor=1 How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See diff --git a/docs/components/sidecar.md b/docs/components/sidecar.md index 58ae7d4628..1e68395bc2 100644 --- a/docs/components/sidecar.md +++ b/docs/components/sidecar.md @@ -58,10 +58,11 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT + --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). + --stackdriver.project=GCLOUDTRACE.PROJECT GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 + --stackdriver.sample-factor=1 How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See diff --git a/docs/components/store.md b/docs/components/store.md index 462b4a4142..3e9e5b70f2 100644 --- a/docs/components/store.md +++ b/docs/components/store.md @@ -42,10 +42,11 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT + --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). + --stackdriver.project=GCLOUDTRACE.PROJECT GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 + --stackdriver.sample-factor=1 How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See From eb405cea79a6edfa2f35ef29f2f4ef16ea34e32f Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 14 May 2019 18:02:08 +0300 Subject: [PATCH 15/35] Fix ..traceType to ..tracerType --- pkg/tracing/provider/factory.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index 2caa7cdeb4..3096090978 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -14,11 +14,11 @@ import ( ) const ( - jaegerTraceType = "jaeger" - stackdriverTraceType = "stackdriver" - noopTraceType = "noop" + jaegerTracerType = "jaeger" + stackdriverTracerType = "stackdriver" + noopTracerType = "noop" - envVarTraceType = "THANOS_TRACE_TYPE" + envVarTracerType = "THANOS_TRACER_TYPE" ) // Factory - tracer factory. @@ -31,9 +31,9 @@ type Factory struct { func NewFactory() *Factory { return &Factory{ factories: map[string]tracing.Factory{ - jaegerTraceType: jaeger.NewFactory(), - stackdriverTraceType: stackdriver.NewFactory(), - noopTraceType: noop.NewFactory(), + jaegerTracerType: jaeger.NewFactory(), + stackdriverTracerType: stackdriver.NewFactory(), + noopTracerType: noop.NewFactory(), }, } } @@ -44,7 +44,7 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName str } func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { - f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default(noopTraceType).Envar(envVarTraceType).String() + f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default(noopTracerType).Envar(envVarTracerType).String() for _, t := range f.factories { t.RegisterKingpinFlags(app) } From c7451713ef68dec8e6409db643e2915e5503b02c Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Wed, 15 May 2019 16:13:46 +0300 Subject: [PATCH 16/35] Refactoring NoopTracer; Comments for exported functions. --- cmd/thanos/main.go | 2 +- pkg/tracing/factory.go | 3 ++- pkg/tracing/provider/factory.go | 30 ++++++++++++++------- pkg/tracing/provider/jaeger/factory.go | 20 +++++++------- pkg/tracing/provider/noop/factory.go | 25 ----------------- pkg/tracing/provider/noop/tracer.go | 11 -------- pkg/tracing/provider/noop_tracer.go | 15 +++++++++++ pkg/tracing/provider/stackdriver/factory.go | 22 +++++++-------- pkg/tracing/tracing.go | 1 + 9 files changed, 58 insertions(+), 71 deletions(-) delete mode 100644 pkg/tracing/provider/noop/factory.go delete mode 100644 pkg/tracing/provider/noop/tracer.go create mode 100644 pkg/tracing/provider/noop_tracer.go diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 90fd3d5a51..ea8be2c8c1 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -144,7 +144,7 @@ func main() { ctx := context.Background() var closer io.Closer - tracer, closer = tracingFactory.Create(ctx, logger, *debugName) + tracer, closer, _ = tracingFactory.Create(ctx, logger, *debugName) // This is bad, but Prometheus does not support any other tracer injections than just global one. // TODO(bplotka): Work with basictracer to handle gracefully tracker mismatches, and also with Prometheus to allow diff --git a/pkg/tracing/factory.go b/pkg/tracing/factory.go index 41ec1433ef..3df43cbfd6 100644 --- a/pkg/tracing/factory.go +++ b/pkg/tracing/factory.go @@ -9,7 +9,8 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) +// Factory defines an interface for a factory that can create implementations of different tracer types. type Factory interface { - Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) + Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer, error) RegisterKingpinFlags(app *kingpin.Application) } diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index 3096090978..0556403561 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -2,12 +2,12 @@ package provider import ( "context" + "github.com/go-kit/kit/log/level" "io" "github.com/go-kit/kit/log" "github.com/improbable-eng/thanos/pkg/tracing" "github.com/improbable-eng/thanos/pkg/tracing/provider/jaeger" - "github.com/improbable-eng/thanos/pkg/tracing/provider/noop" "github.com/improbable-eng/thanos/pkg/tracing/provider/stackdriver" "github.com/opentracing/opentracing-go" "gopkg.in/alecthomas/kingpin.v2" @@ -16,35 +16,47 @@ import ( const ( jaegerTracerType = "jaeger" stackdriverTracerType = "stackdriver" - noopTracerType = "noop" envVarTracerType = "THANOS_TRACER_TYPE" ) -// Factory - tracer factory. +// Factory implements tracing.Factory interface as a meta-factory for tracers. type Factory struct { tracingType *string factories map[string]tracing.Factory } -// NewFactory return new tracer factory. +// NewFactory creates the meta-factory. func NewFactory() *Factory { return &Factory{ factories: map[string]tracing.Factory{ jaegerTracerType: jaeger.NewFactory(), stackdriverTracerType: stackdriver.NewFactory(), - noopTracerType: noop.NewFactory(), }, } } -// Create implement factoty.Factory -func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { - return f.factories[*f.tracingType].Create(ctx, logger, serviceName) +// Create implements tracing.Factory +func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer, error) { + var tracer opentracing.Tracer + var closer io.Closer + var err error + factory, ok := f.factories[*f.tracingType]; + if !ok { + level.Info(logger).Log("msg", "Invalid tracer type. Tracing will be disabled.", "err", err) + return noopTracer, noopCloser, nil + } + tracer, closer, err = factory.Create(ctx, logger, serviceName) + if err != nil { + level.Info(logger).Log("msg", "Tracer create error. Tracing will be disabled.", "err", err) + return noopTracer, noopCloser, nil + } + return tracer, closer, nil } +// RegisterKingpinFlags implements tracing.Factory. func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { - f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default(noopTracerType).Envar(envVarTracerType).String() + f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default("").Envar(envVarTracerType).String() for _, t := range f.factories { t.RegisterKingpinFlags(app) } diff --git a/pkg/tracing/provider/jaeger/factory.go b/pkg/tracing/provider/jaeger/factory.go index f0f5d0e559..6e6096eb66 100644 --- a/pkg/tracing/provider/jaeger/factory.go +++ b/pkg/tracing/provider/jaeger/factory.go @@ -5,9 +5,7 @@ import ( "io" "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "github.com/improbable-eng/thanos/pkg/tracing" - "github.com/improbable-eng/thanos/pkg/tracing/provider/noop" "github.com/opentracing/opentracing-go" "github.com/uber/jaeger-client-go" "github.com/uber/jaeger-client-go/config" @@ -15,19 +13,21 @@ import ( "gopkg.in/alecthomas/kingpin.v2" ) +// Factory implements tracing.Factory for Jaeger Tracer. type Factory struct { } + +// NewFactory creates a new Factory func NewFactory() *Factory { return &Factory{} } -func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { +// Create implements tracing.Factory +func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer, error) { cfg, err := config.FromEnv() if err != nil { - level.Warn(logger).Log("msg", "failed to init Jaeger Tracer from Environment variables. Tracing will be disabled", "err", err) - t := &noop.Tracer{} - return t, t + return nil, nil, err } cfg.Headers = &jaeger.HeadersConfig{ JaegerDebugHeader: tracing.ForceTracingBaggageKey, @@ -46,13 +46,11 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName str config.Logger(jLogger), ) if err != nil { - level.Warn(logger).Log("msg", "failed to init Jaeger Tracer. Tracing will be disabled", "err", err) - t := &noop.Tracer{} - return t, t + return nil, nil, err } - level.Info(logger).Log("msg", "initiated Jaeger Tracer. Tracing will be enabled", "err", err) - return tracer, closer + return tracer, closer, nil } +// RegisterKingpinFlags implements tracing.Factory func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { } diff --git a/pkg/tracing/provider/noop/factory.go b/pkg/tracing/provider/noop/factory.go deleted file mode 100644 index c19902730e..0000000000 --- a/pkg/tracing/provider/noop/factory.go +++ /dev/null @@ -1,25 +0,0 @@ -package noop - -import ( - "context" - "io" - - "github.com/go-kit/kit/log" - "github.com/opentracing/opentracing-go" - "gopkg.in/alecthomas/kingpin.v2" -) - -type Factory struct { -} - -func NewFactory() *Factory { - return &Factory{} -} - -func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { - t := &Tracer{} - return t, t -} - -func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { -} diff --git a/pkg/tracing/provider/noop/tracer.go b/pkg/tracing/provider/noop/tracer.go deleted file mode 100644 index dd6f0bc464..0000000000 --- a/pkg/tracing/provider/noop/tracer.go +++ /dev/null @@ -1,11 +0,0 @@ -package noop - -import "github.com/opentracing/opentracing-go" - -type Tracer struct { - opentracing.NoopTracer -} - -func (t *Tracer) Close() error { - return nil -} diff --git a/pkg/tracing/provider/noop_tracer.go b/pkg/tracing/provider/noop_tracer.go new file mode 100644 index 0000000000..0898e9fb12 --- /dev/null +++ b/pkg/tracing/provider/noop_tracer.go @@ -0,0 +1,15 @@ +package provider + +import "github.com/opentracing/opentracing-go" + +var ( + noopTracer = opentracing.NoopTracer{} + noopCloser = &noopTracerCloser{} +) + +type noopTracerCloser struct { +} + +func (t *noopTracerCloser) Close() error { + return nil +} diff --git a/pkg/tracing/provider/stackdriver/factory.go b/pkg/tracing/provider/stackdriver/factory.go index 0335ef3c54..d06a9dd88a 100644 --- a/pkg/tracing/provider/stackdriver/factory.go +++ b/pkg/tracing/provider/stackdriver/factory.go @@ -2,42 +2,38 @@ package stackdriver import ( "context" + "errors" "io" "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" - "github.com/improbable-eng/thanos/pkg/tracing/provider/noop" "github.com/opentracing/opentracing-go" "gopkg.in/alecthomas/kingpin.v2" ) +// Factory implements tracing.Factory for Stackdriver Tracer. type Factory struct { gcloudTraceProjectID *string sampleFactor *uint64 } +// NewFactory creates a new Factory func NewFactory() *Factory { return &Factory{} } -func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { +// Create implements tracing.Factory +func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer, error) { if *f.gcloudTraceProjectID == "" { - level.Warn(logger).Log("msg", "gcloudtrace.project is empty. Google Cloud Tracer. Tracing will be disabled") - t := &noop.Tracer{} - return t, t + return nil, nil, errors.New("stackdriver.project is empty.") } - tracer, closer, err := newGCloudTracer(ctx, logger, *f.gcloudTraceProjectID, *f.sampleFactor, serviceName) if err != nil { - level.Warn(logger).Log("msg", "failed to init Google Cloud Tracer. Tracing will be disabled", "err", err) - t := &noop.Tracer{} - return t, t + return nil, nil, err } - - level.Info(logger).Log("msg", "initiated Google Cloud Tracer. Tracing will be enabled", "err", err) - return tracer, closer + return tracer, closer, nil } +// RegisterKingpinFlags implements tracing.Factory func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { f.gcloudTraceProjectID = app.Flag("stackdriver.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled.").Default("").String() f.sampleFactor = app.Flag("stackdriver.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details.").Default("1").Uint64() diff --git a/pkg/tracing/tracing.go b/pkg/tracing/tracing.go index 31c9ae486d..2de35e7497 100644 --- a/pkg/tracing/tracing.go +++ b/pkg/tracing/tracing.go @@ -6,6 +6,7 @@ import ( "github.com/opentracing/opentracing-go" ) +// ForceTracingBaggageKey - force sampling header. const ForceTracingBaggageKey = "X-Thanos-Force-Tracing" type contextKey struct{} From 331a9295f7a18765df3c42a5365ba1e7602bb6f0 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Wed, 15 May 2019 16:55:27 +0300 Subject: [PATCH 17/35] Remove noop tracer. Fix docs. --- pkg/tracing/provider/noop_tracer.go | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 pkg/tracing/provider/noop_tracer.go diff --git a/pkg/tracing/provider/noop_tracer.go b/pkg/tracing/provider/noop_tracer.go deleted file mode 100644 index 0898e9fb12..0000000000 --- a/pkg/tracing/provider/noop_tracer.go +++ /dev/null @@ -1,15 +0,0 @@ -package provider - -import "github.com/opentracing/opentracing-go" - -var ( - noopTracer = opentracing.NoopTracer{} - noopCloser = &noopTracerCloser{} -) - -type noopTracerCloser struct { -} - -func (t *noopTracerCloser) Close() error { - return nil -} From 47f3fd16d7b9c268ae464ce4ad7936ab39eb80e7 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Wed, 15 May 2019 17:02:21 +0300 Subject: [PATCH 18/35] Remove noop tracer. Fix docs. --- cmd/thanos/main.go | 5 ++--- docs/components/bucket.md | 2 +- docs/components/compact.md | 2 +- pkg/tracing/provider/factory.go | 23 +++++++++++++---------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index ea8be2c8c1..51467312e7 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -67,8 +67,7 @@ func main() { logFormat := app.Flag("log.format", "Log format to use."). Default(logFormatLogfmt).Enum(logFormatLogfmt, logFormatJson) - tracingFactory := provider.NewFactory() - tracingFactory.RegisterKingpinFlags(app) + tracingFactory := provider.NewFactory(app) cmds := map[string]setupFunc{} registerSidecar(cmds, app, "sidecar") @@ -144,7 +143,7 @@ func main() { ctx := context.Background() var closer io.Closer - tracer, closer, _ = tracingFactory.Create(ctx, logger, *debugName) + tracer, closer = tracingFactory.Create(ctx, logger, *debugName) // This is bad, but Prometheus does not support any other tracer injections than just global one. // TODO(bplotka): Work with basictracer to handle gracefully tracker mismatches, and also with Prometheus to allow diff --git a/docs/components/bucket.md b/docs/components/bucket.md index 080921c0a7..cd0f7a590a 100644 --- a/docs/components/bucket.md +++ b/docs/components/bucket.md @@ -42,7 +42,7 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). + --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). --stackdriver.project=GCLOUDTRACE.PROJECT GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled. diff --git a/docs/components/compact.md b/docs/components/compact.md index 634880e767..b2ce5326e6 100644 --- a/docs/components/compact.md +++ b/docs/components/compact.md @@ -42,7 +42,7 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). + --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). --stackdriver.project=GCLOUDTRACE.PROJECT GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled. diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index 0556403561..1417335850 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -4,6 +4,7 @@ import ( "context" "github.com/go-kit/kit/log/level" "io" + "io/ioutil" "github.com/go-kit/kit/log" "github.com/improbable-eng/thanos/pkg/tracing" @@ -20,42 +21,44 @@ const ( envVarTracerType = "THANOS_TRACER_TYPE" ) -// Factory implements tracing.Factory interface as a meta-factory for tracers. +// Factory is a meta-factory for tracers. type Factory struct { tracingType *string factories map[string]tracing.Factory } // NewFactory creates the meta-factory. -func NewFactory() *Factory { - return &Factory{ +func NewFactory(app *kingpin.Application) *Factory { + f := &Factory{ factories: map[string]tracing.Factory{ jaegerTracerType: jaeger.NewFactory(), stackdriverTracerType: stackdriver.NewFactory(), }, } + f.registerKingpinFlags(app) + return f } -// Create implements tracing.Factory -func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer, error) { +// Create creates the tracer in appliance with a tracerType +func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { var tracer opentracing.Tracer var closer io.Closer var err error factory, ok := f.factories[*f.tracingType]; if !ok { level.Info(logger).Log("msg", "Invalid tracer type. Tracing will be disabled.", "err", err) - return noopTracer, noopCloser, nil + return &opentracing.NoopTracer{}, ioutil.NopCloser(nil) } tracer, closer, err = factory.Create(ctx, logger, serviceName) if err != nil { level.Info(logger).Log("msg", "Tracer create error. Tracing will be disabled.", "err", err) - return noopTracer, noopCloser, nil + return &opentracing.NoopTracer{}, ioutil.NopCloser(nil) } - return tracer, closer, nil + return tracer, closer } -// RegisterKingpinFlags implements tracing.Factory. -func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { +// registerKingpinFlags registers kingpinFlags for every tracer type. +func (f *Factory) registerKingpinFlags(app *kingpin.Application) { f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default("").Envar(envVarTracerType).String() for _, t := range f.factories { t.RegisterKingpinFlags(app) From ff5a2aa9b416196107a2cd1f73b3fe1c011b9917 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Wed, 22 May 2019 13:12:11 +0300 Subject: [PATCH 19/35] Config tracing same as objstore. --- cmd/thanos/flags.go | 24 +++++++ cmd/thanos/main.go | 29 +++++--- pkg/tracing/provider/factory.go | 68 +++++++------------ .../provider/jaeger/{factory.go => jaeger.go} | 33 +++++---- pkg/tracing/provider/stackdriver/factory.go | 40 ----------- .../provider/stackdriver/stackdriver.go | 33 +++++++++ 6 files changed, 121 insertions(+), 106 deletions(-) rename pkg/tracing/provider/jaeger/{factory.go => jaeger.go} (54%) delete mode 100644 pkg/tracing/provider/stackdriver/factory.go create mode 100644 pkg/tracing/provider/stackdriver/stackdriver.go diff --git a/cmd/thanos/flags.go b/cmd/thanos/flags.go index 36f7b7db32..584ec3d742 100644 --- a/cmd/thanos/flags.go +++ b/cmd/thanos/flags.go @@ -201,3 +201,27 @@ func regCommonObjStoreFlags(cmd *kingpin.CmdClause, suffix string, required bool content: bucketConf, } } + + +func regCommonTracingFlags(cmd *kingpin.Application, suffix string, required bool, extraDesc ...string) *pathOrContent { + fileFlagName := fmt.Sprintf("tracing%s.config-file", suffix) + contentFlagName := fmt.Sprintf("tracing%s.config", suffix) + + help := fmt.Sprintf("Path to YAML file that contains tracing%s configuration.", suffix) + help = strings.Join(append([]string{help}, extraDesc...), " ") + tracingConfFile := cmd.Flag(fileFlagName, help).PlaceHolder("").String() + + help = fmt.Sprintf("Alternative to '%s' flag. Tracing%s configuration in YAML.", fileFlagName, suffix) + help = strings.Join(append([]string{help}, extraDesc...), " ") + tracingConf := cmd.Flag(contentFlagName, help). + PlaceHolder("").String() + + return &pathOrContent{ + fileFlagName: fileFlagName, + contentFlagName: contentFlagName, + required: required, + + path: tracingConfFile, + content: tracingConf, + } +} diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 41010e903f..75dfb05a37 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -5,6 +5,8 @@ import ( "crypto/tls" "crypto/x509" "fmt" + "github.com/improbable-eng/thanos/pkg/tracing/provider" + "io" "io/ioutil" "math" "net" @@ -16,21 +18,19 @@ import ( "runtime" "runtime/debug" "syscall" - "io" gmetrics "github.com/armon/go-metrics" gprom "github.com/armon/go-metrics/prometheus" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" - grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" - grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery" - grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" + "github.com/grpc-ecosystem/go-grpc-middleware" + "github.com/grpc-ecosystem/go-grpc-middleware/recovery" + "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/improbable-eng/thanos/pkg/runutil" "github.com/improbable-eng/thanos/pkg/tracing" - "github.com/improbable-eng/thanos/pkg/tracing/provider" "github.com/oklog/run" - opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -39,7 +39,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" "google.golang.org/grpc/status" - kingpin "gopkg.in/alecthomas/kingpin.v2" + "gopkg.in/alecthomas/kingpin.v2" ) const ( @@ -67,7 +67,10 @@ func main() { logFormat := app.Flag("log.format", "Log format to use."). Default(logFormatLogfmt).Enum(logFormatLogfmt, logFormatJson) - tracingFactory := provider.NewFactory(app) + //tracingFactory := provider.NewFactory(app) + + //objStoreConfig := regCommonObjStoreFlags(cmd, "", true) + tracingConfig := regCommonTracingFlags(app, "", false) cmds := map[string]setupFunc{} registerSidecar(cmds, app, "sidecar") @@ -143,7 +146,15 @@ func main() { ctx := context.Background() var closer io.Closer - tracer, closer = tracingFactory.Create(ctx, logger, *debugName) + var confContentYaml []byte + confContentYaml, err = tracingConfig.Content() + //tracer, closer = tracingFactory.Create(ctx, logger, *debugName) + tracer, closer, err = provider.NewTracer(ctx, logger, confContentYaml) + + if err != nil { + fmt.Fprintln(os.Stderr, errors.Wrapf(err, "tracing failed")) + os.Exit(1) + } // This is bad, but Prometheus does not support any other tracer injections than just global one. // TODO(bplotka): Work with basictracer to handle gracefully tracker mismatches, and also with Prometheus to allow diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index 1417335850..a6959795e4 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -2,65 +2,49 @@ package provider import ( "context" - "github.com/go-kit/kit/log/level" "io" "io/ioutil" + "strings" "github.com/go-kit/kit/log" - "github.com/improbable-eng/thanos/pkg/tracing" + "github.com/go-kit/kit/log/level" "github.com/improbable-eng/thanos/pkg/tracing/provider/jaeger" "github.com/improbable-eng/thanos/pkg/tracing/provider/stackdriver" "github.com/opentracing/opentracing-go" - "gopkg.in/alecthomas/kingpin.v2" + "github.com/pkg/errors" + "gopkg.in/yaml.v2" ) -const ( - jaegerTracerType = "jaeger" - stackdriverTracerType = "stackdriver" +type TracingProvider string - envVarTracerType = "THANOS_TRACER_TYPE" +const ( + STACKDRIVER TracingProvider = "STACKDRIVER" + JAEGER TracingProvider = "JAEGER" ) -// Factory is a meta-factory for tracers. -type Factory struct { - tracingType *string - factories map[string]tracing.Factory +type TracingConfig struct { + Type TracingProvider `yaml:"type"` + Config interface{} `yaml:"config"` } -// NewFactory creates the meta-factory. -func NewFactory(app *kingpin.Application) *Factory { - f := &Factory{ - factories: map[string]tracing.Factory{ - jaegerTracerType: jaeger.NewFactory(), - stackdriverTracerType: stackdriver.NewFactory(), - }, +func NewTracer(ctx context.Context, logger log.Logger, confContentYaml []byte) (opentracing.Tracer, io.Closer, error) { + level.Info(logger).Log("msg", "loading tracing configuration") + tracingConf := &TracingConfig{} + if err := yaml.UnmarshalStrict(confContentYaml, tracingConf); err != nil { + return &opentracing.NoopTracer{}, ioutil.NopCloser(nil), errors.Wrap(err, "parsing config YAML file") } - f.registerKingpinFlags(app) - return f -} -// Create creates the tracer in appliance with a tracerType -func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer) { - var tracer opentracing.Tracer - var closer io.Closer - var err error - factory, ok := f.factories[*f.tracingType]; - if !ok { - level.Info(logger).Log("msg", "Invalid tracer type. Tracing will be disabled.", "err", err) - return &opentracing.NoopTracer{}, ioutil.NopCloser(nil) - } - tracer, closer, err = factory.Create(ctx, logger, serviceName) + config, err := yaml.Marshal(tracingConf.Config) if err != nil { - level.Info(logger).Log("msg", "Tracer create error. Tracing will be disabled.", "err", err) - return &opentracing.NoopTracer{}, ioutil.NopCloser(nil) + return nil, nil, errors.Wrap(err, "marshal content of tracing configuration") } - return tracer, closer -} - -// registerKingpinFlags registers kingpinFlags for every tracer type. -func (f *Factory) registerKingpinFlags(app *kingpin.Application) { - f.tracingType = app.Flag("tracing.type", "gcloud/jaeger.").Default("").Envar(envVarTracerType).String() - for _, t := range f.factories { - t.RegisterKingpinFlags(app) + switch strings.ToUpper(string(tracingConf.Type)) { + case string(STACKDRIVER): + return stackdriver.NewTracer(ctx, logger, config) + case string(JAEGER): + return jaeger.NewTracer(ctx, logger, config) + default: + return nil, nil, errors.Errorf("tracing with type %s is not supported", tracingConf.Type) } + return nil, nil, errors.Errorf("tracing bla bla bla") } diff --git a/pkg/tracing/provider/jaeger/factory.go b/pkg/tracing/provider/jaeger/jaeger.go similarity index 54% rename from pkg/tracing/provider/jaeger/factory.go rename to pkg/tracing/provider/jaeger/jaeger.go index 6e6096eb66..b00b838b1e 100644 --- a/pkg/tracing/provider/jaeger/factory.go +++ b/pkg/tracing/provider/jaeger/jaeger.go @@ -10,21 +10,30 @@ import ( "github.com/uber/jaeger-client-go" "github.com/uber/jaeger-client-go/config" "github.com/uber/jaeger-lib/metrics/prometheus" - "gopkg.in/alecthomas/kingpin.v2" + "gopkg.in/yaml.v2" ) -// Factory implements tracing.Factory for Jaeger Tracer. -type Factory struct { +type Config struct { + ServiceName string `yaml:"service_name"` } +func parseConfig(conf []byte) (Config, error) { + config := Config{} + if err := yaml.Unmarshal(conf, &config); err != nil { + return Config{}, err + } + return config, nil +} -// NewFactory creates a new Factory -func NewFactory() *Factory { - return &Factory{} +func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { + config, err := parseConfig(conf) + if err != nil { + return nil, nil, err + } + return NewTracerWithConfig(ctx, logger, config) } -// Create implements tracing.Factory -func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer, error) { +func NewTracerWithConfig(ctx context.Context, logger log.Logger, conf Config) (opentracing.Tracer, io.Closer, error) { cfg, err := config.FromEnv() if err != nil { return nil, nil, err @@ -33,9 +42,7 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName str JaegerDebugHeader: tracing.ForceTracingBaggageKey, } cfg.Headers.ApplyDefaults() - if serviceName != "" { - cfg.ServiceName = serviceName - } + cfg.ServiceName = conf.ServiceName jLogger := &jaegerLogger{ logger: logger, @@ -50,7 +57,3 @@ func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName str } return tracer, closer, nil } - -// RegisterKingpinFlags implements tracing.Factory -func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { -} diff --git a/pkg/tracing/provider/stackdriver/factory.go b/pkg/tracing/provider/stackdriver/factory.go deleted file mode 100644 index d06a9dd88a..0000000000 --- a/pkg/tracing/provider/stackdriver/factory.go +++ /dev/null @@ -1,40 +0,0 @@ -package stackdriver - -import ( - "context" - "errors" - "io" - - "github.com/go-kit/kit/log" - "github.com/opentracing/opentracing-go" - "gopkg.in/alecthomas/kingpin.v2" -) - -// Factory implements tracing.Factory for Stackdriver Tracer. -type Factory struct { - gcloudTraceProjectID *string - sampleFactor *uint64 -} - -// NewFactory creates a new Factory -func NewFactory() *Factory { - return &Factory{} -} - -// Create implements tracing.Factory -func (f *Factory) Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer, error) { - if *f.gcloudTraceProjectID == "" { - return nil, nil, errors.New("stackdriver.project is empty.") - } - tracer, closer, err := newGCloudTracer(ctx, logger, *f.gcloudTraceProjectID, *f.sampleFactor, serviceName) - if err != nil { - return nil, nil, err - } - return tracer, closer, nil -} - -// RegisterKingpinFlags implements tracing.Factory -func (f *Factory) RegisterKingpinFlags(app *kingpin.Application) { - f.gcloudTraceProjectID = app.Flag("stackdriver.project", "GCP project to send Google Cloud Trace tracings to. If empty, tracing will be disabled.").Default("").String() - f.sampleFactor = app.Flag("stackdriver.sample-factor", "How often we send traces (1/). If 0 no trace will be sent periodically, unless forced by baggage item. See `pkg/tracing/tracing.go` for details.").Default("1").Uint64() -} diff --git a/pkg/tracing/provider/stackdriver/stackdriver.go b/pkg/tracing/provider/stackdriver/stackdriver.go new file mode 100644 index 0000000000..4e00c7e8ed --- /dev/null +++ b/pkg/tracing/provider/stackdriver/stackdriver.go @@ -0,0 +1,33 @@ +package stackdriver + +import ( + "context" + "io" + + "github.com/go-kit/kit/log" + "github.com/opentracing/opentracing-go" + "gopkg.in/yaml.v2" +) + +type Config struct { + ServiceName string `yaml:"service_name"` + ProjectId string `yaml:"project_id"` + SampleFactor uint64 `yaml:"sample_factor"` +} + +func parseConfig(conf []byte) (Config, error) { + config := Config{} + if err := yaml.Unmarshal(conf, &config); err != nil { + return Config{}, err + } + return config, nil +} + +func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { + config, err := parseConfig(conf) + if err != nil { + return nil, nil, err + } + println(config.ProjectId) + return newGCloudTracer(ctx, logger, config.ProjectId, config.SampleFactor, config.ServiceName) +} From 2d7460274d513d5cbaa415b6339930ae55d17c76 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Thu, 23 May 2019 12:30:13 +0300 Subject: [PATCH 20/35] Configure jaeger tracing from YAML. Some small fixes. --- cmd/thanos/flags.go | 19 +- cmd/thanos/main.go | 17 +- pkg/tracing/factory.go | 16 -- pkg/tracing/provider/factory.go | 17 +- pkg/tracing/provider/jaeger/config_yaml.go | 213 ++++++++++++++++++ pkg/tracing/provider/jaeger/jaeger.go | 50 ++-- .../provider/stackdriver/stackdriver.go | 11 +- 7 files changed, 263 insertions(+), 80 deletions(-) delete mode 100644 pkg/tracing/factory.go create mode 100644 pkg/tracing/provider/jaeger/config_yaml.go diff --git a/cmd/thanos/flags.go b/cmd/thanos/flags.go index 584ec3d742..006b472437 100644 --- a/cmd/thanos/flags.go +++ b/cmd/thanos/flags.go @@ -203,23 +203,20 @@ func regCommonObjStoreFlags(cmd *kingpin.CmdClause, suffix string, required bool } -func regCommonTracingFlags(cmd *kingpin.Application, suffix string, required bool, extraDesc ...string) *pathOrContent { - fileFlagName := fmt.Sprintf("tracing%s.config-file", suffix) - contentFlagName := fmt.Sprintf("tracing%s.config", suffix) +func regCommonTracingFlags(app *kingpin.Application) *pathOrContent { + fileFlagName := fmt.Sprintf("tracing.config-file") + contentFlagName := fmt.Sprintf("tracing.config") - help := fmt.Sprintf("Path to YAML file that contains tracing%s configuration.", suffix) - help = strings.Join(append([]string{help}, extraDesc...), " ") - tracingConfFile := cmd.Flag(fileFlagName, help).PlaceHolder("").String() + help := fmt.Sprintf("Path to YAML file that contains tracing configuration.") + tracingConfFile := app.Flag(fileFlagName, help).PlaceHolder("").String() - help = fmt.Sprintf("Alternative to '%s' flag. Tracing%s configuration in YAML.", fileFlagName, suffix) - help = strings.Join(append([]string{help}, extraDesc...), " ") - tracingConf := cmd.Flag(contentFlagName, help). - PlaceHolder("").String() + help = fmt.Sprintf("Alternative to '%s' flag. Tracing configuration in YAML.", fileFlagName) + tracingConf := app.Flag(contentFlagName, help).PlaceHolder("").String() return &pathOrContent{ fileFlagName: fileFlagName, contentFlagName: contentFlagName, - required: required, + required: false, path: tracingConfFile, content: tracingConf, diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 75dfb05a37..9d0f260ddb 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -67,10 +67,7 @@ func main() { logFormat := app.Flag("log.format", "Log format to use."). Default(logFormatLogfmt).Enum(logFormatLogfmt, logFormatJson) - //tracingFactory := provider.NewFactory(app) - - //objStoreConfig := regCommonObjStoreFlags(cmd, "", true) - tracingConfig := regCommonTracingFlags(app, "", false) + tracingConfig := regCommonTracingFlags(app) cmds := map[string]setupFunc{} registerSidecar(cmds, app, "sidecar") @@ -148,11 +145,19 @@ func main() { var closer io.Closer var confContentYaml []byte confContentYaml, err = tracingConfig.Content() - //tracer, closer = tracingFactory.Create(ctx, logger, *debugName) - tracer, closer, err = provider.NewTracer(ctx, logger, confContentYaml) + + if len(confContentYaml) == 0 { + level.Info(logger).Log("msg", "Tracing will be disabled") + tracer, closer, err = provider.NoopTracer() + } else { + tracer, closer, err = provider.NewTracer(ctx, logger, confContentYaml) + } if err != nil { fmt.Fprintln(os.Stderr, errors.Wrapf(err, "tracing failed")) + if closer != nil { + closer.Close() + } os.Exit(1) } diff --git a/pkg/tracing/factory.go b/pkg/tracing/factory.go deleted file mode 100644 index 3df43cbfd6..0000000000 --- a/pkg/tracing/factory.go +++ /dev/null @@ -1,16 +0,0 @@ -package tracing - -import ( - "context" - "io" - - "github.com/go-kit/kit/log" - "github.com/opentracing/opentracing-go" - "gopkg.in/alecthomas/kingpin.v2" -) - -// Factory defines an interface for a factory that can create implementations of different tracer types. -type Factory interface { - Create(ctx context.Context, logger log.Logger, serviceName string) (opentracing.Tracer, io.Closer, error) - RegisterKingpinFlags(app *kingpin.Application) -} diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/provider/factory.go index a6959795e4..c150262198 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/provider/factory.go @@ -24,20 +24,26 @@ const ( type TracingConfig struct { Type TracingProvider `yaml:"type"` - Config interface{} `yaml:"config"` + Config interface{} `yaml:"config,omitempty"` } func NewTracer(ctx context.Context, logger log.Logger, confContentYaml []byte) (opentracing.Tracer, io.Closer, error) { level.Info(logger).Log("msg", "loading tracing configuration") tracingConf := &TracingConfig{} + if err := yaml.UnmarshalStrict(confContentYaml, tracingConf); err != nil { - return &opentracing.NoopTracer{}, ioutil.NopCloser(nil), errors.Wrap(err, "parsing config YAML file") + return nil, nil, errors.Wrap(err, "parsing config tracing YAML") } - config, err := yaml.Marshal(tracingConf.Config) + var config []byte + var err error + if tracingConf.Config != nil { + config, err = yaml.Marshal(tracingConf.Config) + } if err != nil { return nil, nil, errors.Wrap(err, "marshal content of tracing configuration") } + switch strings.ToUpper(string(tracingConf.Type)) { case string(STACKDRIVER): return stackdriver.NewTracer(ctx, logger, config) @@ -46,5 +52,8 @@ func NewTracer(ctx context.Context, logger log.Logger, confContentYaml []byte) ( default: return nil, nil, errors.Errorf("tracing with type %s is not supported", tracingConf.Type) } - return nil, nil, errors.Errorf("tracing bla bla bla") +} + +func NoopTracer() (opentracing.Tracer, io.Closer, error) { + return &opentracing.NoopTracer{}, ioutil.NopCloser(nil), nil } diff --git a/pkg/tracing/provider/jaeger/config_yaml.go b/pkg/tracing/provider/jaeger/config_yaml.go new file mode 100644 index 0000000000..81637da7af --- /dev/null +++ b/pkg/tracing/provider/jaeger/config_yaml.go @@ -0,0 +1,213 @@ +package jaeger + +import ( + "fmt" + "net/url" + "os" + "strconv" + "strings" + "time" + + "github.com/opentracing/opentracing-go" + "github.com/pkg/errors" + "github.com/uber/jaeger-client-go" + "github.com/uber/jaeger-client-go/config" + "gopkg.in/yaml.v2" +) + +type Config struct { + ServiceName string `yaml:"service_name"` + Disabled string `yaml:"disabled"` + RPCMetrics string `yaml:"rpc_metrics"` + Tags string `yaml:"tags"` + SamplerType string `yaml:"sampler_type"` + SamplerParam string `yaml:"sampler_param"` + SamplerManagerHostPort string `yaml:"sampler_manager_host_port"` + SamplerMaxOperations string `yaml:"sampler_max_operations"` + SamplerRefreshInterval string `yaml:"sampler_refresh_interval"` + ReporterMaxQueueSize string `yaml:"reporter_max_queue_size"` + ReporterFlushInterval string `yaml:"reporter_flush_interval"` + ReporterLogSpans string `yaml:"reporter_log_spans"` + Endpoint string `yaml:"endpoint"` + User string `yaml:"user"` + Password string `yaml:"password"` + AgentHost string `yaml:"agent_host"` + AgentPort string `yaml:"agent_port"` +} + +// FromYaml uses config YAML to set the tracer's Configuration +func FromYaml(cfg []byte) (*config.Configuration, error) { + conf := &Config{} + + if err := yaml.Unmarshal(cfg, &conf); err != nil { + return nil, err + } + + c := &config.Configuration{} + + if e := conf.ServiceName; e != "" { + c.ServiceName = e + } + + if e := conf.RPCMetrics; e != "" { + if value, err := strconv.ParseBool(e); err == nil { + c.RPCMetrics = value + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", conf.RPCMetrics, e) + } + } + + if e := os.Getenv(conf.Disabled); e != "" { + if value, err := strconv.ParseBool(e); err == nil { + c.Disabled = value + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", conf.Disabled, e) + } + } + + if e := conf.Tags; e != "" { + c.Tags = parseTags(e) + } + + if s, err := samplerConfigFromConfig(*conf); err == nil { + c.Sampler = s + } else { + return nil, errors.Wrap(err, "cannot obtain sampler config from env") + } + + if r, err := reporterConfigFromEnv(*conf); err == nil { + c.Reporter = r + } else { + return nil, errors.Wrap(err, "cannot obtain reporter config from env") + } + + return c, nil +} + +// samplerConfigFromConfig creates a new SamplerConfig based on the YAML Config +func samplerConfigFromConfig(cfg Config) (*config.SamplerConfig, error) { + sc := &config.SamplerConfig{} + + if e := cfg.SamplerType; e != "" { + sc.Type = e + } + + if e := cfg.SamplerParam; e != "" { + if value, err := strconv.ParseFloat(e, 64); err == nil { + sc.Param = value + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.SamplerParam, e) + } + } + + if e := cfg.SamplerManagerHostPort; e != "" { + sc.SamplingServerURL = e + } + + if e := cfg.SamplerMaxOperations; e != "" { + if value, err := strconv.ParseInt(e, 10, 0); err == nil { + sc.MaxOperations = int(value) + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.SamplerMaxOperations, e) + } + } + + if e := cfg.SamplerRefreshInterval; e != "" { + if value, err := time.ParseDuration(e); err == nil { + sc.SamplingRefreshInterval = value + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.SamplerRefreshInterval, e) + } + } + + return sc, nil +} + +// reporterConfigFromConfig creates a new ReporterConfig based on the YAML Config +func reporterConfigFromEnv(cfg Config) (*config.ReporterConfig, error) { + rc := &config.ReporterConfig{} + + if e := cfg.ReporterMaxQueueSize; e != "" { + if value, err := strconv.ParseInt(e, 10, 0); err == nil { + rc.QueueSize = int(value) + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.ReporterMaxQueueSize, e) + } + } + + if e := cfg.ReporterFlushInterval; e != "" { + if value, err := time.ParseDuration(e); err == nil { + rc.BufferFlushInterval = value + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.ReporterFlushInterval, e) + } + } + + if e := cfg.ReporterLogSpans; e != "" { + if value, err := strconv.ParseBool(e); err == nil { + rc.LogSpans = value + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.ReporterLogSpans, e) + } + } + + if e := cfg.Endpoint; e != "" { + u, err := url.ParseRequestURI(e) + if err != nil { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.Endpoint, e) + } + rc.CollectorEndpoint = u.String() + user := cfg.User + pswd := cfg.Password + if user != "" && pswd == "" || user == "" && pswd != "" { + return nil, errors.Errorf("you must set %s and %s env vars together", cfg.User, cfg.Password) + } + rc.User = user + rc.Password = pswd + } else { + host := jaeger.DefaultUDPSpanServerHost + if e := cfg.AgentHost; e != "" { + host = e + } + + port := jaeger.DefaultUDPSpanServerPort + if e := cfg.AgentPort; e != "" { + if value, err := strconv.ParseInt(e, 10, 0); err == nil { + port = int(value) + } else { + return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.AgentPort, e) + } + } + rc.LocalAgentHostPort = fmt.Sprintf("%s:%d", host, port) + } + + return rc, nil +} + +// parseTags parses the given string into a collection of Tags. +// Spec for this value: +// - comma separated list of key=value +// - value can be specified using the notation ${envVar:defaultValue}, where `envVar` +// is an environment variable and `defaultValue` is the value to use in case the env var is not set +func parseTags(sTags string) []opentracing.Tag { + pairs := strings.Split(sTags, ",") + tags := make([]opentracing.Tag, 0) + for _, p := range pairs { + kv := strings.SplitN(p, "=", 2) + k, v := strings.TrimSpace(kv[0]), strings.TrimSpace(kv[1]) + + if strings.HasPrefix(v, "${") && strings.HasSuffix(v, "}") { + ed := strings.SplitN(v[2:len(v)-1], ":", 2) + e, d := ed[0], ed[1] + v = os.Getenv(e) + if v == "" && d != "" { + v = d + } + } + + tag := opentracing.Tag{Key: k, Value: v} + tags = append(tags, tag) + } + + return tags +} diff --git a/pkg/tracing/provider/jaeger/jaeger.go b/pkg/tracing/provider/jaeger/jaeger.go index b00b838b1e..1a300f3203 100644 --- a/pkg/tracing/provider/jaeger/jaeger.go +++ b/pkg/tracing/provider/jaeger/jaeger.go @@ -2,6 +2,7 @@ package jaeger import ( "context" + "github.com/go-kit/kit/log/level" "io" "github.com/go-kit/kit/log" @@ -10,50 +11,33 @@ import ( "github.com/uber/jaeger-client-go" "github.com/uber/jaeger-client-go/config" "github.com/uber/jaeger-lib/metrics/prometheus" - "gopkg.in/yaml.v2" ) -type Config struct { - ServiceName string `yaml:"service_name"` -} - -func parseConfig(conf []byte) (Config, error) { - config := Config{} - if err := yaml.Unmarshal(conf, &config); err != nil { - return Config{}, err - } - return config, nil -} - func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { - config, err := parseConfig(conf) - if err != nil { - return nil, nil, err + var ( + cfg *config.Configuration + err error + ) + if conf != nil { + level.Info(logger).Log("msg", "loading Jaeger tracing configuration from YAML") + cfg, err = FromYaml(conf) + } else { + level.Info(logger).Log("msg", "loading Jaeger tracing configuration from ENV") + cfg, err = config.FromEnv() } - return NewTracerWithConfig(ctx, logger, config) -} - -func NewTracerWithConfig(ctx context.Context, logger log.Logger, conf Config) (opentracing.Tracer, io.Closer, error) { - cfg, err := config.FromEnv() if err != nil { return nil, nil, err } + cfg.Headers = &jaeger.HeadersConfig{ JaegerDebugHeader: tracing.ForceTracingBaggageKey, } cfg.Headers.ApplyDefaults() - cfg.ServiceName = conf.ServiceName - jLogger := &jaegerLogger{ - logger: logger, - } - jMetricsFactory := prometheus.New() - tracer, closer, err := cfg.NewTracer( - config.Metrics(jMetricsFactory), - config.Logger(jLogger), + return cfg.NewTracer( + config.Metrics(prometheus.New()), + config.Logger(&jaegerLogger{ + logger: logger, + }), ) - if err != nil { - return nil, nil, err - } - return tracer, closer, nil } diff --git a/pkg/tracing/provider/stackdriver/stackdriver.go b/pkg/tracing/provider/stackdriver/stackdriver.go index 4e00c7e8ed..a16aff6f1d 100644 --- a/pkg/tracing/provider/stackdriver/stackdriver.go +++ b/pkg/tracing/provider/stackdriver/stackdriver.go @@ -15,19 +15,10 @@ type Config struct { SampleFactor uint64 `yaml:"sample_factor"` } -func parseConfig(conf []byte) (Config, error) { +func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { config := Config{} if err := yaml.Unmarshal(conf, &config); err != nil { - return Config{}, err - } - return config, nil -} - -func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { - config, err := parseConfig(conf) - if err != nil { return nil, nil, err } - println(config.ProjectId) return newGCloudTracer(ctx, logger, config.ProjectId, config.SampleFactor, config.ServiceName) } From 72eaca4ed71e81445e37d0c9d5dd2ee8354cd778 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Thu, 23 May 2019 13:51:56 +0300 Subject: [PATCH 21/35] Fix errcheck --- cmd/thanos/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 9d0f260ddb..26677f705b 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -156,7 +156,9 @@ func main() { if err != nil { fmt.Fprintln(os.Stderr, errors.Wrapf(err, "tracing failed")) if closer != nil { - closer.Close() + if err = closer.Close(); err != nil { + level.Warn(logger).Log("msg", "closing tracer failed", "err", err) + } } os.Exit(1) } From 1a9b83d8b19c93a1fc2730b148e9abdfbed38550 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Fri, 24 May 2019 16:04:42 +0300 Subject: [PATCH 22/35] Add X-Thanos-Trace-Id HTTP header for simplified search traces --- pkg/tracing/http.go | 8 +++++++- pkg/tracing/provider/jaeger/jaeger.go | 21 +++++++++++++++++++-- pkg/tracing/provider/stackdriver/tracer.go | 10 +++++++++- pkg/tracing/tracer.go | 3 +++ pkg/tracing/tracing.go | 8 ++++++++ tracing.conf | 4 ++++ 6 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 pkg/tracing/tracer.go create mode 100644 tracing.conf diff --git a/pkg/tracing/http.go b/pkg/tracing/http.go index a27171d7e5..65970be8ef 100644 --- a/pkg/tracing/http.go +++ b/pkg/tracing/http.go @@ -8,7 +8,7 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" - opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" ) @@ -34,6 +34,12 @@ func HTTPMiddleware(tracer opentracing.Tracer, name string, logger log.Logger, n // If client specified ForceTracingBaggageKey header, ensure span includes it to force tracing. span.SetBaggageItem(ForceTracingBaggageKey, r.Header.Get(ForceTracingBaggageKey)) + if t, ok := tracer.(Tracer); ok { + if traceId, ok :=t.GetTraceIdFromSpanContext(span.Context()); ok { + w.Header().Set(traceIdResponseHeader, traceId) + } + } + next.ServeHTTP(w, r.WithContext(opentracing.ContextWithSpan(ContextWithTracer(r.Context(), tracer), span))) span.Finish() return diff --git a/pkg/tracing/provider/jaeger/jaeger.go b/pkg/tracing/provider/jaeger/jaeger.go index 1a300f3203..b925f0931d 100644 --- a/pkg/tracing/provider/jaeger/jaeger.go +++ b/pkg/tracing/provider/jaeger/jaeger.go @@ -2,6 +2,7 @@ package jaeger import ( "context" + "fmt" "github.com/go-kit/kit/log/level" "io" @@ -13,10 +14,23 @@ import ( "github.com/uber/jaeger-lib/metrics/prometheus" ) +type Tracer struct { + opentracing.Tracer +} + +func (t *Tracer) GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, bool) { + if c, ok := ctx.(jaeger.SpanContext); ok { + return fmt.Sprintf("%016x", c.TraceID().Low), true + } + return "", false +} + func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { var ( cfg *config.Configuration err error + jaegerTracer opentracing.Tracer + closer io.Closer ) if conf != nil { level.Info(logger).Log("msg", "loading Jaeger tracing configuration from YAML") @@ -33,11 +47,14 @@ func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing JaegerDebugHeader: tracing.ForceTracingBaggageKey, } cfg.Headers.ApplyDefaults() - - return cfg.NewTracer( + jaegerTracer, closer, err = cfg.NewTracer( config.Metrics(prometheus.New()), config.Logger(&jaegerLogger{ logger: logger, }), ) + t := &Tracer{ + jaegerTracer, + } + return t, closer, err } diff --git a/pkg/tracing/provider/stackdriver/tracer.go b/pkg/tracing/provider/stackdriver/tracer.go index e6e91f9263..1dc33a290e 100644 --- a/pkg/tracing/provider/stackdriver/tracer.go +++ b/pkg/tracing/provider/stackdriver/tracer.go @@ -7,10 +7,10 @@ import ( "os" "cloud.google.com/go/trace/apiv1" - "github.com/lovoo/gcloud-opentracing" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/improbable-eng/thanos/pkg/tracing" + "github.com/lovoo/gcloud-opentracing" "github.com/opentracing/basictracer-go" "github.com/opentracing/opentracing-go" "github.com/prometheus/common/version" @@ -21,6 +21,14 @@ type tracer struct { wrapped opentracing.Tracer } +func (t *tracer) GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, bool) { + if c, ok := ctx.(basictracer.SpanContext); ok { + // "%016x%016x" - ugly hack for gcloud find traces by ID https://console.cloud.google.com/traces/traces?project=&tid=<62119f61b7c2663962119f61b7c26639> + return fmt.Sprintf("%016x%016x", c.TraceID, c.TraceID), true + } + return "", false +} + func (t *tracer) StartSpan(operationName string, opts ...opentracing.StartSpanOption) opentracing.Span { span := t.wrapped.StartSpan(operationName, opts...) diff --git a/pkg/tracing/tracer.go b/pkg/tracing/tracer.go new file mode 100644 index 0000000000..96e6936b00 --- /dev/null +++ b/pkg/tracing/tracer.go @@ -0,0 +1,3 @@ +package tracing + + diff --git a/pkg/tracing/tracing.go b/pkg/tracing/tracing.go index 2de35e7497..730829e12a 100644 --- a/pkg/tracing/tracing.go +++ b/pkg/tracing/tracing.go @@ -9,10 +9,18 @@ import ( // ForceTracingBaggageKey - force sampling header. const ForceTracingBaggageKey = "X-Thanos-Force-Tracing" + +// traceIdResponseHeader - Trace ID response header. +const traceIdResponseHeader = "X-Thanos-Trace-Id" + type contextKey struct{} var tracerKey = contextKey{} +type Tracer interface { + GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, bool) +} + // ContextWithTracer returns a new `context.Context` that holds a reference to given opentracing.Tracer. func ContextWithTracer(ctx context.Context, tracer opentracing.Tracer) context.Context { return context.WithValue(ctx, tracerKey, tracer) diff --git a/tracing.conf b/tracing.conf new file mode 100644 index 0000000000..27b5d99679 --- /dev/null +++ b/tracing.conf @@ -0,0 +1,4 @@ +type: JAEGER +config: + service_name: ttt + sampler_param: 1 From 27be8ea613a08726a67b70c654adce636916f6b6 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Fri, 24 May 2019 16:28:36 +0300 Subject: [PATCH 23/35] Cleanup --- pkg/tracing/tracer.go | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 pkg/tracing/tracer.go diff --git a/pkg/tracing/tracer.go b/pkg/tracing/tracer.go deleted file mode 100644 index 96e6936b00..0000000000 --- a/pkg/tracing/tracer.go +++ /dev/null @@ -1,3 +0,0 @@ -package tracing - - From e46fae6fc1544fd021bcf69f3b25a428bf9c49d2 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Fri, 24 May 2019 17:32:00 +0300 Subject: [PATCH 24/35] make docs --- docs/components/bucket.md | 57 ++++++++++++++++---------------------- docs/components/compact.md | 15 ++++------ docs/components/query.md | 15 ++++------ docs/components/rule.md | 15 ++++------ docs/components/sidecar.md | 15 ++++------ docs/components/store.md | 15 ++++------ 6 files changed, 54 insertions(+), 78 deletions(-) diff --git a/docs/components/bucket.md b/docs/components/bucket.md index cd0f7a590a..f8cacc4200 100644 --- a/docs/components/bucket.md +++ b/docs/components/bucket.md @@ -42,15 +42,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). - --stackdriver.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings to. - If empty, tracing will be disabled. - --stackdriver.sample-factor=1 - How often we send traces (1/). If 0 no - trace will be sent periodically, unless forced by - baggage item. See `pkg/tracing/tracing.go` for - details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. Tracing + configuration in YAML. --objstore.config-file= Path to YAML file that contains object store configuration. @@ -93,14 +90,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings to. - If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 - How often we send traces (1/). If 0 no - trace will be sent periodically, unless forced by - baggage item. See `pkg/tracing/tracing.go` for - details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. Tracing + configuration in YAML. --objstore.config-file= Path to YAML file that contains object store configuration. @@ -150,14 +145,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings to. - If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 - How often we send traces (1/). If 0 no - trace will be sent periodically, unless forced by - baggage item. See `pkg/tracing/tracing.go` for - details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. Tracing + configuration in YAML. --objstore.config-file= Path to YAML file that contains object store configuration. @@ -191,14 +184,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --gcloudtrace.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings to. - If empty, tracing will be disabled. - --gcloudtrace.sample-factor=1 - How often we send traces (1/). If 0 - no trace will be sent periodically, unless forced - by baggage item. See `pkg/tracing/tracing.go` for - details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. Tracing + configuration in YAML. --objstore.config-file= Path to YAML file that contains object store configuration. diff --git a/docs/components/compact.md b/docs/components/compact.md index b2ce5326e6..0254170871 100644 --- a/docs/components/compact.md +++ b/docs/components/compact.md @@ -42,15 +42,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). - --stackdriver.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings - to. If empty, tracing will be disabled. - --stackdriver.sample-factor=1 - How often we send traces (1/). If - 0 no trace will be sent periodically, unless - forced by baggage item. See - `pkg/tracing/tracing.go` for details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. + Tracing configuration in YAML. --http-address="0.0.0.0:10902" Listen host:port for HTTP endpoints. --data-dir="./data" Data directory in which to cache blocks and diff --git a/docs/components/query.md b/docs/components/query.md index 86a58e1a95..3ddaca6168 100644 --- a/docs/components/query.md +++ b/docs/components/query.md @@ -174,15 +174,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). - --stackdriver.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings - to. If empty, tracing will be disabled. - --stackdriver.sample-factor=1 - How often we send traces (1/). - If 0 no trace will be sent periodically, unless - forced by baggage item. See - `pkg/tracing/tracing.go` for details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. + Tracing configuration in YAML. --http-address="0.0.0.0:10902" Listen host:port for HTTP endpoints. --grpc-address="0.0.0.0:10901" diff --git a/docs/components/rule.md b/docs/components/rule.md index d0f28f8457..138d9100df 100644 --- a/docs/components/rule.md +++ b/docs/components/rule.md @@ -156,15 +156,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). - --stackdriver.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings - to. If empty, tracing will be disabled. - --stackdriver.sample-factor=1 - How often we send traces (1/). - If 0 no trace will be sent periodically, unless - forced by baggage item. See - `pkg/tracing/tracing.go` for details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. + Tracing configuration in YAML. --http-address="0.0.0.0:10902" Listen host:port for HTTP endpoints. --grpc-address="0.0.0.0:10901" diff --git a/docs/components/sidecar.md b/docs/components/sidecar.md index 1e68395bc2..fe1de9bcf4 100644 --- a/docs/components/sidecar.md +++ b/docs/components/sidecar.md @@ -58,15 +58,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). - --stackdriver.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings - to. If empty, tracing will be disabled. - --stackdriver.sample-factor=1 - How often we send traces (1/). - If 0 no trace will be sent periodically, unless - forced by baggage item. See - `pkg/tracing/tracing.go` for details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. + Tracing configuration in YAML. --http-address="0.0.0.0:10902" Listen host:port for HTTP endpoints. --grpc-address="0.0.0.0:10901" diff --git a/docs/components/store.md b/docs/components/store.md index 3e9e5b70f2..56e9487bb5 100644 --- a/docs/components/store.md +++ b/docs/components/store.md @@ -42,15 +42,12 @@ Flags: --version Show application version. --log.level=info Log filtering level. --log.format=logfmt Log format to use. - --tracing.type=noop Tracer to use (stackdriver/jaeger/noop). - --stackdriver.project=GCLOUDTRACE.PROJECT - GCP project to send Google Cloud Trace tracings - to. If empty, tracing will be disabled. - --stackdriver.sample-factor=1 - How often we send traces (1/). - If 0 no trace will be sent periodically, unless - forced by baggage item. See - `pkg/tracing/tracing.go` for details. + --tracing.config-file= + Path to YAML file that contains tracing + configuration. + --tracing.config= + Alternative to 'tracing.config-file' flag. + Tracing configuration in YAML. --http-address="0.0.0.0:10902" Listen host:port for HTTP endpoints. --grpc-address="0.0.0.0:10901" From 2596e11e54771da026b86daabb608c8e00d9df62 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Fri, 24 May 2019 19:24:33 +0300 Subject: [PATCH 25/35] Add store addr to tracing tags. --- pkg/store/proxy.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/store/proxy.go b/pkg/store/proxy.go index b9fd49edf0..95142808d4 100644 --- a/pkg/store/proxy.go +++ b/pkg/store/proxy.go @@ -11,9 +11,11 @@ import ( "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" + grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing" "github.com/improbable-eng/thanos/pkg/component" "github.com/improbable-eng/thanos/pkg/store/storepb" "github.com/improbable-eng/thanos/pkg/strutil" + "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/prometheus/tsdb/labels" "golang.org/x/sync/errgroup" @@ -179,6 +181,9 @@ func (s *ProxyStore) Series(r *storepb.SeriesRequest, srv storepb.Store_SeriesSe // This is used to cancel this stream when one operations takes too long. seriesCtx, closeSeries := context.WithCancel(gctx) + seriesCtx = grpc_opentracing.ClientAddContextTags(seriesCtx, opentracing.Tags{ + "target": st.Addr(), + }) defer closeSeries() sc, err := st.Series(seriesCtx, r) From 0d9af0168d3040e9b67a4213f2ae09e6b4069236 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Mon, 27 May 2019 19:14:18 +0300 Subject: [PATCH 26/35] Tracing refactoring. --- cmd/thanos/main.go | 21 +++++++------------ pkg/tracing/{provider => client}/factory.go | 17 +++++++-------- .../{provider => }/jaeger/config_yaml.go | 8 +++---- pkg/tracing/{provider => }/jaeger/jaeger.go | 0 pkg/tracing/{provider => }/jaeger/logger.go | 0 .../{provider => }/stackdriver/stackdriver.go | 0 .../{provider => }/stackdriver/tracer.go | 0 .../{provider => }/stackdriver/tracer_test.go | 0 tracing.conf | 4 ---- 9 files changed, 19 insertions(+), 31 deletions(-) rename pkg/tracing/{provider => client}/factory.go (76%) rename pkg/tracing/{provider => }/jaeger/config_yaml.go (97%) rename pkg/tracing/{provider => }/jaeger/jaeger.go (100%) rename pkg/tracing/{provider => }/jaeger/logger.go (100%) rename pkg/tracing/{provider => }/stackdriver/stackdriver.go (100%) rename pkg/tracing/{provider => }/stackdriver/tracer.go (100%) rename pkg/tracing/{provider => }/stackdriver/tracer_test.go (100%) delete mode 100644 tracing.conf diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 26677f705b..1618c985cb 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -5,7 +5,6 @@ import ( "crypto/tls" "crypto/x509" "fmt" - "github.com/improbable-eng/thanos/pkg/tracing/provider" "io" "io/ioutil" "math" @@ -20,15 +19,15 @@ import ( "syscall" gmetrics "github.com/armon/go-metrics" - gprom "github.com/armon/go-metrics/prometheus" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/grpc-ecosystem/go-grpc-middleware" - "github.com/grpc-ecosystem/go-grpc-middleware/recovery" + grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery" "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/improbable-eng/thanos/pkg/runutil" "github.com/improbable-eng/thanos/pkg/tracing" + "github.com/improbable-eng/thanos/pkg/tracing/client" "github.com/oklog/run" "github.com/opentracing/opentracing-go" "github.com/pkg/errors" @@ -148,19 +147,13 @@ func main() { if len(confContentYaml) == 0 { level.Info(logger).Log("msg", "Tracing will be disabled") - tracer, closer, err = provider.NoopTracer() + tracer = client.NoopTracer() } else { - tracer, closer, err = provider.NewTracer(ctx, logger, confContentYaml) - } - - if err != nil { - fmt.Fprintln(os.Stderr, errors.Wrapf(err, "tracing failed")) - if closer != nil { - if err = closer.Close(); err != nil { - level.Warn(logger).Log("msg", "closing tracer failed", "err", err) - } + tracer, closer, err = client.NewTracer(ctx, logger, confContentYaml) + if err != nil { + fmt.Fprintln(os.Stderr, errors.Wrapf(err, "tracing failed")) + os.Exit(1) } - os.Exit(1) } // This is bad, but Prometheus does not support any other tracer injections than just global one. diff --git a/pkg/tracing/provider/factory.go b/pkg/tracing/client/factory.go similarity index 76% rename from pkg/tracing/provider/factory.go rename to pkg/tracing/client/factory.go index c150262198..5a085d6a2c 100644 --- a/pkg/tracing/provider/factory.go +++ b/pkg/tracing/client/factory.go @@ -1,15 +1,14 @@ -package provider +package client import ( "context" "io" - "io/ioutil" "strings" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" - "github.com/improbable-eng/thanos/pkg/tracing/provider/jaeger" - "github.com/improbable-eng/thanos/pkg/tracing/provider/stackdriver" + "github.com/improbable-eng/thanos/pkg/tracing/jaeger" + "github.com/improbable-eng/thanos/pkg/tracing/stackdriver" "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "gopkg.in/yaml.v2" @@ -39,9 +38,9 @@ func NewTracer(ctx context.Context, logger log.Logger, confContentYaml []byte) ( var err error if tracingConf.Config != nil { config, err = yaml.Marshal(tracingConf.Config) - } - if err != nil { - return nil, nil, errors.Wrap(err, "marshal content of tracing configuration") + if err != nil { + return nil, nil, errors.Wrap(err, "marshal content of tracing configuration") + } } switch strings.ToUpper(string(tracingConf.Type)) { @@ -54,6 +53,6 @@ func NewTracer(ctx context.Context, logger log.Logger, confContentYaml []byte) ( } } -func NoopTracer() (opentracing.Tracer, io.Closer, error) { - return &opentracing.NoopTracer{}, ioutil.NopCloser(nil), nil +func NoopTracer() opentracing.Tracer { + return &opentracing.NoopTracer{} } diff --git a/pkg/tracing/provider/jaeger/config_yaml.go b/pkg/tracing/jaeger/config_yaml.go similarity index 97% rename from pkg/tracing/provider/jaeger/config_yaml.go rename to pkg/tracing/jaeger/config_yaml.go index 81637da7af..2e11dd03a7 100644 --- a/pkg/tracing/provider/jaeger/config_yaml.go +++ b/pkg/tracing/jaeger/config_yaml.go @@ -35,7 +35,7 @@ type Config struct { AgentPort string `yaml:"agent_port"` } -// FromYaml uses config YAML to set the tracer's Configuration +// FromYaml uses config YAML to set the tracer's Configuration. func FromYaml(cfg []byte) (*config.Configuration, error) { conf := &Config{} @@ -84,7 +84,7 @@ func FromYaml(cfg []byte) (*config.Configuration, error) { return c, nil } -// samplerConfigFromConfig creates a new SamplerConfig based on the YAML Config +// samplerConfigFromConfig creates a new SamplerConfig based on the YAML Config. func samplerConfigFromConfig(cfg Config) (*config.SamplerConfig, error) { sc := &config.SamplerConfig{} @@ -123,7 +123,7 @@ func samplerConfigFromConfig(cfg Config) (*config.SamplerConfig, error) { return sc, nil } -// reporterConfigFromConfig creates a new ReporterConfig based on the YAML Config +// reporterConfigFromConfig creates a new ReporterConfig based on the YAML Config. func reporterConfigFromEnv(cfg Config) (*config.ReporterConfig, error) { rc := &config.ReporterConfig{} @@ -188,7 +188,7 @@ func reporterConfigFromEnv(cfg Config) (*config.ReporterConfig, error) { // Spec for this value: // - comma separated list of key=value // - value can be specified using the notation ${envVar:defaultValue}, where `envVar` -// is an environment variable and `defaultValue` is the value to use in case the env var is not set +// is an environment variable and `defaultValue` is the value to use in case the env var is not set. func parseTags(sTags string) []opentracing.Tag { pairs := strings.Split(sTags, ",") tags := make([]opentracing.Tag, 0) diff --git a/pkg/tracing/provider/jaeger/jaeger.go b/pkg/tracing/jaeger/jaeger.go similarity index 100% rename from pkg/tracing/provider/jaeger/jaeger.go rename to pkg/tracing/jaeger/jaeger.go diff --git a/pkg/tracing/provider/jaeger/logger.go b/pkg/tracing/jaeger/logger.go similarity index 100% rename from pkg/tracing/provider/jaeger/logger.go rename to pkg/tracing/jaeger/logger.go diff --git a/pkg/tracing/provider/stackdriver/stackdriver.go b/pkg/tracing/stackdriver/stackdriver.go similarity index 100% rename from pkg/tracing/provider/stackdriver/stackdriver.go rename to pkg/tracing/stackdriver/stackdriver.go diff --git a/pkg/tracing/provider/stackdriver/tracer.go b/pkg/tracing/stackdriver/tracer.go similarity index 100% rename from pkg/tracing/provider/stackdriver/tracer.go rename to pkg/tracing/stackdriver/tracer.go diff --git a/pkg/tracing/provider/stackdriver/tracer_test.go b/pkg/tracing/stackdriver/tracer_test.go similarity index 100% rename from pkg/tracing/provider/stackdriver/tracer_test.go rename to pkg/tracing/stackdriver/tracer_test.go diff --git a/tracing.conf b/tracing.conf deleted file mode 100644 index 27b5d99679..0000000000 --- a/tracing.conf +++ /dev/null @@ -1,4 +0,0 @@ -type: JAEGER -config: - service_name: ttt - sampler_param: 1 From b60a5367cd5b539dadc2eda9db4841b18047a36e Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Mon, 27 May 2019 19:21:58 +0300 Subject: [PATCH 27/35] Fix noop tracing closer. --- cmd/thanos/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 1618c985cb..2c37db5387 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -166,8 +166,10 @@ func main() { <-ctx.Done() return ctx.Err() }, func(error) { - if err := closer.Close(); err != nil { - level.Warn(logger).Log("msg", "closing tracer failed", "err", err) + if closer != nil { + if err := closer.Close(); err != nil { + level.Warn(logger).Log("msg", "closing tracer failed", "err", err) + } } cancel() }) From c7b67cab394784f041d15646fdfd78c277030393 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 28 May 2019 11:23:48 +0300 Subject: [PATCH 28/35] Add few tracing spans. --- pkg/store/prometheus.go | 7 +++++++ pkg/store/proxy.go | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/store/prometheus.go b/pkg/store/prometheus.go index d79c7a74ed..54ef116ca9 100644 --- a/pkg/store/prometheus.go +++ b/pkg/store/prometheus.go @@ -152,6 +152,7 @@ func (p *PrometheusStore) Series(r *storepb.SeriesRequest, s storepb.Store_Serie span, _ := tracing.StartSpan(s.Context(), "transform_and_respond") defer span.Finish() + span.SetTag("series_count", len(resp.Results[0].Timeseries)) for _, e := range resp.Results[0].Timeseries { lset := p.translateAndExtendLabels(e.Labels, ext) @@ -236,10 +237,12 @@ func (p *PrometheusStore) promSeries(ctx context.Context, q prompb.Query) (*prom preq = preq.WithContext(ctx) + spanReqDo, ctx := tracing.StartSpan(ctx, "query_prometheus_request") presp, err := p.client.Do(preq) if err != nil { return nil, errors.Wrap(err, "send request") } + spanReqDo.Finish() defer runutil.CloseWithLogOnErr(p.logger, presp.Body, "prom series request body") if presp.StatusCode/100 != 2 { @@ -253,16 +256,20 @@ func (p *PrometheusStore) promSeries(ctx context.Context, q prompb.Query) (*prom if _, err := io.Copy(buf, presp.Body); err != nil { return nil, errors.Wrap(err, "copy response") } + spanSnappyDecode, ctx := tracing.StartSpan(ctx, "decompress_response") decomp, err := snappy.Decode(p.getBuffer(), buf.Bytes()) + spanSnappyDecode.Finish() defer p.putBuffer(decomp) if err != nil { return nil, errors.Wrap(err, "decompress response") } var data prompb.ReadResponse + spanUnmarshal, ctx := tracing.StartSpan(ctx, "unmarshal_response") if err := proto.Unmarshal(decomp, &data); err != nil { return nil, errors.Wrap(err, "unmarshal response") } + spanUnmarshal.Finish() if len(data.Results) != 1 { return nil, errors.Errorf("unexepected result size %d", len(data.Results)) } diff --git a/pkg/store/proxy.go b/pkg/store/proxy.go index 95142808d4..d7865c07d0 100644 --- a/pkg/store/proxy.go +++ b/pkg/store/proxy.go @@ -3,6 +3,7 @@ package store import ( "context" "fmt" + "github.com/improbable-eng/thanos/pkg/tracing" "io" "math" "strings" @@ -173,7 +174,10 @@ func (s *ProxyStore) Series(r *storepb.SeriesRequest, srv storepb.Store_SeriesSe // We might be able to skip the store if its meta information indicates // it cannot have series matching our query. // NOTE: all matchers are validated in labelsMatches method so we explicitly ignore error. - if ok, _ := storeMatches(st, r.MinTime, r.MaxTime, r.Matchers...); !ok { + spanStoreMathes, gctx := tracing.StartSpan(gctx, "store_mathes") + ok, _ := storeMatches(st, r.MinTime, r.MaxTime, r.Matchers...) + spanStoreMathes.Finish() + if !ok { storeDebugMsgs = append(storeDebugMsgs, fmt.Sprintf("store %s filtered out", st)) continue } From 2e942f1219ad8a9785af1b2b0a974cffd7c10a20 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 28 May 2019 18:36:52 +0300 Subject: [PATCH 29/35] Pass prometheus registry to jaeger. --- cmd/thanos/main.go | 2 +- pkg/tracing/client/factory.go | 5 +++-- pkg/tracing/jaeger/jaeger.go | 7 ++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/thanos/main.go b/cmd/thanos/main.go index 2c37db5387..538b5d58c1 100644 --- a/cmd/thanos/main.go +++ b/cmd/thanos/main.go @@ -149,7 +149,7 @@ func main() { level.Info(logger).Log("msg", "Tracing will be disabled") tracer = client.NoopTracer() } else { - tracer, closer, err = client.NewTracer(ctx, logger, confContentYaml) + tracer, closer, err = client.NewTracer(ctx, logger, metrics, confContentYaml) if err != nil { fmt.Fprintln(os.Stderr, errors.Wrapf(err, "tracing failed")) os.Exit(1) diff --git a/pkg/tracing/client/factory.go b/pkg/tracing/client/factory.go index 5a085d6a2c..145378c9a8 100644 --- a/pkg/tracing/client/factory.go +++ b/pkg/tracing/client/factory.go @@ -5,6 +5,7 @@ import ( "io" "strings" + "github.com/prometheus/client_golang/prometheus" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/improbable-eng/thanos/pkg/tracing/jaeger" @@ -26,7 +27,7 @@ type TracingConfig struct { Config interface{} `yaml:"config,omitempty"` } -func NewTracer(ctx context.Context, logger log.Logger, confContentYaml []byte) (opentracing.Tracer, io.Closer, error) { +func NewTracer(ctx context.Context, logger log.Logger, metrics *prometheus.Registry, confContentYaml []byte) (opentracing.Tracer, io.Closer, error) { level.Info(logger).Log("msg", "loading tracing configuration") tracingConf := &TracingConfig{} @@ -47,7 +48,7 @@ func NewTracer(ctx context.Context, logger log.Logger, confContentYaml []byte) ( case string(STACKDRIVER): return stackdriver.NewTracer(ctx, logger, config) case string(JAEGER): - return jaeger.NewTracer(ctx, logger, config) + return jaeger.NewTracer(ctx, logger, metrics, config) default: return nil, nil, errors.Errorf("tracing with type %s is not supported", tracingConf.Type) } diff --git a/pkg/tracing/jaeger/jaeger.go b/pkg/tracing/jaeger/jaeger.go index b925f0931d..52ab2c7cb4 100644 --- a/pkg/tracing/jaeger/jaeger.go +++ b/pkg/tracing/jaeger/jaeger.go @@ -11,7 +11,8 @@ import ( "github.com/opentracing/opentracing-go" "github.com/uber/jaeger-client-go" "github.com/uber/jaeger-client-go/config" - "github.com/uber/jaeger-lib/metrics/prometheus" + jaeger_prometheus "github.com/uber/jaeger-lib/metrics/prometheus" + "github.com/prometheus/client_golang/prometheus" ) type Tracer struct { @@ -25,7 +26,7 @@ func (t *Tracer) GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, return "", false } -func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { +func NewTracer(ctx context.Context, logger log.Logger, metrics *prometheus.Registry, conf []byte) (opentracing.Tracer, io.Closer, error) { var ( cfg *config.Configuration err error @@ -48,7 +49,7 @@ func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing } cfg.Headers.ApplyDefaults() jaegerTracer, closer, err = cfg.NewTracer( - config.Metrics(prometheus.New()), + config.Metrics(jaeger_prometheus.New(jaeger_prometheus.WithRegisterer(metrics))), config.Logger(&jaegerLogger{ logger: logger, }), From 56427711ae15aa5e184f46877d985a0b6dde366b Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Wed, 29 May 2019 12:13:16 +0300 Subject: [PATCH 30/35] go.mod --- go.mod | 2 -- go.sum | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 61190309e8..1e287412ce 100644 --- a/go.mod +++ b/go.mod @@ -16,8 +16,6 @@ require ( github.com/gophercloud/gophercloud v0.0.0-20181206160319-9d88c34913a9 github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 github.com/grpc-ecosystem/go-grpc-prometheus v0.0.0-20181025070259-68e3a13e4117 - github.com/hashicorp/go-sockaddr v1.0.0 - github.com/hashicorp/go-version v1.2.0 github.com/hashicorp/golang-lru v0.5.1 github.com/julienschmidt/httprouter v1.1.0 // indirect github.com/leanovate/gopter v0.2.4 diff --git a/go.sum b/go.sum index 8ed9a5bc98..0907a04252 100644 --- a/go.sum +++ b/go.sum @@ -1,34 +1,46 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= contrib.go.opencensus.io/exporter/ocagent v0.4.1/go.mod h1:b6YwD5Q3Yvj4yk0CDK5vGXexygNzI09aXUdDEakQBgA= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= git.apache.org/thrift.git v0.0.0-20181218151757-9b75e4fe745a/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= +github.com/Azure/azure-pipeline-go v0.1.8 h1:KmVRa8oFMaargVesEuuEoiLCQ4zCCwQ8QX/xg++KS20= github.com/Azure/azure-pipeline-go v0.1.8/go.mod h1:XA1kFWRVhSK+KNFiOhfv83Fv8L9achrP7OxIzeTn1Yg= github.com/Azure/azure-sdk-for-go v23.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-storage-blob-go v0.0.0-20181022225951-5152f14ace1c h1:Y5ueznoCekgCWBytF1Q9lTpZ3tJeX37dQtCcGjMCLYI= github.com/Azure/azure-storage-blob-go v0.0.0-20181022225951-5152f14ace1c/go.mod h1:oGfmITT1V6x//CswqY2gtAHND+xIP64/qL7a5QJix0Y= github.com/Azure/go-autorest v11.2.8+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= +github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= +github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/aws/aws-sdk-go v0.0.0-20180507225419-00862f899353/go.mod h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/biogo/store v0.0.0-20160505134755-913427a1d5e8/go.mod h1:Iev9Q3MErcn+w3UOJD/DkEzllvugfdx7bGcMOFhvr/4= github.com/cenk/backoff v2.0.0+incompatible/go.mod h1:7FtoeaSnHoZnmZzz47cM35Y9nSW7tNyaidugnHTaFDE= github.com/census-instrumentation/opencensus-proto v0.1.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/certifi/gocertifi v0.0.0-20180905225744-ee1a9a0726d2/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292/go.mod h1:qRiX68mZX1lGBkTWyp3CLcenw9I94W2dLeRvMzcn9N4= github.com/cockroachdb/cockroach v0.0.0-20170608034007-84bc9597164f/go.mod h1:xeT/CQ0qZHangbYbWShlCGAx31aV4AjGswDUjhKS6HQ= github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk= +github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v0.0.0-20161101193935-9ed569b5d1ac/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= @@ -37,42 +49,59 @@ github.com/elastic/gosigar v0.9.0/go.mod h1:cdorVVzy1fhmEqmtgqkoE3bYtCfSCkVyjTyC github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= github.com/evanphx/json-patch v4.1.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA= +github.com/fatih/structtag v1.0.0 h1:pTHj65+u3RKWYPSGaU290FpI/dXxTaHdVwVwbcPKmEc= github.com/fatih/structtag v1.0.0/go.mod h1:IKitwq45uXL/yqi5mYghiD3w9H6eTOvI9vnk8tXMphA= github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/getsentry/raven-go v0.1.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-ini/ini v1.21.1/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= +github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.0 h1:xU6/SpYbvkNYiptHJYEDRseDLvYE7wSqhYYNy0QSUzI= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20180924190550-6f2cf27854a4/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20160529050041-d9eb7a3d35ec/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180124185431-e89373fe6b4a/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v0.0.0-20150304233714-bbcb9da2d746/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20180605153948-8b03ce837f34/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/googleapis/gax-go v2.0.2+incompatible h1:silFMLAnr330+NRuag/VjIGF7TLp/LBrV2CJKFLWEww= github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gnostic v0.0.0-20180520015035-48a0ecefe2e4/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= +github.com/gophercloud/gophercloud v0.0.0-20181206160319-9d88c34913a9 h1:7TRGugCPfA2Mll6QT7cbhD1GXZwk7+1PUz8tYrOWXgQ= github.com/gophercloud/gophercloud v0.0.0-20181206160319-9d88c34913a9/go.mod h1:3WdhXV3rUYy9p6AUW8d94kr+HS62Y4VL9mBnFxsD8q4= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg= github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v0.0.0-20181025070259-68e3a13e4117 h1:v9uUYPE4RHQHA0C9XfpAX9uzWQvgIDYjPh6m/mQgrzs= github.com/grpc-ecosystem/go-grpc-prometheus v0.0.0-20181025070259-68e3a13e4117/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/grpc-ecosystem/grpc-gateway v1.6.2/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= @@ -81,16 +110,16 @@ github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go github.com/hashicorp/consul v0.0.0-20180615161029-bed22a81e9fd/go.mod h1:mFrjN1mfidgJfYP1xrJCF+AfRhr6Eaqhb2+sfyn/OOI= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.0.0-20160407174126-ad28ea4487f0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.0.0-20150518234257-fa3f63826f7c/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90/go.mod h1:o4zcYY1e0GEZI6eSEr+43QDYmuGglw1qSO6qdHUHCgg= github.com/hashicorp/go-sockaddr v0.0.0-20180320115054-6d291a969b86/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= -github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/memberlist v0.1.0/go.mod h1:ncdBp14cuox2iFOq3kDiquKU6fqsTBc3W6JvZwjxxsE= github.com/hashicorp/serf v0.0.0-20161007004122-1d4fa605f6ff/go.mod h1:h/Ru6tmZazX7WO/GDmwdpS975F019L4t5ng5IgwbNrE= @@ -101,21 +130,29 @@ github.com/jackc/fake v0.0.0-20150926172116-812a484cc733/go.mod h1:WrMFNQdiFJ80s github.com/jackc/pgx v3.2.0+incompatible/go.mod h1:0ZGrqGqkRlliWnWB4zKnWtjbSWbGkVEFm4TeybAXq+I= github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v0.0.0-20150905172533-109e267447e9/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/julienschmidt/httprouter v1.1.0 h1:7wLdtIiIpzOkC9u6sXOozpBauPdskj3ru4EI5MABq68= github.com/julienschmidt/httprouter v1.1.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/knz/strtime v0.0.0-20181018220328-af2256ee352c/go.mod h1:4ZxfWkxwtc7dBeifERVVWRy9F9rTU9p0yCDgeCtlius= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/leanovate/gopter v0.2.4 h1:U4YLBggDFhJdqQsG4Na2zX7joVTky9vHaj/AGEwSuXU= github.com/leanovate/gopter v0.2.4/go.mod h1:gNcbPWNEWRe4lm+bycKqxUYoH5uoVje5SkOJ3uoLer8= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lightstep/lightstep-tracer-go v0.15.6/go.mod h1:6AMpwZpsyCFwSovxzM78e+AsYxE8sGwiM6C3TytaWeI= +github.com/lovoo/gcloud-opentracing v0.3.0 h1:nAeKG70rIsog0TelcEtt6KU0Y1s5qXtsDLnHp0urPLU= github.com/lovoo/gcloud-opentracing v0.3.0/go.mod h1:ZFqk2y38kMDDikZPAK7ynTTGuyt17nSPdS3K5e+ZTBY= +github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.1.4/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.8 h1:1QYRAKU3lN5cRfLCkPU08hwvLJFhvjP6MqNMmQz6ZVI= @@ -123,49 +160,67 @@ github.com/miekg/dns v1.1.8/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nr github.com/minio/minio-go v0.0.0-20200511070425-f33eae714a28 h1:SOCqV8mmu2Aqo2MktoZkHq17+jklWGlXsy0uf5q0ckM= github.com/minio/minio-go v0.0.0-20200511070425-f33eae714a28/go.mod h1:/haSOWG8hQNx2+JOfLJ9GKp61EAmgPwRVw/Sac0NzaM= github.com/mitchellh/go-homedir v0.0.0-20180523094522-3864e76763d9/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/mozillazg/go-cos v0.11.0 h1:PUaIGDL6Jxgrzqg0XvZ6y32jS/5z26+UxnX6ENMm7yE= github.com/mozillazg/go-cos v0.11.0/go.mod h1:Zp6DvvXn0RUOXGJ2chmWt2bLEqRAnJnS3DnAZsJsoaE= +github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ= github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223 h1:F9x/1yl3T2AeKLr2AMdilSD8+f9bvMnNN8VS5iDtovc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/oklog/oklog v0.0.0-20170918173356-f857583a70c3/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= +github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20180912035003-be2c049b30cc/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/opentracing-contrib/go-stdlib v0.0.0-20170113013457-1de4cc2120e7 h1:8KbikWulLUcMM96hBxjgoo6gTmCkG6HYSDohv/WygYU= github.com/opentracing-contrib/go-stdlib v0.0.0-20170113013457-1de4cc2120e7/go.mod h1:PLldrQSroqzH70Xl+1DQcGnefIbqsKR7UDaiux3zV+w= +github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7lZWlQw5UXuoo= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.1/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/peterbourgon/diskv v0.0.0-20180312054125-0646ccaebea1/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea/go.mod h1:1VcHEd3ro4QMoHfiNl/j7Jkln9+KQuorp0PItHMJYNg= github.com/petermattis/goid v0.0.0-20170504144140-0ded85884ba5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.2 h1:awm861/B8OKDd2I/6o1dy3ra4BamzKhYOiGItCeZ740= github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181119215939-b36ad289a3ea/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.0.0-20181218105931-67670fe90761 h1:z6tvbDJ5OLJ48FFmnksv04a78maSTRBUIhkdHYV5Y98= github.com/prometheus/common v0.0.0-20181218105931-67670fe90761/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/prometheus v0.0.0-20190328180107-4d60eb36dcbe h1:Wpwxfdtx0+/3dgqBvUAB2CTRtHRimQrH4RTEJ5yxCUo= github.com/prometheus/prometheus v0.0.0-20190328180107-4d60eb36dcbe/go.mod h1:mVHnNN4pf1p9fM7dRvZQAKj0Ex93s+mIhtsml8SJy5E= +github.com/prometheus/tsdb v0.6.1 h1:wUp5iY/rmwv6VNzZg4yaUVpkSs4nX5O5+aoviWTNeUo= github.com/prometheus/tsdb v0.6.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rlmcpherson/s3gof3r v0.5.0/go.mod h1:s7vv7SMDPInkitQMuZzH615G7yWHdrU2r/Go7Bo71Rs= @@ -178,18 +233,32 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9Nz github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= github.com/shurcooL/vfsgen v0.0.0-20180711163814-62bca832be04/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 h1:Jpy1PXuP99tXNrhbq2BaPz9B+jNAvH1JPQQpG/9GCXY= github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= +github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w= github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/uber-go/atomic v1.4.0 h1:yOuPqEq4ovnhEjpHmfFwsqBXDYbQeT6Nb0bwD6XnD5o= +github.com/uber-go/atomic v1.4.0/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= +github.com/uber/jaeger-client-go v2.16.0+incompatible h1:Q2Pp6v3QYiocMxomCaJuwQGFt7E53bPYqEgug/AoBtY= +github.com/uber/jaeger-client-go v2.16.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.0.0+incompatible h1:iMSCV0rmXEogjNWPh2D0xk9YVKvrtGoHJNe9ebLu/pw= +github.com/uber/jaeger-lib v2.0.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go.opencensus.io v0.18.1-0.20181204023538-aab39bd6a98b/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= +go.opencensus.io v0.19.0 h1:+jrnNy8MR4GZXvwF9PEuSyHxA4NaTf6601oNRwCSXq0= go.opencensus.io v0.19.0/go.mod h1:AYeH0+ZxYyghG8diqaaIq/9P3VgCCt5GF2ldCY4dkFg= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190128193316-c7b33c32a30b h1:Ib/yptP38nXZFMwqWSip+OKuMP9OkyDe3p+DssP8n9w= golang.org/x/crypto v0.0.0-20190128193316-c7b33c32a30b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -200,19 +269,24 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181217023233-e147a9138326/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jYthdXAmZ6PP+meazmaU= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 h1:uESlIz09WIHT2I+pasSXcpLYqYK8wHcdCetU3VuMBJE= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/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/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/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-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181218192612-074acd46bca6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc h1:4gbWbmmPFp4ySWICouJl6emP0MyS31yy9SrTlAGFT+g= golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20170424234030-8be79e1e0910/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -220,30 +294,39 @@ golang.org/x/tools v0.0.0-20181023010539-40a48ad93fbe/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20181219222714-6e267b5cc78e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= +google.golang.org/api v0.1.0 h1:K6z2u68e86TPdSdefXdzvXgR1zEMa+459vBSfWYAZkI= google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20181202183823-bd91e49a0898/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= +google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb h1:dQshZyyJ5W/Xk8myF4GKBak1pZW6EywJuQ8+44EQhGA= google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.15.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= +google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/fsnotify/fsnotify.v1 v1.3.0/go.mod h1:Fyux9zXlo4rWoMSIzpn9fDAYjalPqJ/K1qJ27s+7ltE= +gopkg.in/fsnotify/fsnotify.v1 v1.4.7 h1:XNNYLJHt73EyYiCZi6+xjupS9CpvmiDgjPTAjrBlQbo= gopkg.in/fsnotify/fsnotify.v1 v1.4.7/go.mod h1:Fyux9zXlo4rWoMSIzpn9fDAYjalPqJ/K1qJ27s+7ltE= gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/ini.v1 v1.41.0 h1:Ka3ViY6gNYSKiVy71zXBEqKplnV35ImDLVG+8uoIklE= gopkg.in/ini.v1 v1.41.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/vmihailenco/msgpack.v2 v2.9.1/go.mod h1:/3Dn1Npt9+MYyLpYYXjInO/5jvMLamn+AEGwNEOatn8= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/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-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 72d55592d1912c369481cc5563cb52d2da651314 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Fri, 31 May 2019 16:54:30 +0300 Subject: [PATCH 31/35] Refactoring --- cmd/thanos/sidecar.go | 9 +- go.mod | 15 +-- go.sum | 45 ++++----- pkg/store/prometheus.go | 4 +- pkg/tracing/jaeger/config_yaml.go | 130 +++++++++---------------- pkg/tracing/jaeger/jaeger.go | 10 +- pkg/tracing/stackdriver/stackdriver.go | 2 + 7 files changed, 88 insertions(+), 127 deletions(-) diff --git a/cmd/thanos/sidecar.go b/cmd/thanos/sidecar.go index e3fba975b1..36ab0bb3e2 100644 --- a/cmd/thanos/sidecar.go +++ b/cmd/thanos/sidecar.go @@ -4,7 +4,6 @@ import ( "context" "math" "net" - "net/http" "net/url" "sync" "time" @@ -21,13 +20,13 @@ import ( "github.com/improbable-eng/thanos/pkg/store" "github.com/improbable-eng/thanos/pkg/store/storepb" "github.com/oklog/run" - opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/tsdb/labels" "google.golang.org/grpc" - kingpin "gopkg.in/alecthomas/kingpin.v2" + "gopkg.in/alecthomas/kingpin.v2" ) func registerSidecar(m map[string]setupFunc, app *kingpin.Application, name string) { @@ -204,10 +203,10 @@ func runSidecar( } logger := log.With(logger, "component", component.Sidecar.String()) - var client http.Client + //var client http.Client promStore, err := store.NewPrometheusStore( - logger, &client, promURL, component.Sidecar, m.Labels, m.Timestamps) + logger, nil, promURL, component.Sidecar, m.Labels, m.Timestamps) if err != nil { return errors.Wrap(err, "create Prometheus store") } diff --git a/go.mod b/go.mod index a03df247b9..99312a4810 100644 --- a/go.mod +++ b/go.mod @@ -30,22 +30,25 @@ require ( github.com/olekukonko/tablewriter v0.0.1 github.com/opentracing-contrib/go-stdlib v0.0.0-20170113013457-1de4cc2120e7 github.com/opentracing/basictracer-go v1.0.0 - github.com/opentracing/opentracing-go v1.0.2 + github.com/opentracing/opentracing-go v1.1.0 github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v0.9.2 github.com/prometheus/common v0.0.0-20181218105931-67670fe90761 github.com/prometheus/prometheus v0.0.0-20190328180107-4d60eb36dcbe github.com/prometheus/tsdb v0.6.1 github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect - go.opencensus.io v0.19.0 // indirect + github.com/uber-go/atomic v1.4.0 // indirect + github.com/uber/jaeger-client-go v2.16.0+incompatible + github.com/uber/jaeger-lib v2.0.0+incompatible + go.uber.org/atomic v1.4.0 // indirect golang.org/x/net v0.0.0-20190522155817-f3200d17e092 - golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 - golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 + golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 + golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 google.golang.org/api v0.5.0 - google.golang.org/appengine v1.4.0 // indirect - google.golang.org/grpc v1.17.0 + google.golang.org/grpc v1.19.0 gopkg.in/alecthomas/kingpin.v2 v2.2.6 + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index 41f8a7b8cb..2eadb5348b 100644 --- a/go.sum +++ b/go.sum @@ -3,7 +3,6 @@ cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= contrib.go.opencensus.io/exporter/ocagent v0.4.1/go.mod h1:b6YwD5Q3Yvj4yk0CDK5vGXexygNzI09aXUdDEakQBgA= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= -git.apache.org/thrift.git v0.0.0-20181218151757-9b75e4fe745a/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/Azure/azure-pipeline-go v0.1.8 h1:KmVRa8oFMaargVesEuuEoiLCQ4zCCwQ8QX/xg++KS20= github.com/Azure/azure-pipeline-go v0.1.8/go.mod h1:XA1kFWRVhSK+KNFiOhfv83Fv8L9achrP7OxIzeTn1Yg= github.com/Azure/azure-sdk-for-go v23.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= @@ -38,6 +37,7 @@ github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMe github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292/go.mod h1:qRiX68mZX1lGBkTWyp3CLcenw9I94W2dLeRvMzcn9N4= github.com/cockroachdb/cockroach v0.0.0-20170608034007-84bc9597164f/go.mod h1:xeT/CQ0qZHangbYbWShlCGAx31aV4AjGswDUjhKS6HQ= github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk= +github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -77,7 +77,6 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/groupcache v0.0.0-20180924190550-6f2cf27854a4/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/snappy v0.0.0-20160529050041-d9eb7a3d35ec/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -91,6 +90,7 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO github.com/google/gofuzz v0.0.0-20150304233714-bbcb9da2d746/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20180605153948-8b03ce837f34 h1:mGdRet4qWdrDnNidFrlgpa8iNWM/RAwRDEMsLRICCac= github.com/google/pprof v0.0.0-20180605153948-8b03ce837f34/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/googleapis/gax-go v2.0.2+incompatible h1:silFMLAnr330+NRuag/VjIGF7TLp/LBrV2CJKFLWEww= github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= @@ -106,7 +106,6 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmg github.com/grpc-ecosystem/go-grpc-prometheus v0.0.0-20181025070259-68e3a13e4117 h1:v9uUYPE4RHQHA0C9XfpAX9uzWQvgIDYjPh6m/mQgrzs= github.com/grpc-ecosystem/go-grpc-prometheus v0.0.0-20181025070259-68e3a13e4117/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= -github.com/grpc-ecosystem/grpc-gateway v1.6.2/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/grpc-ecosystem/grpc-gateway v1.6.3/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw= github.com/hashicorp/consul v0.0.0-20180615161029-bed22a81e9fd/go.mod h1:mFrjN1mfidgJfYP1xrJCF+AfRhr6Eaqhb2+sfyn/OOI= @@ -172,8 +171,6 @@ github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/mozillazg/go-cos v0.11.0 h1:PUaIGDL6Jxgrzqg0XvZ6y32jS/5z26+UxnX6ENMm7yE= -github.com/mozillazg/go-cos v0.11.0/go.mod h1:Zp6DvvXn0RUOXGJ2chmWt2bLEqRAnJnS3DnAZsJsoaE= github.com/mozillazg/go-cos v0.12.0 h1:b9hUd5HjrDe10BUfkyiLYI1+z4M2kAgKasktszx9pO4= github.com/mozillazg/go-cos v0.12.0/go.mod h1:Zp6DvvXn0RUOXGJ2chmWt2bLEqRAnJnS3DnAZsJsoaE= github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ= @@ -195,10 +192,9 @@ github.com/opentracing-contrib/go-stdlib v0.0.0-20170113013457-1de4cc2120e7/go.m github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7lZWlQw5UXuoo= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.1/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= -github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= -github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/peterbourgon/diskv v0.0.0-20180312054125-0646ccaebea1/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= @@ -255,11 +251,17 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= +github.com/uber-go/atomic v1.4.0 h1:yOuPqEq4ovnhEjpHmfFwsqBXDYbQeT6Nb0bwD6XnD5o= +github.com/uber-go/atomic v1.4.0/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= +github.com/uber/jaeger-client-go v2.16.0+incompatible h1:Q2Pp6v3QYiocMxomCaJuwQGFt7E53bPYqEgug/AoBtY= +github.com/uber/jaeger-client-go v2.16.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.0.0+incompatible h1:iMSCV0rmXEogjNWPh2D0xk9YVKvrtGoHJNe9ebLu/pw= +github.com/uber/jaeger-lib v2.0.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= go.opencensus.io v0.18.1-0.20181204023538-aab39bd6a98b/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= -go.opencensus.io v0.19.0 h1:+jrnNy8MR4GZXvwF9PEuSyHxA4NaTf6601oNRwCSXq0= -go.opencensus.io v0.19.0/go.mod h1:AYeH0+ZxYyghG8diqaaIq/9P3VgCCt5GF2ldCY4dkFg= +go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= golang.org/x/crypto v0.0.0-20180621125126-a49355c7e3f8/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -268,15 +270,12 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 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-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181217023233-e147a9138326/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -284,18 +283,17 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 h1:uESlIz09WIHT2I+pasSXcpLYqYK8wHcdCetU3VuMBJE= -golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/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-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181218192612-074acd46bca6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190116161447-11f53e031339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -307,32 +305,26 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 golang.org/x/time v0.0.0-20170424234030-8be79e1e0910/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181023010539-40a48ad93fbe/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20181219222714-6e267b5cc78e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384 h1:TFlARGu6Czu1z7q93HTxcP1P+/ZFC/IKythI5RzrnRg= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= -google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= -google.golang.org/api v0.1.0 h1:K6z2u68e86TPdSdefXdzvXgR1zEMa+459vBSfWYAZkI= -google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= google.golang.org/api v0.5.0 h1:lj9SyhMzyoa38fgFF0oO2T6pjs5IzkLPKfVtxpyCRMM= google.golang.org/api v0.5.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20181202183823-bd91e49a0898/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= -google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb h1:dQshZyyJ5W/Xk8myF4GKBak1pZW6EywJuQ8+44EQhGA= -google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19 h1:Lj2SnHtxkRGJDqnGaSjo+CCdIieEnwVazbOXILwQemk= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.15.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= -google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio= 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.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -354,7 +346,6 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/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-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= k8s.io/api v0.0.0-20181213150558-05914d821849/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA= k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= diff --git a/pkg/store/prometheus.go b/pkg/store/prometheus.go index 52d0ff571b..f50f732b16 100644 --- a/pkg/store/prometheus.go +++ b/pkg/store/prometheus.go @@ -235,10 +235,8 @@ func (p *PrometheusStore) promSeries(ctx context.Context, q prompb.Query) (*prom preq.Header.Add("Content-Encoding", "snappy") preq.Header.Set("Content-Type", "application/x-protobuf") preq.Header.Set("X-Prometheus-Remote-Read-Version", "0.1.0") - - preq = preq.WithContext(ctx) - spanReqDo, ctx := tracing.StartSpan(ctx, "query_prometheus_request") + preq = preq.WithContext(ctx) presp, err := p.client.Do(preq) if err != nil { return nil, errors.Wrap(err, "send request") diff --git a/pkg/tracing/jaeger/config_yaml.go b/pkg/tracing/jaeger/config_yaml.go index 2e11dd03a7..dec349c1c4 100644 --- a/pkg/tracing/jaeger/config_yaml.go +++ b/pkg/tracing/jaeger/config_yaml.go @@ -4,7 +4,6 @@ import ( "fmt" "net/url" "os" - "strconv" "strings" "time" @@ -15,28 +14,29 @@ import ( "gopkg.in/yaml.v2" ) +// Config - YAML configuration type Config struct { ServiceName string `yaml:"service_name"` - Disabled string `yaml:"disabled"` - RPCMetrics string `yaml:"rpc_metrics"` + Disabled bool `yaml:"disabled"` + RPCMetrics bool `yaml:"rpc_metrics"` Tags string `yaml:"tags"` SamplerType string `yaml:"sampler_type"` - SamplerParam string `yaml:"sampler_param"` + SamplerParam float64 `yaml:"sampler_param"` SamplerManagerHostPort string `yaml:"sampler_manager_host_port"` - SamplerMaxOperations string `yaml:"sampler_max_operations"` - SamplerRefreshInterval string `yaml:"sampler_refresh_interval"` - ReporterMaxQueueSize string `yaml:"reporter_max_queue_size"` - ReporterFlushInterval string `yaml:"reporter_flush_interval"` - ReporterLogSpans string `yaml:"reporter_log_spans"` + SamplerMaxOperations int `yaml:"sampler_max_operations"` + SamplerRefreshInterval time.Duration `yaml:"sampler_refresh_interval"` + ReporterMaxQueueSize int `yaml:"reporter_max_queue_size"` + ReporterFlushInterval time.Duration `yaml:"reporter_flush_interval"` + ReporterLogSpans bool `yaml:"reporter_log_spans"` Endpoint string `yaml:"endpoint"` User string `yaml:"user"` Password string `yaml:"password"` AgentHost string `yaml:"agent_host"` - AgentPort string `yaml:"agent_port"` + AgentPort int `yaml:"agent_port"` } // FromYaml uses config YAML to set the tracer's Configuration. -func FromYaml(cfg []byte) (*config.Configuration, error) { +func ParseConfigFromYaml(cfg []byte) (*config.Configuration, error) { conf := &Config{} if err := yaml.Unmarshal(cfg, &conf); err != nil { @@ -45,40 +45,32 @@ func FromYaml(cfg []byte) (*config.Configuration, error) { c := &config.Configuration{} - if e := conf.ServiceName; e != "" { - c.ServiceName = e + if conf.ServiceName != "" { + c.ServiceName = conf.ServiceName } - if e := conf.RPCMetrics; e != "" { - if value, err := strconv.ParseBool(e); err == nil { - c.RPCMetrics = value - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", conf.RPCMetrics, e) - } + if conf.RPCMetrics { + c.RPCMetrics = conf.RPCMetrics } - if e := os.Getenv(conf.Disabled); e != "" { - if value, err := strconv.ParseBool(e); err == nil { - c.Disabled = value - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", conf.Disabled, e) - } + if conf.Disabled { + c.Disabled = conf.Disabled } - if e := conf.Tags; e != "" { - c.Tags = parseTags(e) + if conf.Tags != "" { + c.Tags = parseTags(conf.Tags) } if s, err := samplerConfigFromConfig(*conf); err == nil { c.Sampler = s } else { - return nil, errors.Wrap(err, "cannot obtain sampler config from env") + return nil, errors.Wrap(err, "cannot obtain sampler config from YAML") } - if r, err := reporterConfigFromEnv(*conf); err == nil { + if r, err := reporterConfigFromConfig(*conf); err == nil { c.Reporter = r } else { - return nil, errors.Wrap(err, "cannot obtain reporter config from env") + return nil, errors.Wrap(err, "cannot obtain reporter config from YAML") } return c, nil @@ -88,95 +80,67 @@ func FromYaml(cfg []byte) (*config.Configuration, error) { func samplerConfigFromConfig(cfg Config) (*config.SamplerConfig, error) { sc := &config.SamplerConfig{} - if e := cfg.SamplerType; e != "" { - sc.Type = e + if cfg.SamplerType != "" { + sc.Type = cfg.SamplerType } - if e := cfg.SamplerParam; e != "" { - if value, err := strconv.ParseFloat(e, 64); err == nil { - sc.Param = value - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.SamplerParam, e) - } + if cfg.SamplerParam != 0 { + sc.Param = cfg.SamplerParam } - if e := cfg.SamplerManagerHostPort; e != "" { - sc.SamplingServerURL = e + if cfg.SamplerManagerHostPort != "" { + sc.SamplingServerURL = cfg.SamplerManagerHostPort } - if e := cfg.SamplerMaxOperations; e != "" { - if value, err := strconv.ParseInt(e, 10, 0); err == nil { - sc.MaxOperations = int(value) - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.SamplerMaxOperations, e) - } + if cfg.SamplerMaxOperations != 0 { + sc.MaxOperations = cfg.SamplerMaxOperations } - if e := cfg.SamplerRefreshInterval; e != "" { - if value, err := time.ParseDuration(e); err == nil { - sc.SamplingRefreshInterval = value - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.SamplerRefreshInterval, e) - } + if cfg.SamplerRefreshInterval != 0 { + sc.SamplingRefreshInterval = cfg.SamplerRefreshInterval } return sc, nil } // reporterConfigFromConfig creates a new ReporterConfig based on the YAML Config. -func reporterConfigFromEnv(cfg Config) (*config.ReporterConfig, error) { +func reporterConfigFromConfig(cfg Config) (*config.ReporterConfig, error) { rc := &config.ReporterConfig{} - if e := cfg.ReporterMaxQueueSize; e != "" { - if value, err := strconv.ParseInt(e, 10, 0); err == nil { - rc.QueueSize = int(value) - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.ReporterMaxQueueSize, e) - } + if cfg.ReporterMaxQueueSize != 0 { + rc.QueueSize = cfg.ReporterMaxQueueSize } - if e := cfg.ReporterFlushInterval; e != "" { - if value, err := time.ParseDuration(e); err == nil { - rc.BufferFlushInterval = value - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.ReporterFlushInterval, e) - } + if cfg.ReporterFlushInterval != 0 { + rc.BufferFlushInterval = cfg.ReporterFlushInterval } - if e := cfg.ReporterLogSpans; e != "" { - if value, err := strconv.ParseBool(e); err == nil { - rc.LogSpans = value - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.ReporterLogSpans, e) - } + if cfg.ReporterLogSpans { + rc.LogSpans = cfg.ReporterLogSpans } - if e := cfg.Endpoint; e != "" { - u, err := url.ParseRequestURI(e) + if cfg.Endpoint != "" { + u, err := url.ParseRequestURI(cfg.Endpoint) if err != nil { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.Endpoint, e) + return nil, errors.Wrapf(err, "cannot parse endpoint=%s", cfg.Endpoint) } rc.CollectorEndpoint = u.String() user := cfg.User pswd := cfg.Password if user != "" && pswd == "" || user == "" && pswd != "" { - return nil, errors.Errorf("you must set %s and %s env vars together", cfg.User, cfg.Password) + return nil, errors.Errorf("you must set %s and %s parameters together", cfg.User, cfg.Password) } rc.User = user rc.Password = pswd } else { host := jaeger.DefaultUDPSpanServerHost - if e := cfg.AgentHost; e != "" { - host = e + if cfg.AgentHost != "" { + host = cfg.AgentHost } port := jaeger.DefaultUDPSpanServerPort - if e := cfg.AgentPort; e != "" { - if value, err := strconv.ParseInt(e, 10, 0); err == nil { - port = int(value) - } else { - return nil, errors.Wrapf(err, "cannot parse env var %s=%s", cfg.AgentPort, e) - } + if cfg.AgentPort != 0 { + port = cfg.AgentPort } rc.LocalAgentHostPort = fmt.Sprintf("%s:%d", host, port) } diff --git a/pkg/tracing/jaeger/jaeger.go b/pkg/tracing/jaeger/jaeger.go index 52ab2c7cb4..1d44a35d19 100644 --- a/pkg/tracing/jaeger/jaeger.go +++ b/pkg/tracing/jaeger/jaeger.go @@ -4,21 +4,24 @@ import ( "context" "fmt" "github.com/go-kit/kit/log/level" + "github.com/improbable-eng/thanos/pkg/tracing" "io" "github.com/go-kit/kit/log" - "github.com/improbable-eng/thanos/pkg/tracing" "github.com/opentracing/opentracing-go" + "github.com/prometheus/client_golang/prometheus" "github.com/uber/jaeger-client-go" "github.com/uber/jaeger-client-go/config" jaeger_prometheus "github.com/uber/jaeger-lib/metrics/prometheus" - "github.com/prometheus/client_golang/prometheus" ) + +// Tracer extends opentracing.Tracer type Tracer struct { opentracing.Tracer } +// GetTraceIdFromSpanContext return TraceID from span.Context func (t *Tracer) GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, bool) { if c, ok := ctx.(jaeger.SpanContext); ok { return fmt.Sprintf("%016x", c.TraceID().Low), true @@ -26,6 +29,7 @@ func (t *Tracer) GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, return "", false } +// NewTracer create tracer from YAML func NewTracer(ctx context.Context, logger log.Logger, metrics *prometheus.Registry, conf []byte) (opentracing.Tracer, io.Closer, error) { var ( cfg *config.Configuration @@ -35,7 +39,7 @@ func NewTracer(ctx context.Context, logger log.Logger, metrics *prometheus.Regis ) if conf != nil { level.Info(logger).Log("msg", "loading Jaeger tracing configuration from YAML") - cfg, err = FromYaml(conf) + cfg, err = ParseConfigFromYaml(conf) } else { level.Info(logger).Log("msg", "loading Jaeger tracing configuration from ENV") cfg, err = config.FromEnv() diff --git a/pkg/tracing/stackdriver/stackdriver.go b/pkg/tracing/stackdriver/stackdriver.go index a16aff6f1d..1404108587 100644 --- a/pkg/tracing/stackdriver/stackdriver.go +++ b/pkg/tracing/stackdriver/stackdriver.go @@ -9,12 +9,14 @@ import ( "gopkg.in/yaml.v2" ) +// Config - YAML configuration type Config struct { ServiceName string `yaml:"service_name"` ProjectId string `yaml:"project_id"` SampleFactor uint64 `yaml:"sample_factor"` } +// NewTracer create tracer from YAML func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { config := Config{} if err := yaml.Unmarshal(conf, &config); err != nil { From 94aabb33d0844704a6d727eed403e8b15d7314ef Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Fri, 31 May 2019 17:38:08 +0300 Subject: [PATCH 32/35] Resolve go mod conflicts --- go.mod | 6 +++++- go.sum | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 3d353a2c9e..a30cf2f0e4 100644 --- a/go.mod +++ b/go.mod @@ -29,12 +29,16 @@ require ( github.com/olekukonko/tablewriter v0.0.1 github.com/opentracing-contrib/go-stdlib v0.0.0-20170113013457-1de4cc2120e7 github.com/opentracing/basictracer-go v1.0.0 - github.com/opentracing/opentracing-go v1.0.2 + github.com/opentracing/opentracing-go v1.1.0 github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829 github.com/prometheus/common v0.4.0 github.com/prometheus/prometheus v2.9.2+incompatible github.com/prometheus/tsdb v0.8.0 + github.com/uber-go/atomic v1.4.0 // indirect + github.com/uber/jaeger-client-go v2.16.0+incompatible + github.com/uber/jaeger-lib v2.0.0+incompatible + go.uber.org/atomic v1.4.0 // indirect golang.org/x/net v0.0.0-20190522155817-f3200d17e092 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 diff --git a/go.sum b/go.sum index 2b3bcbcbb5..e1982bc910 100644 --- a/go.sum +++ b/go.sum @@ -43,6 +43,7 @@ github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMe github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292/go.mod h1:qRiX68mZX1lGBkTWyp3CLcenw9I94W2dLeRvMzcn9N4= github.com/cockroachdb/cockroach v0.0.0-20170608034007-84bc9597164f/go.mod h1:xeT/CQ0qZHangbYbWShlCGAx31aV4AjGswDUjhKS6HQ= github.com/cockroachdb/cockroach-go v0.0.0-20181001143604-e0a95dfd547c/go.mod h1:XGLbWH/ujMcbPbhZq52Nv6UrCghb1yGn//133kEsvDk= +github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd h1:qMd81Ts1T2OTKmB4acZcyKaMtRnY5Y44NuXGX2GFJ1w= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coreos/etcd v3.3.12+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -216,6 +217,8 @@ github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7l github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -277,9 +280,17 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/uber-go/atomic v1.4.0 h1:yOuPqEq4ovnhEjpHmfFwsqBXDYbQeT6Nb0bwD6XnD5o= +github.com/uber-go/atomic v1.4.0/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= +github.com/uber/jaeger-client-go v2.16.0+incompatible h1:Q2Pp6v3QYiocMxomCaJuwQGFt7E53bPYqEgug/AoBtY= +github.com/uber/jaeger-client-go v2.16.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/uber/jaeger-lib v2.0.0+incompatible h1:iMSCV0rmXEogjNWPh2D0xk9YVKvrtGoHJNe9ebLu/pw= +github.com/uber/jaeger-lib v2.0.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2 h1:NAfh7zF0/3/HqtMvJNZ/RFrSlCE6ZTlHmKfhL/Dm1Jk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= From 4e98096eab0b893eb3289b1aba18be8a5749ba35 Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Fri, 31 May 2019 18:43:48 +0300 Subject: [PATCH 33/35] Remove comments. --- cmd/thanos/sidecar.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/thanos/sidecar.go b/cmd/thanos/sidecar.go index 36ab0bb3e2..ac33a89731 100644 --- a/cmd/thanos/sidecar.go +++ b/cmd/thanos/sidecar.go @@ -203,8 +203,6 @@ func runSidecar( } logger := log.With(logger, "component", component.Sidecar.String()) - //var client http.Client - promStore, err := store.NewPrometheusStore( logger, nil, promURL, component.Sidecar, m.Labels, m.Timestamps) if err != nil { From b70f05a09de1eb78016dea091973a557d60a706b Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 4 Jun 2019 18:57:43 +0300 Subject: [PATCH 34/35] PR refactoring for review. --- pkg/tracing/http.go | 4 ++-- pkg/tracing/jaeger/config_yaml.go | 4 ++-- pkg/tracing/jaeger/jaeger.go | 15 +++++++-------- pkg/tracing/stackdriver/stackdriver.go | 4 ++-- pkg/tracing/stackdriver/tracer.go | 3 ++- pkg/tracing/tracing.go | 5 +++-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pkg/tracing/http.go b/pkg/tracing/http.go index 65970be8ef..c2e92adfab 100644 --- a/pkg/tracing/http.go +++ b/pkg/tracing/http.go @@ -35,8 +35,8 @@ func HTTPMiddleware(tracer opentracing.Tracer, name string, logger log.Logger, n span.SetBaggageItem(ForceTracingBaggageKey, r.Header.Get(ForceTracingBaggageKey)) if t, ok := tracer.(Tracer); ok { - if traceId, ok :=t.GetTraceIdFromSpanContext(span.Context()); ok { - w.Header().Set(traceIdResponseHeader, traceId) + if traceID, ok :=t.GetTraceIDFromSpanContext(span.Context()); ok { + w.Header().Set(traceIDResponseHeader, traceID) } } diff --git a/pkg/tracing/jaeger/config_yaml.go b/pkg/tracing/jaeger/config_yaml.go index dec349c1c4..9832a40ca5 100644 --- a/pkg/tracing/jaeger/config_yaml.go +++ b/pkg/tracing/jaeger/config_yaml.go @@ -14,7 +14,7 @@ import ( "gopkg.in/yaml.v2" ) -// Config - YAML configuration +// Config - YAML configuration. For details see to https://github.com/jaegertracing/jaeger-client-go#environment-variables type Config struct { ServiceName string `yaml:"service_name"` Disabled bool `yaml:"disabled"` @@ -35,7 +35,7 @@ type Config struct { AgentPort int `yaml:"agent_port"` } -// FromYaml uses config YAML to set the tracer's Configuration. +// ParseConfigFromYaml uses config YAML to set the tracer's Configuration. func ParseConfigFromYaml(cfg []byte) (*config.Configuration, error) { conf := &Config{} diff --git a/pkg/tracing/jaeger/jaeger.go b/pkg/tracing/jaeger/jaeger.go index 1d44a35d19..7cdb08e6f5 100644 --- a/pkg/tracing/jaeger/jaeger.go +++ b/pkg/tracing/jaeger/jaeger.go @@ -15,27 +15,26 @@ import ( jaeger_prometheus "github.com/uber/jaeger-lib/metrics/prometheus" ) - -// Tracer extends opentracing.Tracer +// Tracer extends opentracing.Tracer. type Tracer struct { opentracing.Tracer } -// GetTraceIdFromSpanContext return TraceID from span.Context -func (t *Tracer) GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, bool) { +// GetTraceIDFromSpanContext return TraceID from span.Context. +func (t *Tracer) GetTraceIDFromSpanContext(ctx opentracing.SpanContext) (string, bool) { if c, ok := ctx.(jaeger.SpanContext); ok { return fmt.Sprintf("%016x", c.TraceID().Low), true } return "", false } -// NewTracer create tracer from YAML +// NewTracer create tracer from YAML. func NewTracer(ctx context.Context, logger log.Logger, metrics *prometheus.Registry, conf []byte) (opentracing.Tracer, io.Closer, error) { var ( - cfg *config.Configuration - err error + cfg *config.Configuration + err error jaegerTracer opentracing.Tracer - closer io.Closer + closer io.Closer ) if conf != nil { level.Info(logger).Log("msg", "loading Jaeger tracing configuration from YAML") diff --git a/pkg/tracing/stackdriver/stackdriver.go b/pkg/tracing/stackdriver/stackdriver.go index 1404108587..be2d9eb039 100644 --- a/pkg/tracing/stackdriver/stackdriver.go +++ b/pkg/tracing/stackdriver/stackdriver.go @@ -9,14 +9,14 @@ import ( "gopkg.in/yaml.v2" ) -// Config - YAML configuration +// Config - YAML configuration. type Config struct { ServiceName string `yaml:"service_name"` ProjectId string `yaml:"project_id"` SampleFactor uint64 `yaml:"sample_factor"` } -// NewTracer create tracer from YAML +// NewTracer create tracer from YAML. func NewTracer(ctx context.Context, logger log.Logger, conf []byte) (opentracing.Tracer, io.Closer, error) { config := Config{} if err := yaml.Unmarshal(conf, &config); err != nil { diff --git a/pkg/tracing/stackdriver/tracer.go b/pkg/tracing/stackdriver/tracer.go index 1dc33a290e..0b0e133458 100644 --- a/pkg/tracing/stackdriver/tracer.go +++ b/pkg/tracing/stackdriver/tracer.go @@ -21,7 +21,8 @@ type tracer struct { wrapped opentracing.Tracer } -func (t *tracer) GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, bool) { +// GetTraceIDFromSpanContext return TraceID from span.Context. +func (t *tracer) GetTraceIDFromSpanContext(ctx opentracing.SpanContext) (string, bool) { if c, ok := ctx.(basictracer.SpanContext); ok { // "%016x%016x" - ugly hack for gcloud find traces by ID https://console.cloud.google.com/traces/traces?project=&tid=<62119f61b7c2663962119f61b7c26639> return fmt.Sprintf("%016x%016x", c.TraceID, c.TraceID), true diff --git a/pkg/tracing/tracing.go b/pkg/tracing/tracing.go index 730829e12a..8c0ae53a7c 100644 --- a/pkg/tracing/tracing.go +++ b/pkg/tracing/tracing.go @@ -11,14 +11,15 @@ const ForceTracingBaggageKey = "X-Thanos-Force-Tracing" // traceIdResponseHeader - Trace ID response header. -const traceIdResponseHeader = "X-Thanos-Trace-Id" +const traceIDResponseHeader = "X-Thanos-Trace-Id" type contextKey struct{} var tracerKey = contextKey{} +// Tracer interface to provide GetTraceIDFromSpanContext method. type Tracer interface { - GetTraceIdFromSpanContext(ctx opentracing.SpanContext) (string, bool) + GetTraceIDFromSpanContext(ctx opentracing.SpanContext) (string, bool) } // ContextWithTracer returns a new `context.Context` that holds a reference to given opentracing.Tracer. From 847cc917d39c60721483fa3969a8d7b60d3859ef Mon Sep 17 00:00:00 2001 From: Aleksey Sin Date: Tue, 4 Jun 2019 18:58:39 +0300 Subject: [PATCH 35/35] Format files. --- pkg/tracing/jaeger/config_yaml.go | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pkg/tracing/jaeger/config_yaml.go b/pkg/tracing/jaeger/config_yaml.go index 9832a40ca5..3e3a75dd92 100644 --- a/pkg/tracing/jaeger/config_yaml.go +++ b/pkg/tracing/jaeger/config_yaml.go @@ -16,23 +16,23 @@ import ( // Config - YAML configuration. For details see to https://github.com/jaegertracing/jaeger-client-go#environment-variables type Config struct { - ServiceName string `yaml:"service_name"` - Disabled bool `yaml:"disabled"` - RPCMetrics bool `yaml:"rpc_metrics"` - Tags string `yaml:"tags"` - SamplerType string `yaml:"sampler_type"` - SamplerParam float64 `yaml:"sampler_param"` - SamplerManagerHostPort string `yaml:"sampler_manager_host_port"` - SamplerMaxOperations int `yaml:"sampler_max_operations"` + ServiceName string `yaml:"service_name"` + Disabled bool `yaml:"disabled"` + RPCMetrics bool `yaml:"rpc_metrics"` + Tags string `yaml:"tags"` + SamplerType string `yaml:"sampler_type"` + SamplerParam float64 `yaml:"sampler_param"` + SamplerManagerHostPort string `yaml:"sampler_manager_host_port"` + SamplerMaxOperations int `yaml:"sampler_max_operations"` SamplerRefreshInterval time.Duration `yaml:"sampler_refresh_interval"` - ReporterMaxQueueSize int `yaml:"reporter_max_queue_size"` + ReporterMaxQueueSize int `yaml:"reporter_max_queue_size"` ReporterFlushInterval time.Duration `yaml:"reporter_flush_interval"` - ReporterLogSpans bool `yaml:"reporter_log_spans"` - Endpoint string `yaml:"endpoint"` - User string `yaml:"user"` - Password string `yaml:"password"` - AgentHost string `yaml:"agent_host"` - AgentPort int `yaml:"agent_port"` + ReporterLogSpans bool `yaml:"reporter_log_spans"` + Endpoint string `yaml:"endpoint"` + User string `yaml:"user"` + Password string `yaml:"password"` + AgentHost string `yaml:"agent_host"` + AgentPort int `yaml:"agent_port"` } // ParseConfigFromYaml uses config YAML to set the tracer's Configuration. @@ -54,7 +54,7 @@ func ParseConfigFromYaml(cfg []byte) (*config.Configuration, error) { } if conf.Disabled { - c.Disabled = conf.Disabled + c.Disabled = conf.Disabled } if conf.Tags != "" { @@ -93,7 +93,7 @@ func samplerConfigFromConfig(cfg Config) (*config.SamplerConfig, error) { } if cfg.SamplerMaxOperations != 0 { - sc.MaxOperations = cfg.SamplerMaxOperations + sc.MaxOperations = cfg.SamplerMaxOperations } if cfg.SamplerRefreshInterval != 0 { @@ -112,11 +112,11 @@ func reporterConfigFromConfig(cfg Config) (*config.ReporterConfig, error) { } if cfg.ReporterFlushInterval != 0 { - rc.BufferFlushInterval = cfg.ReporterFlushInterval + rc.BufferFlushInterval = cfg.ReporterFlushInterval } if cfg.ReporterLogSpans { - rc.LogSpans = cfg.ReporterLogSpans + rc.LogSpans = cfg.ReporterLogSpans } if cfg.Endpoint != "" {