Skip to content

Commit 23f760f

Browse files
committed
cmd/go: remove checks that all counters incremented are in counters.txt
This change removes cmd/go/testdata/counters.txt. It also removes the code that prepares it and checks that it contains all registered counters as well as counters for all flags and subcommands. It removes the counter registration mechanism, and uses telemetry.NewCounter to create new counters instead. It keeps the tests that check that at least one counter is incremented if the go command is invoked in a script test. Change-Id: Ic6bda5c64e90f0dd7e221968fce0e375e84d6e17 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/582715 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
1 parent 7b5206b commit 23f760f

File tree

9 files changed

+11
-884
lines changed

9 files changed

+11
-884
lines changed

src/cmd/go/counters_test.go

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/cmd/go/internal/base/base.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
package base
88

99
import (
10-
"cmd/internal/telemetry"
1110
"context"
1211
"flag"
1312
"fmt"
1413
"log"
1514
"os"
1615
"os/exec"
1716
"reflect"
18-
"sort"
1917
"strings"
2018
"sync"
2119

@@ -223,28 +221,3 @@ func RunStdin(cmdline []string) {
223221
// Usage is the usage-reporting function, filled in by package main
224222
// but here for reference by other packages.
225223
var Usage func()
226-
227-
var counterNames = map[string]bool{}
228-
229-
type Counter interface {
230-
Inc()
231-
}
232-
233-
// NewCounter registers a new counter. It must be called from an init function
234-
// or global variable initializer.
235-
func NewCounter(name string) Counter {
236-
if counterNames[name] {
237-
panic(fmt.Errorf("counter %q initialized twice", name))
238-
}
239-
counterNames[name] = true
240-
return telemetry.NewCounter(name)
241-
}
242-
243-
func RegisteredCounterNames() []string {
244-
var names []string
245-
for name := range counterNames {
246-
names = append(names, name)
247-
}
248-
sort.Strings(names)
249-
return names
250-
}

src/cmd/go/internal/help/help.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import (
1616
"unicode/utf8"
1717

1818
"cmd/go/internal/base"
19+
"cmd/internal/telemetry"
1920
)
2021

21-
var counterErrorsHelpUnknownTopic = base.NewCounter("go/errors:help-unknown-topic")
22+
var counterErrorsHelpUnknownTopic = telemetry.NewCounter("go/errors:help-unknown-topic")
2223

2324
// Help implements the 'help' command.
2425
func Help(w io.Writer, args []string) {

src/cmd/go/internal/modfetch/cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"cmd/go/internal/modfetch/codehost"
2727
"cmd/go/internal/par"
2828
"cmd/go/internal/robustio"
29+
"cmd/internal/telemetry"
2930

3031
"golang.org/x/mod/module"
3132
"golang.org/x/mod/semver"
@@ -778,7 +779,7 @@ var (
778779
statCacheOnce sync.Once
779780
statCacheErr error
780781

781-
counterErrorsGOMODCACHEEntryRelative = base.NewCounter("go/errors:gomodcache-entry-relative")
782+
counterErrorsGOMODCACHEEntryRelative = telemetry.NewCounter("go/errors:gomodcache-entry-relative")
782783
)
783784

784785
// checkCacheDir checks if the directory specified by GOMODCACHE exists. An

src/cmd/go/internal/toolchain/select.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"cmd/go/internal/modload"
2727
"cmd/go/internal/run"
2828
"cmd/go/internal/work"
29+
"cmd/internal/telemetry"
2930

3031
"golang.org/x/mod/module"
3132
)
@@ -81,7 +82,7 @@ func FilterEnv(env []string) []string {
8182
return out
8283
}
8384

84-
var counterErrorsInvalidToolchainInFile = base.NewCounter("go/errors:invalid-toolchain-in-file")
85+
var counterErrorsInvalidToolchainInFile = telemetry.NewCounter("go/errors:invalid-toolchain-in-file")
8586

8687
// Select invokes a different Go toolchain if directed by
8788
// the GOTOOLCHAIN environment variable or the user's configuration
@@ -245,7 +246,7 @@ func Select() {
245246
Exec(gotoolchain)
246247
}
247248

248-
var counterSelectExec = base.NewCounter("go/toolchain/select-exec")
249+
var counterSelectExec = telemetry.NewCounter("go/toolchain/select-exec")
249250

250251
// TestVersionSwitch is set in the test go binary to the value in $TESTGO_VERSION_SWITCH.
251252
// Valid settings are:

src/cmd/go/internal/toolchain/switch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"cmd/go/internal/cfg"
1717
"cmd/go/internal/gover"
1818
"cmd/go/internal/modfetch"
19+
"cmd/internal/telemetry"
1920
)
2021

2122
// A Switcher collects errors to be reported and then decides
@@ -103,7 +104,7 @@ func (s *Switcher) Switch(ctx context.Context) {
103104
panic("unreachable")
104105
}
105106

106-
var counterSwitchExec = base.NewCounter("go/toolchain/switch-exec")
107+
var counterSwitchExec = telemetry.NewCounter("go/toolchain/switch-exec")
107108

108109
// SwitchOrFatal attempts a toolchain switch based on the information in err
109110
// and otherwise falls back to base.Fatal(err).

src/cmd/go/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
// license that can be found in the LICENSE file.
44

55
//go:generate go test cmd/go -v -run=^TestDocsUpToDate$ -fixdocs
6-
//go:generate go test cmd/go -v -run=^TestCounterNamesUpToDate$ -update
76

87
package main
98

109
import (
11-
"cmd/internal/telemetry"
1210
"context"
1311
"flag"
1412
"fmt"
@@ -44,6 +42,7 @@ import (
4442
"cmd/go/internal/vet"
4543
"cmd/go/internal/work"
4644
"cmd/go/internal/workcmd"
45+
"cmd/internal/telemetry"
4746
)
4847

4948
func init() {
@@ -89,7 +88,7 @@ func init() {
8988

9089
var _ = go11tag
9190

92-
var counterErrorsGOPATHEntryRelative = base.NewCounter("go/errors:gopath-entry-relative")
91+
var counterErrorsGOPATHEntryRelative = telemetry.NewCounter("go/errors:gopath-entry-relative")
9392

9493
func main() {
9594
log.SetFlags(0)

src/cmd/go/script_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"path/filepath"
2323
"runtime"
2424
"strings"
25-
"sync"
2625
"testing"
2726
"time"
2827

@@ -395,32 +394,13 @@ func readCounters(t *testing.T, telemetryDir string) map[string]uint64 {
395394
return totals
396395
}
397396

398-
//go:embed testdata/counters.txt
399-
var countersTxt string
400-
401-
var (
402-
allowedCountersOnce sync.Once
403-
allowedCounters = map[string]bool{} // Set of allowed counters.
404-
)
405-
406397
func checkCounters(t *testing.T, telemetryDir string) {
407-
allowedCountersOnce.Do(func() {
408-
for _, counter := range strings.Fields(countersTxt) {
409-
allowedCounters[counter] = true
410-
}
411-
})
412398
counters := readCounters(t, telemetryDir)
413399
if _, ok := scriptGoInvoked.Load(testing.TB(t)); ok {
414400
if !disabledOnPlatform && len(counters) == 0 {
415401
t.Fatal("go was invoked but no counters were incremented")
416402
}
417403
}
418-
for name := range counters {
419-
if !allowedCounters[name] {
420-
t.Fatalf("incremented counter %q is not in testdata/counters.txt. "+
421-
"Please update counters_test.go to produce an entry for it.", name)
422-
}
423-
}
424404
}
425405

426406
// Copied from https://go.googlesource.com/telemetry/+/5f08a0cbff3f/internal/telemetry/mode.go#122

0 commit comments

Comments
 (0)