From: Shengjing Zhu Date: Fri, 23 Feb 2024 21:44:16 -0700 Subject: Disable telemetry in gopls Co-authored-by: Anthony Fok Last-Update: 2024-03-24 --- cmd/deadcode/deadcode.go | 3 -- gopls/internal/cmd/serve.go | 4 --- gopls/internal/protocol/protocol.go | 4 +-- gopls/internal/server/command.go | 8 ----- gopls/internal/server/general.go | 9 +----- gopls/internal/server/prompt.go | 5 ++-- gopls/internal/telemetry/cmd/stacks/stacks.go | 2 ++ gopls/internal/telemetry/latency.go | 42 --------------------------- gopls/internal/telemetry/telemetry_test.go | 4 +-- gopls/internal/util/bug/bug.go | 6 ---- gopls/main.go | 2 -- 11 files changed, 9 insertions(+), 80 deletions(-) diff --git a/cmd/deadcode/deadcode.go b/cmd/deadcode/deadcode.go index e0fce42..1630a02 100644 --- a/cmd/deadcode/deadcode.go +++ b/cmd/deadcode/deadcode.go @@ -26,7 +26,6 @@ import ( "strings" "text/template" - "golang.org/x/telemetry" "golang.org/x/tools/go/callgraph" "golang.org/x/tools/go/callgraph/rta" "golang.org/x/tools/go/packages" @@ -64,8 +63,6 @@ Flags: } func main() { - telemetry.Start(telemetry.Config{ReportCrashes: true}) - log.SetPrefix("deadcode: ") log.SetFlags(0) // no time prefix diff --git a/gopls/internal/cmd/serve.go b/gopls/internal/cmd/serve.go index 3b79ccb..16f3b16 100644 --- a/gopls/internal/cmd/serve.go +++ b/gopls/internal/cmd/serve.go @@ -14,7 +14,6 @@ import ( "os" "time" - "golang.org/x/telemetry/upload" "golang.org/x/tools/gopls/internal/cache" "golang.org/x/tools/gopls/internal/debug" "golang.org/x/tools/gopls/internal/lsprpc" @@ -78,9 +77,6 @@ func (s *Serve) remoteArgs(network, address string) []string { // Run configures a server based on the flags, and then runs it. // It blocks until the server shuts down. func (s *Serve) Run(ctx context.Context, args ...string) error { - // TODO(adonovan): eliminate this once telemetry.Start has this effect. - go upload.Run(nil) // start telemetry uploader - if len(args) > 0 { return tool.CommandLineErrorf("server does not take arguments, got %v", args) } diff --git a/gopls/internal/protocol/protocol.go b/gopls/internal/protocol/protocol.go index 7cc5589..a703de8 100644 --- a/gopls/internal/protocol/protocol.go +++ b/gopls/internal/protocol/protocol.go @@ -11,7 +11,6 @@ import ( "fmt" "io" - "golang.org/x/telemetry/crashmonitor" "golang.org/x/tools/gopls/internal/util/bug" "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/jsonrpc2" @@ -302,7 +301,8 @@ func recoverHandlerPanic(method string) { // Report panics in the handler goroutine, // unless we have enabled the monitor, // which reports all crashes. - if !crashmonitor.Supported() { + // if !crashmonitor.Supported() { + if !false { defer func() { if x := recover(); x != nil { bug.Reportf("panic in %s request", method) diff --git a/gopls/internal/server/command.go b/gopls/internal/server/command.go index 3f5d53c..d92e6c6 100644 --- a/gopls/internal/server/command.go +++ b/gopls/internal/server/command.go @@ -21,7 +21,6 @@ import ( "sync" "golang.org/x/mod/modfile" - "golang.org/x/telemetry/counter" "golang.org/x/tools/go/ast/astutil" "golang.org/x/tools/gopls/internal/cache" "golang.org/x/tools/gopls/internal/cache/metadata" @@ -80,13 +79,6 @@ func (*commandHandler) AddTelemetryCounters(_ context.Context, args command.AddT return fmt.Errorf("Names and Values must have the same length") } // invalid counter update requests will be silently dropped. (no audience) - for i, n := range args.Names { - v := args.Values[i] - if n == "" || v < 0 { - continue - } - counter.Add("fwd/"+n, v) - } return nil } diff --git a/gopls/internal/server/general.go b/gopls/internal/server/general.go index 9ead470..13f8e5d 100644 --- a/gopls/internal/server/general.go +++ b/gopls/internal/server/general.go @@ -20,7 +20,6 @@ import ( "strings" "sync" - "golang.org/x/telemetry/counter" "golang.org/x/tools/gopls/internal/cache" "golang.org/x/tools/gopls/internal/debug" "golang.org/x/tools/gopls/internal/file" @@ -249,9 +248,6 @@ func (s *server) checkViewGoVersions() { if oldestVersion == -1 || viewVersion < oldestVersion { oldestVersion, fromBuild = viewVersion, false } - if viewVersion >= 0 { - counter.Inc(fmt.Sprintf("gopls/goversion:1.%d", viewVersion)) - } } if msg, isError := goversion.Message(oldestVersion, fromBuild); msg != "" { @@ -672,9 +668,6 @@ func recordClientInfo(clientName string) { // Accumulate at least a local counter for an unknown // client name, but also fall through to count it as // ":other" for collection. - if clientName != "" { - counter.New(fmt.Sprintf("gopls/client-other:%s", clientName)).Inc() - } } - counter.Inc(key) + _ = key } diff --git a/gopls/internal/server/prompt.go b/gopls/internal/server/prompt.go index 7dc16b9..e2015ba 100644 --- a/gopls/internal/server/prompt.go +++ b/gopls/internal/server/prompt.go @@ -11,7 +11,6 @@ import ( "path/filepath" "time" - "golang.org/x/telemetry" "golang.org/x/tools/gopls/internal/protocol" "golang.org/x/tools/internal/event" ) @@ -64,7 +63,7 @@ func (s *server) telemetryMode() string { } return "local" } - return telemetry.Mode() + return "off" } // setTelemetryMode sets the current telemetry mode. @@ -74,7 +73,7 @@ func (s *server) setTelemetryMode(mode string) error { if fake := s.getenv(FakeTelemetryModefileEnvvar); fake != "" { return os.WriteFile(fake, []byte(mode), 0666) } - return telemetry.SetMode(mode) + return nil } // maybePromptForTelemetry checks for the right conditions, and then prompts diff --git a/gopls/internal/telemetry/cmd/stacks/stacks.go b/gopls/internal/telemetry/cmd/stacks/stacks.go index 7123b3d..832a986 100644 --- a/gopls/internal/telemetry/cmd/stacks/stacks.go +++ b/gopls/internal/telemetry/cmd/stacks/stacks.go @@ -5,6 +5,8 @@ // The stacks command finds all gopls stack traces reported by // telemetry in the past 7 days, and reports their associated GitHub // issue, creating new issues as needed. + +//go:build ignore package main import ( diff --git a/gopls/internal/telemetry/latency.go b/gopls/internal/telemetry/latency.go index b0e2da7..e6a6f5a 100644 --- a/gopls/internal/telemetry/latency.go +++ b/gopls/internal/telemetry/latency.go @@ -7,12 +7,9 @@ package telemetry import ( "context" "errors" - "fmt" "sort" "sync" "time" - - "golang.org/x/telemetry/counter" ) // latencyKey is used for looking up latency counters. @@ -37,45 +34,8 @@ var ( } latencyCounterMu sync.Mutex - latencyCounters = make(map[latencyKey]*counter.Counter) // lazily populated ) -// ForEachLatencyCounter runs the provided function for each current latency -// counter measuring the given operation. -// -// Exported for testing. -func ForEachLatencyCounter(operation string, isError bool, f func(*counter.Counter)) { - latencyCounterMu.Lock() - defer latencyCounterMu.Unlock() - - for k, v := range latencyCounters { - if k.operation == operation && k.isError == isError { - f(v) - } - } -} - -// getLatencyCounter returns the counter used to record latency of the given -// operation in the given bucket. -func getLatencyCounter(operation, bucket string, isError bool) *counter.Counter { - latencyCounterMu.Lock() - defer latencyCounterMu.Unlock() - - key := latencyKey{operation, bucket, isError} - c, ok := latencyCounters[key] - if !ok { - var name string - if isError { - name = fmt.Sprintf("gopls/%s/error-latency:%s", operation, bucket) - } else { - name = fmt.Sprintf("gopls/%s/latency:%s", operation, bucket) - } - c = counter.New(name) - latencyCounters[key] = c - } - return c -} - // StartLatencyTimer starts a timer for the gopls operation with the given // name, and returns a func to stop the timer and record the latency sample. // @@ -95,8 +55,6 @@ func StartLatencyTimer(operation string) func(context.Context, error) { return latency < bucket.end }) if bucketIdx < len(latencyBuckets) { // ignore latency longer than a day :) - bucketName := latencyBuckets[bucketIdx].name - getLatencyCounter(operation, bucketName, err != nil).Inc() } } } diff --git a/gopls/internal/telemetry/telemetry_test.go b/gopls/internal/telemetry/telemetry_test.go index 1abd7ad..160b41d 100644 --- a/gopls/internal/telemetry/telemetry_test.go +++ b/gopls/internal/telemetry/telemetry_test.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.21 && !openbsd && !js && !wasip1 && !solaris && !android && !386 -// +build go1.21,!openbsd,!js,!wasip1,!solaris,!android,!386 +//go:build ignore && go1.21 && !openbsd && !js && !wasip1 && !solaris && !android && !386 +// +build ignore,go1.21,!openbsd,!js,!wasip1,!solaris,!android,!386 package telemetry_test diff --git a/gopls/internal/util/bug/bug.go b/gopls/internal/util/bug/bug.go index dcd242d..3b5a985 100644 --- a/gopls/internal/util/bug/bug.go +++ b/gopls/internal/util/bug/bug.go @@ -18,8 +18,6 @@ import ( "sort" "sync" "time" - - "golang.org/x/telemetry/counter" ) // PanicOnBugs controls whether to panic when bugs are reported. @@ -68,9 +66,6 @@ func Report(description string) { report(description) } -// BugReportCount is a telemetry counter that tracks # of bug reports. -var BugReportCount = counter.NewStack("gopls/bug", 16) - func report(description string) { _, file, line, ok := runtime.Caller(2) // all exported reporting functions call report directly @@ -106,7 +101,6 @@ func report(description string) { mu.Unlock() if newBug { - BugReportCount.Inc() } // Call the handlers outside the critical section since a // handler may itself fail and call bug.Report. Since handlers diff --git a/gopls/main.go b/gopls/main.go index 9217b27..6844865 100644 --- a/gopls/main.go +++ b/gopls/main.go @@ -17,7 +17,6 @@ import ( "context" "os" - "golang.org/x/telemetry" "golang.org/x/tools/gopls/internal/cmd" "golang.org/x/tools/gopls/internal/hooks" versionpkg "golang.org/x/tools/gopls/internal/version" @@ -29,7 +28,6 @@ var version = "" // if set by the linker, overrides the gopls version func main() { versionpkg.VersionOverride = version - telemetry.Start(telemetry.Config{ReportCrashes: true}) ctx := context.Background() tool.Main(ctx, cmd.New(hooks.Options), os.Args[1:]) }