Skip to content

Commit 3f29941

Browse files
findleyrgopherbot
authored andcommitted
all: remove the "local" mode in favor of just "off" and "on"
Per discussion, "local" mode does not offer much long term benefit: it just exists to have a bail-out in case of e.g. performance problems with telemetry collection. But such problems should be unlikely, and it's not worth the more complicated state: revert to just on/off. Fixes golang/go#63143 Change-Id: I416fd511742207336d73ce9c00ba19743e6d9694 Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/530436 Auto-Submit: Robert Findley <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent dd3d43c commit 3f29941

File tree

6 files changed

+14
-27
lines changed

6 files changed

+14
-27
lines changed

cmd/gotelemetry/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func usage() {
7171
w := flag.CommandLine.Output()
7272
fmt.Fprintln(w, "Usage:")
7373
fmt.Fprintln(w, "\tgotelemetry")
74-
fmt.Fprintln(w, "\tgotelemetry set <on|off|local>")
74+
fmt.Fprintln(w, "\tgotelemetry set <on|off>")
7575
fmt.Fprintln(w, "\tgotelemetry dump [file1 file2 ...]")
7676
fmt.Fprintln(w, "\tgotelemetry view (runs web server)")
7777
fmt.Fprintln(w, "\tgotelemetry csv (prints all known counters)")

internal/counter/file.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ func (f *file) lookup(name string) counterPtr {
111111
return counterPtr{current, ptr}
112112
}
113113

114-
// ErrDisabled is the error returned when telemetry is disabled.
115-
var ErrDisabled = errors.New("counter: disabled by GOTELEMETRY=off")
116-
117114
var (
118115
errNoBuildInfo = errors.New("counter: missing build info")
119116
errCorrupt = errors.New("counter: corrupt counter file")
@@ -125,10 +122,6 @@ func (f *file) init(begin, end time.Time) {
125122
f.err = errNoBuildInfo
126123
return
127124
}
128-
if telemetry.Mode() == "off" {
129-
f.err = ErrDisabled
130-
return
131-
}
132125
dir := telemetry.LocalDir
133126

134127
if err := os.MkdirAll(dir, 0777); err != nil {

internal/telemetry/mode.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ func init() {
4141
}
4242

4343
// SetMode updates the telemetry mode with the given mode.
44-
// Acceptable values for mode are "on", "off", or "local".
44+
// Acceptable values for mode are "on" or "off".
4545
func SetMode(mode string) error {
4646
return ModeFile.SetMode(mode)
4747
}
4848

4949
func (m ModeFilePath) SetMode(mode string) error {
5050
mode = strings.TrimSpace(mode)
5151
switch mode {
52-
case "on", "off", "local":
52+
case "on", "off":
5353
default:
5454
return fmt.Errorf("invalid telemetry mode: %q", mode)
5555
}
@@ -76,7 +76,7 @@ func (m ModeFilePath) Mode() string {
7676
}
7777
data, err := os.ReadFile(fname)
7878
if err != nil {
79-
return "local" // default
79+
return "off" // default
8080
}
8181
mode := string(data)
8282
mode = strings.TrimSpace(mode)

internal/telemetry/mode_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestTelemetryModeWithNoModeConfig(t *testing.T) {
3333
modefile ModeFilePath
3434
want string
3535
}{
36-
{ModeFilePath(filepath.Join(tmp, "mode")), "local"},
36+
{ModeFilePath(filepath.Join(tmp, "mode")), "off"},
3737
{"", "off"},
3838
}
3939
for _, tt := range tests {
@@ -51,7 +51,7 @@ func TestTelemetryMode(t *testing.T) {
5151
}{
5252
{"on", false},
5353
{"off", false},
54-
{"local", false},
54+
{"local", true}, // golang/go#63143: local mode is no longer supported
5555
{"https://mytelemetry.com", true},
5656
{"http://insecure.com", true},
5757
{"bogus", true},

internal/upload/reports.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ var (
2727

2828
// reports generates reports from inactive count files
2929
func reports(todo *work) ([]string, error) {
30-
if it.Mode() == "off" {
31-
return nil, nil // no reports
32-
}
3330
today := thisInstant.Format("2006-01-02")
3431
lastWeek := latestReport(todo.uploaded)
3532
if lastWeek >= today { //should never happen
@@ -113,7 +110,7 @@ func createReport(date string, files []string, lastWeek string) (string, error)
113110
configVersion = v
114111
}
115112
uploadOK := true
116-
if uploadConfig == nil || it.Mode() == "local" {
113+
if uploadConfig == nil || it.Mode() != "on" {
117114
uploadOK = false // no config, nothing to upload
118115
}
119116
if tooOld(date) {

mode.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@ import (
1010

1111
// Mode returns the current telemetry mode.
1212
//
13-
// The telemetry mode is a global value that controls both the collection and
14-
// uploading of telemetry data. When collection is enabled, telemetry counters
15-
// and stack information are written to the local file system and may be
16-
// inspected with the [gotelemetry] command. When uploading is enabled, this
17-
// anonymous data is periodically uploaded to remote servers.
13+
// The telemetry mode is a global value that controls the
14+
// uploading of telemetry data. Possible mode values are:
15+
// - "on": uploading is enabled
16+
// - "off": uploading is disabled
1817
//
19-
// Possible mode values are:
20-
// - "on": both collection and uploading are enabled
21-
// - "local": telemetry collection is enabled, but uploading is disabled
22-
// - "off": both collection and uploading are disabled
18+
// When mode is "off", local data is still written to the local file system and
19+
// may be inspected with the [gotelemetry] command.
2320
//
2421
// If an error occurs while reading the telemetry mode from the file system,
25-
// Mode returns the default value "local".
22+
// Mode returns the default value "off".
2623
//
2724
// [gotelemetry]: https://pkg.go.dev/golang.org/x/telemetry/cmd/gotelemetry
2825
func Mode() string {

0 commit comments

Comments
 (0)