Skip to content

Commit 4f07bb3

Browse files
committed
cmd/go: change some counter names
Primarily, this change removes the cmd/ prefix on the go command counter names. The 'error' counter is changed to 'errors' reflecting that it's a bucket that contains multiple errors. the switch-exec and select-exec counters are moved into a 'toolchain' grouping. For #58894 Change-Id: Id6e0e7a0b4a5e42a0aef04b1210d2bb5256eb6c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/570736 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 38723f2 commit 4f07bb3

File tree

7 files changed

+692
-692
lines changed

7 files changed

+692
-692
lines changed

src/cmd/go/counters_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ func TestCounterNamesUpToDate(t *testing.T) {
2424
var counters []string
2525
// -C is a special case because it's handled by handleChdirFlag rather than
2626
// standard flag processing with FlagSets.
27-
// cmd/go/subcommand:unknown is also a special case: it's used when the subcommand
27+
// go/subcommand:unknown is also a special case: it's used when the subcommand
2828
// doesn't match any of the known commands.
29-
counters = append(counters, "cmd/go/flag:C", "cmd/go/subcommand:unknown")
30-
counters = append(counters, flagscounters("cmd/go/flag:", *flag.CommandLine)...)
29+
counters = append(counters, "go/flag:C", "go/subcommand:unknown")
30+
counters = append(counters, flagscounters("go/flag:", *flag.CommandLine)...)
3131

3232
// Add help (without any arguments) as a special case. cmdcounters adds go help <cmd>
3333
// for all subcommands, but it's also valid to invoke go help without any arguments.
34-
counters = append(counters, "cmd/go/subcommand:help")
34+
counters = append(counters, "go/subcommand:help")
3535
for _, cmd := range base.Go.Commands {
3636
counters = append(counters, cmdcounters(nil, cmd)...)
3737
}
3838

3939
counters = append(counters, base.RegisteredCounterNames()...)
4040
for _, c := range counters {
41-
const counterPrefix = "cmd/go"
41+
const counterPrefix = "go/"
4242
if !strings.HasPrefix(c, counterPrefix) {
4343
t.Fatalf("registered counter %q does not start with %q", c, counterPrefix)
4444
}
@@ -77,8 +77,8 @@ func flagscounters(prefix string, flagSet flag.FlagSet) []string {
7777
}
7878

7979
func cmdcounters(previous []string, cmd *base.Command) []string {
80-
const subcommandPrefix = "cmd/go/subcommand:"
81-
const flagPrefix = "cmd/go/flag:"
80+
const subcommandPrefix = "go/subcommand:"
81+
const flagPrefix = "go/flag:"
8282
var counters []string
8383
previousComponent := strings.Join(previous, "-")
8484
if len(previousComponent) > 0 {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"cmd/go/internal/base"
1919
)
2020

21-
var counterErrorHelpUnknownTopic = base.NewCounter("cmd/go/error:help-unknown-topic")
21+
var counterErrorsHelpUnknownTopic = base.NewCounter("go/errors:help-unknown-topic")
2222

2323
// Help implements the 'help' command.
2424
func Help(w io.Writer, args []string) {
@@ -59,7 +59,7 @@ Args:
5959
if i > 0 {
6060
helpSuccess += " " + strings.Join(args[:i], " ")
6161
}
62-
counterErrorHelpUnknownTopic.Inc()
62+
counterErrorsHelpUnknownTopic.Inc()
6363
fmt.Fprintf(os.Stderr, "go help %s: unknown help topic. Run '%s'.\n", strings.Join(args, " "), helpSuccess)
6464
base.SetExitStatus(2) // failed at 'go help cmd'
6565
base.Exit()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ var (
778778
statCacheOnce sync.Once
779779
statCacheErr error
780780

781-
counterErrorGOMODCACHEEntryRelative = base.NewCounter("cmd/go/error:gomodcache-entry-relative")
781+
counterErrorsGOMODCACHEEntryRelative = base.NewCounter("go/errors:gomodcache-entry-relative")
782782
)
783783

784784
// checkCacheDir checks if the directory specified by GOMODCACHE exists. An
@@ -790,7 +790,7 @@ func checkCacheDir(ctx context.Context) error {
790790
return fmt.Errorf("module cache not found: neither GOMODCACHE nor GOPATH is set")
791791
}
792792
if !filepath.IsAbs(cfg.GOMODCACHE) {
793-
counterErrorGOMODCACHEEntryRelative.Inc()
793+
counterErrorsGOMODCACHEEntryRelative.Inc()
794794
return fmt.Errorf("GOMODCACHE entry is relative; must be absolute path: %q.\n", cfg.GOMODCACHE)
795795
}
796796

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func FilterEnv(env []string) []string {
8181
return out
8282
}
8383

84-
var counterErrorInvalidToolchainInFile = base.NewCounter("cmd/go/error:invalid-toolchain-in-file")
84+
var counterErrorsInvalidToolchainInFile = base.NewCounter("go/errors:invalid-toolchain-in-file")
8585

8686
// Select invokes a different Go toolchain if directed by
8787
// the GOTOOLCHAIN environment variable or the user's configuration
@@ -176,7 +176,7 @@ func Select() {
176176
// has a suffix like "go1.21.1-foo" and toolchain is "go1.21.1".)
177177
toolVers := gover.FromToolchain(toolchain)
178178
if toolVers == "" || (!strings.HasPrefix(toolchain, "go") && !strings.Contains(toolchain, "-go")) {
179-
counterErrorInvalidToolchainInFile.Inc()
179+
counterErrorsInvalidToolchainInFile.Inc()
180180
base.Fatalf("invalid toolchain %q in %s", toolchain, base.ShortPath(file))
181181
}
182182
if gover.Compare(toolVers, minVers) > 0 {
@@ -237,7 +237,7 @@ func Select() {
237237
Exec(gotoolchain)
238238
}
239239

240-
var counterSelectExec = base.NewCounter("cmd/go/select-exec")
240+
var counterSelectExec = base.NewCounter("go/toolchain/select-exec")
241241

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (s *Switcher) Switch(ctx context.Context) {
103103
panic("unreachable")
104104
}
105105

106-
var counterSwitchExec = base.NewCounter("cmd/go/switch-exec")
106+
var counterSwitchExec = base.NewCounter("go/toolchain/switch-exec")
107107

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

src/cmd/go/main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func init() {
9090

9191
var _ = go11tag
9292

93-
var counterErrorGOPATHEntryRelative = base.NewCounter("cmd/go/error:gopath-entry-relative")
93+
var counterErrorsGOPATHEntryRelative = base.NewCounter("go/errors:gopath-entry-relative")
9494

9595
func main() {
9696
log.SetFlags(0)
@@ -100,7 +100,7 @@ func main() {
100100

101101
flag.Usage = base.Usage
102102
flag.Parse()
103-
counter.CountFlags("cmd/go/flag:", *flag.CommandLine)
103+
counter.CountFlags("go/flag:", *flag.CommandLine)
104104

105105
args := flag.Args()
106106
if len(args) < 1 {
@@ -109,7 +109,7 @@ func main() {
109109

110110
cfg.CmdName = args[0] // for error messages
111111
if args[0] == "help" {
112-
counter.Inc("cmd/go/subcommand:" + strings.Join(append([]string{"help"}, args[1:]...), "-"))
112+
counter.Inc("go/subcommand:" + strings.Join(append([]string{"help"}, args[1:]...), "-"))
113113
help.Help(os.Stdout, args[1:])
114114
return
115115
}
@@ -148,7 +148,7 @@ func main() {
148148
// Instead of dying, uninfer it.
149149
cfg.BuildContext.GOPATH = ""
150150
} else {
151-
counterErrorGOPATHEntryRelative.Inc()
151+
counterErrorsGOPATHEntryRelative.Inc()
152152
fmt.Fprintf(os.Stderr, "go: GOPATH entry is relative; must be absolute path: %q.\nFor more details see: 'go help gopath'\n", p)
153153
os.Exit(2)
154154
}
@@ -166,7 +166,7 @@ func main() {
166166
}
167167
if args[used] == "help" {
168168
// Accept 'go mod help' and 'go mod help foo' for 'go help mod' and 'go help mod foo'.
169-
counter.Inc("cmd/go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "-" + strings.Join(args[used:], "-"))
169+
counter.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "-" + strings.Join(args[used:], "-"))
170170
help.Help(os.Stdout, append(slices.Clip(args[:used]), args[used+1:]...))
171171
base.Exit()
172172
}
@@ -178,12 +178,12 @@ func main() {
178178
if cmdName == "" {
179179
cmdName = args[0]
180180
}
181-
counter.Inc("cmd/go/subcommand:unknown")
181+
counter.Inc("go/subcommand:unknown")
182182
fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cmdName, helpArg)
183183
base.SetExitStatus(2)
184184
base.Exit()
185185
}
186-
counter.Inc("cmd/go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-"))
186+
counter.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-"))
187187
invoke(cmd, args[used-1:])
188188
base.Exit()
189189
}
@@ -248,7 +248,7 @@ func invoke(cmd *base.Command, args []string) {
248248
} else {
249249
base.SetFromGOFLAGS(&cmd.Flag)
250250
cmd.Flag.Parse(args[1:])
251-
counter.CountFlags("cmd/go/flag:"+strings.ReplaceAll(cfg.CmdName, " ", "-")+"-", cmd.Flag)
251+
counter.CountFlags("go/flag:"+strings.ReplaceAll(cfg.CmdName, " ", "-")+"-", cmd.Flag)
252252
args = cmd.Flag.Args()
253253
}
254254

@@ -333,7 +333,7 @@ func handleChdirFlag() {
333333
_, dir, _ = strings.Cut(a, "=")
334334
os.Args = slices.Delete(os.Args, used, used+1)
335335
}
336-
counter.Inc("cmd/go/flag:C")
336+
counter.Inc("go/flag:C")
337337

338338
if err := os.Chdir(dir); err != nil {
339339
base.Fatalf("go: %v", err)

0 commit comments

Comments
 (0)