From 903869a8272da80f667091454712c41bce538484 Mon Sep 17 00:00:00 2001 From: Ian Cottrell Date: Fri, 3 Apr 2020 22:59:59 -0400 Subject: [PATCH] internal/lsp: make event directly implement TagMap Makes Event implement TagMap directly, instead of having to build an entirely new object. Change-Id: I0c1e8638de3dc3347f60fd93af3df6b7f8387751 Reviewed-on: https://go-review.googlesource.com/c/tools/+/227300 Run-TryBot: Ian Cottrell TryBot-Result: Gobot Gobot Reviewed-by: Emmanuel Odeke --- internal/lsp/debug/rpc.go | 5 ++--- internal/lsp/debug/serve.go | 2 +- internal/telemetry/event/event.go | 12 ++++-------- internal/telemetry/event/export.go | 2 +- internal/telemetry/export/ocagent/ocagent.go | 2 +- internal/telemetry/export/tag.go | 2 +- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/internal/lsp/debug/rpc.go b/internal/lsp/debug/rpc.go index 46326611be..e1c93e2847 100644 --- a/internal/lsp/debug/rpc.go +++ b/internal/lsp/debug/rpc.go @@ -158,8 +158,7 @@ func (r *rpcs) getRPCSpan(ctx context.Context, ev event.Event) (*export.Span, *r } // use the span start event look up the correct stats block // we do this because it prevents us matching a sub span - startMap := span.Start().Map() - return span, r.getRPCStats(startMap) + return span, r.getRPCStats(span.Start()) } func (r *rpcs) getRPCStats(tagMap event.TagMap) *rpcStats { @@ -201,7 +200,7 @@ func (h *rpcTimeHistogram) Mean() timeUnits { return h.Sum / timeUnits(h.Count) func getStatusCode(span *export.Span) string { for _, ev := range span.Events() { - if status := tag.StatusCode.Get(ev.Map()); status != "" { + if status := tag.StatusCode.Get(ev); status != "" { return status } } diff --git a/internal/lsp/debug/serve.go b/internal/lsp/debug/serve.go index 11364b6e0e..c5781e5071 100644 --- a/internal/lsp/debug/serve.go +++ b/internal/lsp/debug/serve.go @@ -547,7 +547,7 @@ func makeGlobalExporter(stderr io.Writer) event.Exporter { if ev.IsLog() { // Don't log context cancellation errors. - if err := event.Err.Get(ev.Map()); xerrors.Is(err, context.Canceled) { + if err := event.Err.Get(ev); xerrors.Is(err, context.Canceled) { return ctx } // Make sure any log messages without an instance go to stderr. diff --git a/internal/telemetry/event/event.go b/internal/telemetry/event/event.go index 9a18c29b77..0ef81a86f3 100644 --- a/internal/telemetry/event/event.go +++ b/internal/telemetry/event/event.go @@ -54,7 +54,7 @@ func (ev Event) IsDetach() bool { return ev.typ == DetachType } func (ev Event) IsRecord() bool { return ev.typ == RecordType } func (ev Event) Format(f fmt.State, r rune) { - tagMap := ev.Map() + tagMap := TagMap(ev) if !ev.At.IsZero() { fmt.Fprint(f, ev.At.Format("2006/01/02 15:04:05 ")) } @@ -85,17 +85,13 @@ func (ev Event) Tags() TagIterator { NewTagIterator(ev.dynamic...)) } -func (ev Event) Map() TagMap { - return &eventTagMap{event: ev} -} - -func (m *eventTagMap) Find(key interface{}) Tag { - for _, tag := range m.event.static { +func (ev Event) Find(key interface{}) Tag { + for _, tag := range ev.static { if tag.Key == key { return tag } } - for _, tag := range m.event.dynamic { + for _, tag := range ev.dynamic { if tag.Key == key { return tag } diff --git a/internal/telemetry/event/export.go b/internal/telemetry/event/export.go index 5b41e99e9a..a2633b6023 100644 --- a/internal/telemetry/event/export.go +++ b/internal/telemetry/event/export.go @@ -40,7 +40,7 @@ func deliver(ctx context.Context, exporter Exporter, ev Event) context.Context { // add the current time to the event ev.At = time.Now() // hand the event off to the current exporter - return exporter(ctx, ev, ev.Map()) + return exporter(ctx, ev, ev) } // dispatch is called to deliver an event to the global exporter if set. diff --git a/internal/telemetry/export/ocagent/ocagent.go b/internal/telemetry/export/ocagent/ocagent.go index 5af78612e4..6eec1b9f00 100644 --- a/internal/telemetry/export/ocagent/ocagent.go +++ b/internal/telemetry/export/ocagent/ocagent.go @@ -299,7 +299,7 @@ func convertAnnotation(ev event.Event) *wire.Annotation { if !tags.Valid() { return nil } - tagMap := ev.Map() + tagMap := event.TagMap(ev) description := event.Msg.Get(tagMap) tags = event.Filter(tags, event.Msg) if description == "" { diff --git a/internal/telemetry/export/tag.go b/internal/telemetry/export/tag.go index 6acadf0c54..7d29529355 100644 --- a/internal/telemetry/export/tag.go +++ b/internal/telemetry/export/tag.go @@ -20,7 +20,7 @@ func Labels(output event.Exporter) event.Exporter { stored, _ := ctx.Value(labelContextKey).(event.TagMap) if ev.IsLabel() || ev.IsStartSpan() { // update the tag source stored in the context - fromEvent := ev.Map() + fromEvent := event.TagMap(ev) if stored == nil { stored = fromEvent } else {