aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/debug
diff options
context:
space:
mode:
authorIan Cottrell <iancottrell@google.com>2020-03-26 22:00:12 -0400
committerIan Cottrell <iancottrell@google.com>2020-03-31 00:50:33 +0000
commit80f63e2b9b4314bc38c0cefb598900d30f7d1429 (patch)
tree806ebc0d23e7c03cd0cb66e63d190fbb45a55f9d /internal/lsp/debug
parent657a652153b51184fc743971963d74b2b2eb1e0d (diff)
downloadgolang-x-tools-80f63e2b9b4314bc38c0cefb598900d30f7d1429.tar.gz
internal/lsp: rewrite the stats using the newer telemetry features
This allows us to reduce the handler interface and delete the telemetry handler. It is also safer and faster, and can be easily disabled along with the rest of the telemetry system. Change-Id: Ia4961d7f2e374f7dc22360d6a4020a065bfeae6f Reviewed-on: https://go-review.googlesource.com/c/tools/+/225957 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'internal/lsp/debug')
-rw-r--r--internal/lsp/debug/rpc.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/internal/lsp/debug/rpc.go b/internal/lsp/debug/rpc.go
index 0f39c7cdd..823ee9d43 100644
--- a/internal/lsp/debug/rpc.go
+++ b/internal/lsp/debug/rpc.go
@@ -11,9 +11,11 @@ import (
"net/http"
"sort"
"sync"
+ "time"
"golang.org/x/tools/internal/lsp/debug/tag"
"golang.org/x/tools/internal/telemetry/event"
+ "golang.org/x/tools/internal/telemetry/export"
"golang.org/x/tools/internal/telemetry/export/metric"
)
@@ -92,11 +94,33 @@ type rpcCodeBucket struct {
}
func (r *rpcs) ProcessEvent(ctx context.Context, ev event.Event, tagMap event.TagMap) context.Context {
- if !ev.IsRecord() {
+ switch {
+ case ev.IsEndSpan():
+ // calculate latency if this was an rpc span
+ span := export.GetSpan(ctx)
+ if span == nil {
+ return ctx
+ }
+ // is this a finished rpc span, if so it will have a status code record
+ for _, ev := range span.Events() {
+ code := tag.StatusCode.Get(ev.Map())
+ if code != "" {
+ elapsedTime := span.Finish().At.Sub(span.Start().At)
+ latencyMillis := float64(elapsedTime) / float64(time.Millisecond)
+ statsCtx := event.Label1(ctx, tag.StatusCode.Of(code))
+ event.Record1(statsCtx, tag.Latency.Of(latencyMillis))
+ }
+ }
+ return ctx
+ case ev.IsRecord():
+ // fall through to the metrics handling logic
+ default:
+ // ignore all other event types
return ctx
}
r.mu.Lock()
defer r.mu.Unlock()
+ //TODO(38168): we should just deal with the events here and not use metrics
metrics := metric.Entries.Get(tagMap).([]metric.Data)
for _, data := range metrics {
for i, group := range data.Groups() {