Skip to content

Commit

Permalink
gopls: upgrade x/telemetry and account for new mode logic
Browse files Browse the repository at this point in the history
Upgrade x/telemetry to pick up the new (on|off|local) mode logic. In
this new schema, when the mode is explicitly "off" we should assume that
the user doesn't want to be prompted about enabling telemetry. Update
our internal logic and tests accordingly.

For golang/go#63832

Change-Id: I7b9c0840c48c680110ffa84c59bce2d5249942dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/542317
Reviewed-by: Peter Weinberger <pjw@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
findleyr committed Nov 14, 2023
1 parent 38fc9a2 commit 944d4e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions gopls/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ require (
github.com/sergi/go-diff v1.1.0
golang.org/x/mod v0.14.0
golang.org/x/sync v0.5.0
golang.org/x/sys v0.14.0
golang.org/x/telemetry v0.0.0-20231011160506-788d5629a052
golang.org/x/telemetry v0.0.0-20231114163143-69313e640400
golang.org/x/text v0.14.0
golang.org/x/tools v0.13.1-0.20230920233436-f9b8da7b22be
golang.org/x/vuln v1.0.1
Expand All @@ -24,6 +23,7 @@ require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/google/safehtml v0.1.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 // indirect
golang.org/x/sys v0.14.0 // indirect

)

Expand Down
4 changes: 2 additions & 2 deletions gopls/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,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.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20231011160506-788d5629a052 h1:1baVNneD/IRxmu8JQdBuki78zUqBtZxq8smZXQj0X2Y=
golang.org/x/telemetry v0.0.0-20231011160506-788d5629a052/go.mod h1:6p4ScoNeC2dhpQ1nSSMmkZ7mEj5JQUSCyc0uExBp5T4=
golang.org/x/telemetry v0.0.0-20231114163143-69313e640400 h1:brbkEFfGwNGAEkykUOcryE/JiHUMMJouzE0fWWmz/QU=
golang.org/x/telemetry v0.0.0-20231114163143-69313e640400/go.mod h1:P6hMdmAcoG7FyATwqSr6R/U0n7yeXNP/QXeRlxb1szE=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
10 changes: 5 additions & 5 deletions gopls/internal/lsp/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *server) telemetryMode() string {
if data, err := os.ReadFile(fake); err == nil {
return string(data)
}
return "off"
return "local"
}
return telemetry.Mode()
}
Expand Down Expand Up @@ -95,8 +95,8 @@ func (s *server) maybePromptForTelemetry(ctx context.Context, enabled bool) {
return // prompt is disabled
}

if s.telemetryMode() == "on" {
// Telemetry is already on -- nothing to ask about.
if s.telemetryMode() == "on" || s.telemetryMode() == "off" {
// Telemetry is already on or explicitly off -- nothing to ask about.
return
}

Expand Down Expand Up @@ -262,9 +262,9 @@ func telemetryOnMessage(linkify bool) string {
To disable telemetry uploading, run %s.
`
var runCmd = "`go run golang.org/x/telemetry/cmd/gotelemetry@latest off`"
var runCmd = "`go run golang.org/x/telemetry/cmd/gotelemetry@latest local`"
if linkify {
runCmd = "[gotelemetry off](https://golang.org/x/telemetry/cmd/gotelemetry)"
runCmd = "[gotelemetry local](https://golang.org/x/telemetry/cmd/gotelemetry)"
}
return fmt.Sprintf(format, runCmd)
}
Expand Down
4 changes: 2 additions & 2 deletions gopls/internal/regtest/misc/prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {

for _, enabled := range []bool{true, false} {
t.Run(fmt.Sprintf("telemetryPrompt=%v", enabled), func(t *testing.T) {
for _, initialMode := range []string{"", "off", "on"} {
for _, initialMode := range []string{"", "local", "off", "on"} {
t.Run(fmt.Sprintf("initial_mode=%s", initialMode), func(t *testing.T) {
modeFile := filepath.Join(t.TempDir(), "mode")
if initialMode != "" {
Expand All @@ -51,7 +51,7 @@ func main() {
"telemetryPrompt": enabled,
},
).Run(t, src, func(t *testing.T, env *Env) {
wantPrompt := enabled && (initialMode == "" || initialMode == "off")
wantPrompt := enabled && (initialMode == "" || initialMode == "local")
expectation := ShownMessageRequest(".*Would you like to enable Go telemetry?")
if !wantPrompt {
expectation = Not(expectation)
Expand Down

0 comments on commit 944d4e7

Please sign in to comment.