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>
(cherry picked from commit 944d4e7)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/542156
Reviewed-by: Alan Donovan <adonovan@google.com>
  • Loading branch information
findleyr committed Nov 14, 2023
1 parent e985f84 commit c9d3e7d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions gopls/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ require (
github.com/jba/printsrc v0.2.2
github.com/jba/templatecheck v0.6.0
github.com/sergi/go-diff v1.1.0
golang.org/x/mod v0.13.0
golang.org/x/mod v0.14.0
golang.org/x/sync v0.4.0
golang.org/x/sys v0.13.0
golang.org/x/telemetry v0.0.0-20231011160506-788d5629a052
golang.org/x/sys v0.14.0
golang.org/x/telemetry v0.0.0-20231114163143-69313e640400
golang.org/x/text v0.13.0
golang.org/x/tools v0.14.1-0.20231026192422-8b5abd452b28
golang.org/x/vuln v1.0.1
Expand Down
12 changes: 6 additions & 6 deletions gopls/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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/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-20231114163143-69313e640400 h1:brbkEFfGwNGAEkykUOcryE/JiHUMMJouzE0fWWmz/QU=
golang.org/x/telemetry v0.0.0-20231114163143-69313e640400/go.mod h1:P6hMdmAcoG7FyATwqSr6R/U0n7yeXNP/QXeRlxb1szE=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
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 c9d3e7d

Please sign in to comment.