Skip to content

Commit

Permalink
x/tools: update telemetry import (new Start API)
Browse files Browse the repository at this point in the history
Change-Id: I78701b620029a94b47524f5d4a77c35a86df2e4e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/564337
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
adonovan authored and gopherbot committed Feb 28, 2024
1 parent 1f7dbdf commit a6c03c8
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 27 deletions.
6 changes: 2 additions & 4 deletions cmd/deadcode/deadcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
2 changes: 1 addition & 1 deletion gopls/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions gopls/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 3 additions & 8 deletions gopls/internal/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
4 changes: 1 addition & 3 deletions gopls/internal/telemetry/telemetry_go118.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
14 changes: 13 additions & 1 deletion gopls/internal/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
})

Expand Down
3 changes: 1 addition & 2 deletions gopls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
}

0 comments on commit a6c03c8

Please sign in to comment.