From 4744b7c9d747ce8588a26eea6b36e4e5b45b66bb Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 13 Jun 2019 15:11:00 +0200 Subject: [PATCH] p2p/protocols: do not vendor swarm related packages (#1462) --- p2p/protocols/protocol.go | 4 +- .../swarm/spancontext/spancontext.go | 49 ----- .../go-ethereum/swarm/tracing/tracing.go | 173 ------------------ vendor/vendor.json | 12 -- 4 files changed, 2 insertions(+), 236 deletions(-) delete mode 100644 vendor/github.com/ethereum/go-ethereum/swarm/spancontext/spancontext.go delete mode 100644 vendor/github.com/ethereum/go-ethereum/swarm/tracing/tracing.go diff --git a/p2p/protocols/protocol.go b/p2p/protocols/protocol.go index a9a00984d1..8cd6cfcfd0 100644 --- a/p2p/protocols/protocol.go +++ b/p2p/protocols/protocol.go @@ -42,8 +42,8 @@ import ( "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rlp" - "github.com/ethereum/go-ethereum/swarm/spancontext" - "github.com/ethereum/go-ethereum/swarm/tracing" + "github.com/ethersphere/swarm/spancontext" + "github.com/ethersphere/swarm/tracing" opentracing "github.com/opentracing/opentracing-go" ) diff --git a/vendor/github.com/ethereum/go-ethereum/swarm/spancontext/spancontext.go b/vendor/github.com/ethereum/go-ethereum/swarm/spancontext/spancontext.go deleted file mode 100644 index 2cb9f82f7c..0000000000 --- a/vendor/github.com/ethereum/go-ethereum/swarm/spancontext/spancontext.go +++ /dev/null @@ -1,49 +0,0 @@ -package spancontext - -import ( - "context" - - opentracing "github.com/opentracing/opentracing-go" -) - -func WithContext(ctx context.Context, sctx opentracing.SpanContext) context.Context { - return context.WithValue(ctx, "span_context", sctx) -} - -func FromContext(ctx context.Context) opentracing.SpanContext { - sctx, ok := ctx.Value("span_context").(opentracing.SpanContext) - if ok { - return sctx - } - - return nil -} - -func StartSpan(ctx context.Context, name string) (context.Context, opentracing.Span) { - tracer := opentracing.GlobalTracer() - - sctx := FromContext(ctx) - - var sp opentracing.Span - if sctx != nil { - sp = tracer.StartSpan( - name, - opentracing.ChildOf(sctx)) - } else { - sp = tracer.StartSpan(name) - } - - nctx := context.WithValue(ctx, "span_context", sp.Context()) - - return nctx, sp -} - -func StartSpanFrom(name string, sctx opentracing.SpanContext) opentracing.Span { - tracer := opentracing.GlobalTracer() - - sp := tracer.StartSpan( - name, - opentracing.ChildOf(sctx)) - - return sp -} diff --git a/vendor/github.com/ethereum/go-ethereum/swarm/tracing/tracing.go b/vendor/github.com/ethereum/go-ethereum/swarm/tracing/tracing.go deleted file mode 100644 index 55875464b9..0000000000 --- a/vendor/github.com/ethereum/go-ethereum/swarm/tracing/tracing.go +++ /dev/null @@ -1,173 +0,0 @@ -package tracing - -import ( - "context" - "io" - "os" - "strings" - "sync" - "time" - - "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/swarm/spancontext" - - opentracing "github.com/opentracing/opentracing-go" - jaeger "github.com/uber/jaeger-client-go" - jaegercfg "github.com/uber/jaeger-client-go/config" - cli "gopkg.in/urfave/cli.v1" -) - -var ( - // Enabled turns tracing on for the current swarm instance - Enabled bool = false - store = spanStore{} -) - -const ( - // TracingEnabledFlag is the CLI flag name to use to enable trace collections. - TracingEnabledFlag = "tracing" - - // StoreLabelId is the context value key of the name of the span to be saved - StoreLabelId = "span_save_id" - - // StoreLabelMeta is the context value key that together with StoreLabelId constitutes the retrieval key for saved spans in the span store - // StartSaveSpan and ShiftSpanByKey - StoreLabelMeta = "span_save_meta" -) - -var ( - Closer io.Closer -) - -var ( - TracingFlag = cli.BoolFlag{ - Name: TracingEnabledFlag, - Usage: "Enable tracing", - } - TracingEndpointFlag = cli.StringFlag{ - Name: "tracing.endpoint", - Usage: "Tracing endpoint", - Value: "0.0.0.0:6831", - } - TracingSvcFlag = cli.StringFlag{ - Name: "tracing.svc", - Usage: "Tracing service name", - Value: "swarm", - } -) - -// Flags holds all command-line flags required for tracing collection. -var Flags = []cli.Flag{ - TracingFlag, - TracingEndpointFlag, - TracingSvcFlag, -} - -// Init enables or disables the open tracing system. -func init() { - for _, arg := range os.Args { - if flag := strings.TrimLeft(arg, "-"); flag == TracingEnabledFlag { - Enabled = true - } - } -} - -func Setup(ctx *cli.Context) { - if Enabled { - log.Info("Enabling opentracing") - var ( - endpoint = ctx.GlobalString(TracingEndpointFlag.Name) - svc = ctx.GlobalString(TracingSvcFlag.Name) - ) - - Closer = initTracer(endpoint, svc) - } -} - -func initTracer(endpoint, svc string) (closer io.Closer) { - // Sample configuration for testing. Use constant sampling to sample every trace - // and enable LogSpan to log every span via configured Logger. - cfg := jaegercfg.Configuration{ - Sampler: &jaegercfg.SamplerConfig{ - Type: jaeger.SamplerTypeConst, - Param: 1, - }, - Reporter: &jaegercfg.ReporterConfig{ - LogSpans: true, - BufferFlushInterval: 1 * time.Second, - LocalAgentHostPort: endpoint, - }, - } - - // Example logger and metrics factory. Use github.com/uber/jaeger-client-go/log - // and github.com/uber/jaeger-lib/metrics respectively to bind to real logging and metrics - // frameworks. - //jLogger := jaegerlog.StdLogger - //jMetricsFactory := metrics.NullFactory - - // Initialize tracer with a logger and a metrics factory - closer, err := cfg.InitGlobalTracer( - svc, - //jaegercfg.Logger(jLogger), - //jaegercfg.Metrics(jMetricsFactory), - //jaegercfg.Observer(rpcmetrics.NewObserver(jMetricsFactory, rpcmetrics.DefaultNameNormalizer)), - ) - if err != nil { - log.Error("Could not initialize Jaeger tracer", "err", err) - } - - return closer -} - -// spanStore holds saved spans -type spanStore struct { - spans sync.Map -} - -// StartSaveSpan stores the span specified in the passed context for later retrieval -// The span object but be context value on the key StoreLabelId. -// It will be stored under the the following string key context.Value(StoreLabelId)|.|context.Value(StoreLabelMeta) -func StartSaveSpan(ctx context.Context) context.Context { - if !Enabled { - return ctx - } - traceId := ctx.Value(StoreLabelId) - - if traceId != nil { - traceStr := traceId.(string) - var sp opentracing.Span - ctx, sp = spancontext.StartSpan( - ctx, - traceStr, - ) - traceMeta := ctx.Value(StoreLabelMeta) - if traceMeta != nil { - traceStr = traceStr + "." + traceMeta.(string) - } - store.spans.Store(traceStr, sp) - } - return ctx -} - -// ShiftSpanByKey retrieves the span stored under the key of the string given as argument -// The span is then deleted from the store -func ShiftSpanByKey(k string) opentracing.Span { - if !Enabled { - return nil - } - span, spanOk := store.spans.Load(k) - if !spanOk { - return nil - } - store.spans.Delete(k) - return span.(opentracing.Span) -} - -// FinishSpans calls `Finish()` on all stored spans -// It should be called on instance shutdown -func FinishSpans() { - store.spans.Range(func(_, v interface{}) bool { - v.(opentracing.Span).Finish() - return true - }) -} diff --git a/vendor/vendor.json b/vendor/vendor.json index 9aab1acc97..06dd683cdd 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -602,18 +602,6 @@ "revision": "7a22da98b9f81d206eb65d1fa4f5e773d888bac3", "revisionTime": "2019-05-31T09:30:28Z" }, - { - "checksumSHA1": "xNdgmBmhiTpNkDy8vqvxuUll6SM=", - "path": "github.com/ethereum/go-ethereum/swarm/spancontext", - "revision": "7a22da98b9f81d206eb65d1fa4f5e773d888bac3", - "revisionTime": "2019-05-31T09:30:28Z" - }, - { - "checksumSHA1": "w3qoUcgf9BVZofb3kzUhtACSCCo=", - "path": "github.com/ethereum/go-ethereum/swarm/tracing", - "revision": "7a22da98b9f81d206eb65d1fa4f5e773d888bac3", - "revisionTime": "2019-05-31T09:30:28Z" - }, { "checksumSHA1": "k43RYS4EvI3YvRbZP8pS9OO82QA=", "path": "github.com/ethereum/go-ethereum/trie",