From a6c03c86fe37d3a870a08c8814c242a6a4105726 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 15 Feb 2024 12:29:41 -0500 Subject: [PATCH] x/tools: update telemetry import (new Start API) Change-Id: I78701b620029a94b47524f5d4a77c35a86df2e4e Reviewed-on: https://go-review.googlesource.com/c/tools/+/564337 LUCI-TryBot-Result: Go LUCI Auto-Submit: Alan Donovan Commit-Queue: Alan Donovan Reviewed-by: Robert Findley --- cmd/deadcode/deadcode.go | 6 ++---- go.mod | 2 +- go.sum | 6 ++---- gopls/go.mod | 2 +- gopls/go.sum | 5 ++--- gopls/internal/telemetry/telemetry.go | 11 +++-------- gopls/internal/telemetry/telemetry_go118.go | 4 +--- gopls/internal/telemetry/telemetry_test.go | 14 +++++++++++++- gopls/main.go | 3 +-- 9 files changed, 26 insertions(+), 27 deletions(-) diff --git a/cmd/deadcode/deadcode.go b/cmd/deadcode/deadcode.go index 38a067e69f9..e0fce428d08 100644 --- a/cmd/deadcode/deadcode.go +++ b/cmd/deadcode/deadcode.go @@ -26,8 +26,7 @@ import ( "strings" "text/template" - "golang.org/x/telemetry/counter" - "golang.org/x/telemetry/crashmonitor" + "golang.org/x/telemetry" "golang.org/x/tools/go/callgraph" "golang.org/x/tools/go/callgraph/rta" "golang.org/x/tools/go/packages" @@ -65,8 +64,7 @@ Flags: } func main() { - counter.Open() // Enable telemetry counter writing. - crashmonitor.Start() // Enable crash reporting watchdog. + telemetry.Start(telemetry.Config{ReportCrashes: true}) log.SetPrefix("deadcode: ") log.SetFlags(0) // no time prefix diff --git a/go.mod b/go.mod index 54b8bd473c5..c8e522063d4 100644 --- a/go.mod +++ b/go.mod @@ -12,5 +12,5 @@ require golang.org/x/sync v0.6.0 require ( golang.org/x/sys v0.17.0 // indirect - golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808 + golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 ) diff --git a/go.sum b/go.sum index 373ed3cdd52..5e7611e6cca 100644 --- a/go.sum +++ b/go.sum @@ -8,7 +8,5 @@ golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/telemetry v0.0.0-20240201224847-0a1d30dda509 h1:Nr7eTQpQZ/ytesxDJpQgaf0t4sdLnnDtAbmtViTrSUo= -golang.org/x/telemetry v0.0.0-20240201224847-0a1d30dda509/go.mod h1:ZthVHHkOi8rlMEsfFr3Ie42Ym1NonbFNNRKW3ci0UrU= -golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808 h1:+Kc94D8UVEVxJnLXp/+FMfqQARZtWHfVrcRtcG8aT3g= -golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808/go.mod h1:KG1lNk5ZFNssSZLrpVb4sMXKMpGwGXOxSG3rnu2gZQQ= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= diff --git a/gopls/go.mod b/gopls/go.mod index 6a6bec7c5f1..fdf5998d264 100644 --- a/gopls/go.mod +++ b/gopls/go.mod @@ -8,7 +8,7 @@ require ( github.com/jba/templatecheck v0.7.0 golang.org/x/mod v0.15.0 golang.org/x/sync v0.6.0 - golang.org/x/telemetry v0.0.0-20240209200032-7b892fcb8a78 + golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 golang.org/x/text v0.14.0 golang.org/x/tools v0.18.0 golang.org/x/vuln v1.0.1 diff --git a/gopls/go.sum b/gopls/go.sum index ca69d20cfc4..4a9335ea552 100644 --- a/gopls/go.sum +++ b/gopls/go.sum @@ -27,9 +27,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808/go.mod h1:KG1lNk5ZFNssSZLrpVb4sMXKMpGwGXOxSG3rnu2gZQQ= -golang.org/x/telemetry v0.0.0-20240209200032-7b892fcb8a78 h1:vcVnuftN4J4UKLRcgetjzfU9FjjgXUUYUc3JhFplgV4= -golang.org/x/telemetry v0.0.0-20240209200032-7b892fcb8a78/go.mod h1:KG1lNk5ZFNssSZLrpVb4sMXKMpGwGXOxSG3rnu2gZQQ= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY= +golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/gopls/internal/telemetry/telemetry.go b/gopls/internal/telemetry/telemetry.go index deab5d22eb1..58083992a17 100644 --- a/gopls/internal/telemetry/telemetry.go +++ b/gopls/internal/telemetry/telemetry.go @@ -16,14 +16,9 @@ import ( "golang.org/x/telemetry/upload" ) -// CounterOpen calls [counter.Open]. -func CounterOpen() { - counter.Open() -} - -// StartCrashMonitor calls [crashmonitor.Start]. -func StartCrashMonitor() { - crashmonitor.Start() +// Start starts telemetry, including the crash monitor. +func Start() { + telemetry.Start(telemetry.Config{ReportCrashes: true}) } // CrashMonitorSupported calls [crashmonitor.Supported]. diff --git a/gopls/internal/telemetry/telemetry_go118.go b/gopls/internal/telemetry/telemetry_go118.go index 12b7803f1a7..3fd1df2939c 100644 --- a/gopls/internal/telemetry/telemetry_go118.go +++ b/gopls/internal/telemetry/telemetry_go118.go @@ -12,9 +12,7 @@ package telemetry // gopls may not refer to the telemetry module directly, but must go // through this file. -func CounterOpen() {} - -func StartCrashMonitor() {} +func Start() {} func CrashMonitorSupported() bool { return false } diff --git a/gopls/internal/telemetry/telemetry_test.go b/gopls/internal/telemetry/telemetry_test.go index b52ac7093c7..1abd7ada03c 100644 --- a/gopls/internal/telemetry/telemetry_test.go +++ b/gopls/internal/telemetry/telemetry_test.go @@ -59,7 +59,7 @@ func TestTelemetry(t *testing.T) { for i, c := range sessionCounters { count, err := countertest.ReadCounter(c) if err != nil { - t.Fatalf("ReadCounter(%s): %v", c.Name(), err) + continue // counter db not open, or counter not found } initialCounts[i] = count } @@ -74,7 +74,19 @@ func TestTelemetry(t *testing.T) { goversion = strconv.Itoa(env.GoVersion()) addForwardedCounters(env, []string{"vscode/linter:a"}, []int64{1}) const desc = "got a bug" + + // This will increment a counter named something like: + // + // `gopls/bug + // golang.org/x/tools/gopls/internal/util/bug.report:+35 + // golang.org/x/tools/gopls/internal/util/bug.Report:=68 + // golang.org/x/tools/gopls/internal/telemetry_test.TestTelemetry.func2:+4 + // golang.org/x/tools/gopls/internal/test/integration.(*Runner).Run.func1:+87 + // testing.tRunner:+150 + // runtime.goexit:+0` + // bug.Report(desc) // want a stack counter with the trace starting from here. + env.Await(ShownMessage(desc)) }) diff --git a/gopls/main.go b/gopls/main.go index e3fb3861f68..31c5c5fdf1a 100644 --- a/gopls/main.go +++ b/gopls/main.go @@ -29,8 +29,7 @@ var version = "" // if set by the linker, overrides the gopls version func main() { versionpkg.VersionOverride = version - telemetry.CounterOpen() - telemetry.StartCrashMonitor() + telemetry.Start() ctx := context.Background() tool.Main(ctx, cmd.New(hooks.Options), os.Args[1:]) }