| 1 |
From: Shengjing Zhu <[email protected]> |
| 2 |
Date: Fri, 23 Feb 2024 21:44:16 -0700 |
| 3 |
Subject: Disable telemetry in gopls |
| 4 |
|
| 5 |
Co-authored-by: Anthony Fok <[email protected]> |
| 6 |
Last-Update: 2024-03-24 |
| 7 |
--- |
| 8 |
cmd/deadcode/deadcode.go | 3 -- |
| 9 |
gopls/internal/cmd/serve.go | 4 --- |
| 10 |
gopls/internal/protocol/protocol.go | 4 +-- |
| 11 |
gopls/internal/server/command.go | 8 ----- |
| 12 |
gopls/internal/server/general.go | 9 +----- |
| 13 |
gopls/internal/server/prompt.go | 5 ++-- |
| 14 |
gopls/internal/telemetry/cmd/stacks/stacks.go | 2 ++ |
| 15 |
gopls/internal/telemetry/latency.go | 42 --------------------------- |
| 16 |
gopls/internal/telemetry/telemetry_test.go | 4 +-- |
| 17 |
gopls/internal/util/bug/bug.go | 6 ---- |
| 18 |
gopls/main.go | 2 -- |
| 19 |
11 files changed, 9 insertions(+), 80 deletions(-) |
| 20 |
|
| 21 |
diff --git a/cmd/deadcode/deadcode.go b/cmd/deadcode/deadcode.go |
| 22 |
index e0fce42..1630a02 100644 |
| 23 |
--- a/cmd/deadcode/deadcode.go |
| 24 |
+++ b/cmd/deadcode/deadcode.go |
| 25 |
@@ -26,7 +26,6 @@ import ( |
| 26 |
"strings" |
| 27 |
"text/template" |
| 28 |
|
| 29 |
- "golang.org/x/telemetry" |
| 30 |
"golang.org/x/tools/go/callgraph" |
| 31 |
"golang.org/x/tools/go/callgraph/rta" |
| 32 |
"golang.org/x/tools/go/packages" |
| 33 |
@@ -64,8 +63,6 @@ Flags: |
| 34 |
} |
| 35 |
|
| 36 |
func main() { |
| 37 |
- telemetry.Start(telemetry.Config{ReportCrashes: true}) |
| 38 |
- |
| 39 |
log.SetPrefix("deadcode: ") |
| 40 |
log.SetFlags(0) // no time prefix |
| 41 |
|
| 42 |
diff --git a/gopls/internal/cmd/serve.go b/gopls/internal/cmd/serve.go |
| 43 |
index 3b79ccb..16f3b16 100644 |
| 44 |
--- a/gopls/internal/cmd/serve.go |
| 45 |
+++ b/gopls/internal/cmd/serve.go |
| 46 |
@@ -14,7 +14,6 @@ import ( |
| 47 |
"os" |
| 48 |
"time" |
| 49 |
|
| 50 |
- "golang.org/x/telemetry/upload" |
| 51 |
"golang.org/x/tools/gopls/internal/cache" |
| 52 |
"golang.org/x/tools/gopls/internal/debug" |
| 53 |
"golang.org/x/tools/gopls/internal/lsprpc" |
| 54 |
@@ -78,9 +77,6 @@ func (s *Serve) remoteArgs(network, address string) []string { |
| 55 |
// Run configures a server based on the flags, and then runs it. |
| 56 |
// It blocks until the server shuts down. |
| 57 |
func (s *Serve) Run(ctx context.Context, args ...string) error { |
| 58 |
- // TODO(adonovan): eliminate this once telemetry.Start has this effect. |
| 59 |
- go upload.Run(nil) // start telemetry uploader |
| 60 |
- |
| 61 |
if len(args) > 0 { |
| 62 |
return tool.CommandLineErrorf("server does not take arguments, got %v", args) |
| 63 |
} |
| 64 |
diff --git a/gopls/internal/protocol/protocol.go b/gopls/internal/protocol/protocol.go |
| 65 |
index 7cc5589..a703de8 100644 |
| 66 |
--- a/gopls/internal/protocol/protocol.go |
| 67 |
+++ b/gopls/internal/protocol/protocol.go |
| 68 |
@@ -11,7 +11,6 @@ import ( |
| 69 |
"fmt" |
| 70 |
"io" |
| 71 |
|
| 72 |
- "golang.org/x/telemetry/crashmonitor" |
| 73 |
"golang.org/x/tools/gopls/internal/util/bug" |
| 74 |
"golang.org/x/tools/internal/event" |
| 75 |
"golang.org/x/tools/internal/jsonrpc2" |
| 76 |
@@ -302,7 +301,8 @@ func recoverHandlerPanic(method string) { |
| 77 |
// Report panics in the handler goroutine, |
| 78 |
// unless we have enabled the monitor, |
| 79 |
// which reports all crashes. |
| 80 |
- if !crashmonitor.Supported() { |
| 81 |
+ // if !crashmonitor.Supported() { |
| 82 |
+ if !false { |
| 83 |
defer func() { |
| 84 |
if x := recover(); x != nil { |
| 85 |
bug.Reportf("panic in %s request", method) |
| 86 |
diff --git a/gopls/internal/server/command.go b/gopls/internal/server/command.go |
| 87 |
index 3f5d53c..d92e6c6 100644 |
| 88 |
--- a/gopls/internal/server/command.go |
| 89 |
+++ b/gopls/internal/server/command.go |
| 90 |
@@ -21,7 +21,6 @@ import ( |
| 91 |
"sync" |
| 92 |
|
| 93 |
"golang.org/x/mod/modfile" |
| 94 |
- "golang.org/x/telemetry/counter" |
| 95 |
"golang.org/x/tools/go/ast/astutil" |
| 96 |
"golang.org/x/tools/gopls/internal/cache" |
| 97 |
"golang.org/x/tools/gopls/internal/cache/metadata" |
| 98 |
@@ -80,13 +79,6 @@ func (*commandHandler) AddTelemetryCounters(_ context.Context, args command.AddT |
| 99 |
return fmt.Errorf("Names and Values must have the same length") |
| 100 |
} |
| 101 |
// invalid counter update requests will be silently dropped. (no audience) |
| 102 |
- for i, n := range args.Names { |
| 103 |
- v := args.Values[i] |
| 104 |
- if n == "" || v < 0 { |
| 105 |
- continue |
| 106 |
- } |
| 107 |
- counter.Add("fwd/"+n, v) |
| 108 |
- } |
| 109 |
return nil |
| 110 |
} |
| 111 |
|
| 112 |
diff --git a/gopls/internal/server/general.go b/gopls/internal/server/general.go |
| 113 |
index 9ead470..13f8e5d 100644 |
| 114 |
--- a/gopls/internal/server/general.go |
| 115 |
+++ b/gopls/internal/server/general.go |
| 116 |
@@ -20,7 +20,6 @@ import ( |
| 117 |
"strings" |
| 118 |
"sync" |
| 119 |
|
| 120 |
- "golang.org/x/telemetry/counter" |
| 121 |
"golang.org/x/tools/gopls/internal/cache" |
| 122 |
"golang.org/x/tools/gopls/internal/debug" |
| 123 |
"golang.org/x/tools/gopls/internal/file" |
| 124 |
@@ -249,9 +248,6 @@ func (s *server) checkViewGoVersions() { |
| 125 |
if oldestVersion == -1 || viewVersion < oldestVersion { |
| 126 |
oldestVersion, fromBuild = viewVersion, false |
| 127 |
} |
| 128 |
- if viewVersion >= 0 { |
| 129 |
- counter.Inc(fmt.Sprintf("gopls/goversion:1.%d", viewVersion)) |
| 130 |
- } |
| 131 |
} |
| 132 |
|
| 133 |
if msg, isError := goversion.Message(oldestVersion, fromBuild); msg != "" { |
| 134 |
@@ -672,9 +668,6 @@ func recordClientInfo(clientName string) { |
| 135 |
// Accumulate at least a local counter for an unknown |
| 136 |
// client name, but also fall through to count it as |
| 137 |
// ":other" for collection. |
| 138 |
- if clientName != "" { |
| 139 |
- counter.New(fmt.Sprintf("gopls/client-other:%s", clientName)).Inc() |
| 140 |
- } |
| 141 |
} |
| 142 |
- counter.Inc(key) |
| 143 |
+ _ = key |
| 144 |
} |
| 145 |
diff --git a/gopls/internal/server/prompt.go b/gopls/internal/server/prompt.go |
| 146 |
index 7dc16b9..e2015ba 100644 |
| 147 |
--- a/gopls/internal/server/prompt.go |
| 148 |
+++ b/gopls/internal/server/prompt.go |
| 149 |
@@ -11,7 +11,6 @@ import ( |
| 150 |
"path/filepath" |
| 151 |
"time" |
| 152 |
|
| 153 |
- "golang.org/x/telemetry" |
| 154 |
"golang.org/x/tools/gopls/internal/protocol" |
| 155 |
"golang.org/x/tools/internal/event" |
| 156 |
) |
| 157 |
@@ -64,7 +63,7 @@ func (s *server) telemetryMode() string { |
| 158 |
} |
| 159 |
return "local" |
| 160 |
} |
| 161 |
- return telemetry.Mode() |
| 162 |
+ return "off" |
| 163 |
} |
| 164 |
|
| 165 |
// setTelemetryMode sets the current telemetry mode. |
| 166 |
@@ -74,7 +73,7 @@ func (s *server) setTelemetryMode(mode string) error { |
| 167 |
if fake := s.getenv(FakeTelemetryModefileEnvvar); fake != "" { |
| 168 |
return os.WriteFile(fake, []byte(mode), 0666) |
| 169 |
} |
| 170 |
- return telemetry.SetMode(mode) |
| 171 |
+ return nil |
| 172 |
} |
| 173 |
|
| 174 |
// maybePromptForTelemetry checks for the right conditions, and then prompts |
| 175 |
diff --git a/gopls/internal/telemetry/cmd/stacks/stacks.go b/gopls/internal/telemetry/cmd/stacks/stacks.go |
| 176 |
index 7123b3d..832a986 100644 |
| 177 |
--- a/gopls/internal/telemetry/cmd/stacks/stacks.go |
| 178 |
+++ b/gopls/internal/telemetry/cmd/stacks/stacks.go |
| 179 |
@@ -5,6 +5,8 @@ |
| 180 |
// The stacks command finds all gopls stack traces reported by |
| 181 |
// telemetry in the past 7 days, and reports their associated GitHub |
| 182 |
// issue, creating new issues as needed. |
| 183 |
+ |
| 184 |
+//go:build ignore |
| 185 |
package main |
| 186 |
|
| 187 |
import ( |
| 188 |
diff --git a/gopls/internal/telemetry/latency.go b/gopls/internal/telemetry/latency.go |
| 189 |
index b0e2da7..e6a6f5a 100644 |
| 190 |
--- a/gopls/internal/telemetry/latency.go |
| 191 |
+++ b/gopls/internal/telemetry/latency.go |
| 192 |
@@ -7,12 +7,9 @@ package telemetry |
| 193 |
import ( |
| 194 |
"context" |
| 195 |
"errors" |
| 196 |
- "fmt" |
| 197 |
"sort" |
| 198 |
"sync" |
| 199 |
"time" |
| 200 |
- |
| 201 |
- "golang.org/x/telemetry/counter" |
| 202 |
) |
| 203 |
|
| 204 |
// latencyKey is used for looking up latency counters. |
| 205 |
@@ -37,45 +34,8 @@ var ( |
| 206 |
} |
| 207 |
|
| 208 |
latencyCounterMu sync.Mutex |
| 209 |
- latencyCounters = make(map[latencyKey]*counter.Counter) // lazily populated |
| 210 |
) |
| 211 |
|
| 212 |
-// ForEachLatencyCounter runs the provided function for each current latency |
| 213 |
-// counter measuring the given operation. |
| 214 |
-// |
| 215 |
-// Exported for testing. |
| 216 |
-func ForEachLatencyCounter(operation string, isError bool, f func(*counter.Counter)) { |
| 217 |
- latencyCounterMu.Lock() |
| 218 |
- defer latencyCounterMu.Unlock() |
| 219 |
- |
| 220 |
- for k, v := range latencyCounters { |
| 221 |
- if k.operation == operation && k.isError == isError { |
| 222 |
- f(v) |
| 223 |
- } |
| 224 |
- } |
| 225 |
-} |
| 226 |
- |
| 227 |
-// getLatencyCounter returns the counter used to record latency of the given |
| 228 |
-// operation in the given bucket. |
| 229 |
-func getLatencyCounter(operation, bucket string, isError bool) *counter.Counter { |
| 230 |
- latencyCounterMu.Lock() |
| 231 |
- defer latencyCounterMu.Unlock() |
| 232 |
- |
| 233 |
- key := latencyKey{operation, bucket, isError} |
| 234 |
- c, ok := latencyCounters[key] |
| 235 |
- if !ok { |
| 236 |
- var name string |
| 237 |
- if isError { |
| 238 |
- name = fmt.Sprintf("gopls/%s/error-latency:%s", operation, bucket) |
| 239 |
- } else { |
| 240 |
- name = fmt.Sprintf("gopls/%s/latency:%s", operation, bucket) |
| 241 |
- } |
| 242 |
- c = counter.New(name) |
| 243 |
- latencyCounters[key] = c |
| 244 |
- } |
| 245 |
- return c |
| 246 |
-} |
| 247 |
- |
| 248 |
// StartLatencyTimer starts a timer for the gopls operation with the given |
| 249 |
// name, and returns a func to stop the timer and record the latency sample. |
| 250 |
// |
| 251 |
@@ -95,8 +55,6 @@ func StartLatencyTimer(operation string) func(context.Context, error) { |
| 252 |
return latency < bucket.end |
| 253 |
}) |
| 254 |
if bucketIdx < len(latencyBuckets) { // ignore latency longer than a day :) |
| 255 |
- bucketName := latencyBuckets[bucketIdx].name |
| 256 |
- getLatencyCounter(operation, bucketName, err != nil).Inc() |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
diff --git a/gopls/internal/telemetry/telemetry_test.go b/gopls/internal/telemetry/telemetry_test.go |
| 261 |
index 1abd7ad..160b41d 100644 |
| 262 |
--- a/gopls/internal/telemetry/telemetry_test.go |
| 263 |
+++ b/gopls/internal/telemetry/telemetry_test.go |
| 264 |
@@ -2,8 +2,8 @@ |
| 265 |
// Use of this source code is governed by a BSD-style |
| 266 |
// license that can be found in the LICENSE file. |
| 267 |
|
| 268 |
-//go:build go1.21 && !openbsd && !js && !wasip1 && !solaris && !android && !386 |
| 269 |
-// +build go1.21,!openbsd,!js,!wasip1,!solaris,!android,!386 |
| 270 |
+//go:build ignore && go1.21 && !openbsd && !js && !wasip1 && !solaris && !android && !386 |
| 271 |
+// +build ignore,go1.21,!openbsd,!js,!wasip1,!solaris,!android,!386 |
| 272 |
|
| 273 |
package telemetry_test |
| 274 |
|
| 275 |
diff --git a/gopls/internal/util/bug/bug.go b/gopls/internal/util/bug/bug.go |
| 276 |
index dcd242d..3b5a985 100644 |
| 277 |
--- a/gopls/internal/util/bug/bug.go |
| 278 |
+++ b/gopls/internal/util/bug/bug.go |
| 279 |
@@ -18,8 +18,6 @@ import ( |
| 280 |
"sort" |
| 281 |
"sync" |
| 282 |
"time" |
| 283 |
- |
| 284 |
- "golang.org/x/telemetry/counter" |
| 285 |
) |
| 286 |
|
| 287 |
// PanicOnBugs controls whether to panic when bugs are reported. |
| 288 |
@@ -68,9 +66,6 @@ func Report(description string) { |
| 289 |
report(description) |
| 290 |
} |
| 291 |
|
| 292 |
-// BugReportCount is a telemetry counter that tracks # of bug reports. |
| 293 |
-var BugReportCount = counter.NewStack("gopls/bug", 16) |
| 294 |
- |
| 295 |
func report(description string) { |
| 296 |
_, file, line, ok := runtime.Caller(2) // all exported reporting functions call report directly |
| 297 |
|
| 298 |
@@ -106,7 +101,6 @@ func report(description string) { |
| 299 |
mu.Unlock() |
| 300 |
|
| 301 |
if newBug { |
| 302 |
- BugReportCount.Inc() |
| 303 |
} |
| 304 |
// Call the handlers outside the critical section since a |
| 305 |
// handler may itself fail and call bug.Report. Since handlers |
| 306 |
diff --git a/gopls/main.go b/gopls/main.go |
| 307 |
index 9217b27..6844865 100644 |
| 308 |
--- a/gopls/main.go |
| 309 |
+++ b/gopls/main.go |
| 310 |
@@ -17,7 +17,6 @@ import ( |
| 311 |
"context" |
| 312 |
"os" |
| 313 |
|
| 314 |
- "golang.org/x/telemetry" |
| 315 |
"golang.org/x/tools/gopls/internal/cmd" |
| 316 |
"golang.org/x/tools/gopls/internal/hooks" |
| 317 |
versionpkg "golang.org/x/tools/gopls/internal/version" |
| 318 |
@@ -29,7 +28,6 @@ var version = "" // if set by the linker, overrides the gopls version |
| 319 |
func main() { |
| 320 |
versionpkg.VersionOverride = version |
| 321 |
|
| 322 |
- telemetry.Start(telemetry.Config{ReportCrashes: true}) |
| 323 |
ctx := context.Background() |
| 324 |
tool.Main(ctx, cmd.New(hooks.Options), os.Args[1:]) |
| 325 |
} |