1
0
mirror of https://github.com/golang/go synced 2024-11-25 07:17:56 -07:00

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 <hyangah@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Michael Matloob 2024-03-11 16:35:45 -04:00
parent 38723f2b38
commit 4f07bb3953
7 changed files with 692 additions and 692 deletions

View File

@ -24,21 +24,21 @@ func TestCounterNamesUpToDate(t *testing.T) {
var counters []string
// -C is a special case because it's handled by handleChdirFlag rather than
// standard flag processing with FlagSets.
// cmd/go/subcommand:unknown is also a special case: it's used when the subcommand
// go/subcommand:unknown is also a special case: it's used when the subcommand
// doesn't match any of the known commands.
counters = append(counters, "cmd/go/flag:C", "cmd/go/subcommand:unknown")
counters = append(counters, flagscounters("cmd/go/flag:", *flag.CommandLine)...)
counters = append(counters, "go/flag:C", "go/subcommand:unknown")
counters = append(counters, flagscounters("go/flag:", *flag.CommandLine)...)
// Add help (without any arguments) as a special case. cmdcounters adds go help <cmd>
// for all subcommands, but it's also valid to invoke go help without any arguments.
counters = append(counters, "cmd/go/subcommand:help")
counters = append(counters, "go/subcommand:help")
for _, cmd := range base.Go.Commands {
counters = append(counters, cmdcounters(nil, cmd)...)
}
counters = append(counters, base.RegisteredCounterNames()...)
for _, c := range counters {
const counterPrefix = "cmd/go"
const counterPrefix = "go/"
if !strings.HasPrefix(c, counterPrefix) {
t.Fatalf("registered counter %q does not start with %q", c, counterPrefix)
}
@ -77,8 +77,8 @@ func flagscounters(prefix string, flagSet flag.FlagSet) []string {
}
func cmdcounters(previous []string, cmd *base.Command) []string {
const subcommandPrefix = "cmd/go/subcommand:"
const flagPrefix = "cmd/go/flag:"
const subcommandPrefix = "go/subcommand:"
const flagPrefix = "go/flag:"
var counters []string
previousComponent := strings.Join(previous, "-")
if len(previousComponent) > 0 {

View File

@ -18,7 +18,7 @@ import (
"cmd/go/internal/base"
)
var counterErrorHelpUnknownTopic = base.NewCounter("cmd/go/error:help-unknown-topic")
var counterErrorsHelpUnknownTopic = base.NewCounter("go/errors:help-unknown-topic")
// Help implements the 'help' command.
func Help(w io.Writer, args []string) {
@ -59,7 +59,7 @@ Args:
if i > 0 {
helpSuccess += " " + strings.Join(args[:i], " ")
}
counterErrorHelpUnknownTopic.Inc()
counterErrorsHelpUnknownTopic.Inc()
fmt.Fprintf(os.Stderr, "go help %s: unknown help topic. Run '%s'.\n", strings.Join(args, " "), helpSuccess)
base.SetExitStatus(2) // failed at 'go help cmd'
base.Exit()

View File

@ -778,7 +778,7 @@ var (
statCacheOnce sync.Once
statCacheErr error
counterErrorGOMODCACHEEntryRelative = base.NewCounter("cmd/go/error:gomodcache-entry-relative")
counterErrorsGOMODCACHEEntryRelative = base.NewCounter("go/errors:gomodcache-entry-relative")
)
// checkCacheDir checks if the directory specified by GOMODCACHE exists. An
@ -790,7 +790,7 @@ func checkCacheDir(ctx context.Context) error {
return fmt.Errorf("module cache not found: neither GOMODCACHE nor GOPATH is set")
}
if !filepath.IsAbs(cfg.GOMODCACHE) {
counterErrorGOMODCACHEEntryRelative.Inc()
counterErrorsGOMODCACHEEntryRelative.Inc()
return fmt.Errorf("GOMODCACHE entry is relative; must be absolute path: %q.\n", cfg.GOMODCACHE)
}

View File

@ -81,7 +81,7 @@ func FilterEnv(env []string) []string {
return out
}
var counterErrorInvalidToolchainInFile = base.NewCounter("cmd/go/error:invalid-toolchain-in-file")
var counterErrorsInvalidToolchainInFile = base.NewCounter("go/errors:invalid-toolchain-in-file")
// Select invokes a different Go toolchain if directed by
// the GOTOOLCHAIN environment variable or the user's configuration
@ -176,7 +176,7 @@ func Select() {
// has a suffix like "go1.21.1-foo" and toolchain is "go1.21.1".)
toolVers := gover.FromToolchain(toolchain)
if toolVers == "" || (!strings.HasPrefix(toolchain, "go") && !strings.Contains(toolchain, "-go")) {
counterErrorInvalidToolchainInFile.Inc()
counterErrorsInvalidToolchainInFile.Inc()
base.Fatalf("invalid toolchain %q in %s", toolchain, base.ShortPath(file))
}
if gover.Compare(toolVers, minVers) > 0 {
@ -237,7 +237,7 @@ func Select() {
Exec(gotoolchain)
}
var counterSelectExec = base.NewCounter("cmd/go/select-exec")
var counterSelectExec = base.NewCounter("go/toolchain/select-exec")
// TestVersionSwitch is set in the test go binary to the value in $TESTGO_VERSION_SWITCH.
// Valid settings are:

View File

@ -103,7 +103,7 @@ func (s *Switcher) Switch(ctx context.Context) {
panic("unreachable")
}
var counterSwitchExec = base.NewCounter("cmd/go/switch-exec")
var counterSwitchExec = base.NewCounter("go/toolchain/switch-exec")
// SwitchOrFatal attempts a toolchain switch based on the information in err
// and otherwise falls back to base.Fatal(err).

View File

@ -90,7 +90,7 @@ func init() {
var _ = go11tag
var counterErrorGOPATHEntryRelative = base.NewCounter("cmd/go/error:gopath-entry-relative")
var counterErrorsGOPATHEntryRelative = base.NewCounter("go/errors:gopath-entry-relative")
func main() {
log.SetFlags(0)
@ -100,7 +100,7 @@ func main() {
flag.Usage = base.Usage
flag.Parse()
counter.CountFlags("cmd/go/flag:", *flag.CommandLine)
counter.CountFlags("go/flag:", *flag.CommandLine)
args := flag.Args()
if len(args) < 1 {
@ -109,7 +109,7 @@ func main() {
cfg.CmdName = args[0] // for error messages
if args[0] == "help" {
counter.Inc("cmd/go/subcommand:" + strings.Join(append([]string{"help"}, args[1:]...), "-"))
counter.Inc("go/subcommand:" + strings.Join(append([]string{"help"}, args[1:]...), "-"))
help.Help(os.Stdout, args[1:])
return
}
@ -148,7 +148,7 @@ func main() {
// Instead of dying, uninfer it.
cfg.BuildContext.GOPATH = ""
} else {
counterErrorGOPATHEntryRelative.Inc()
counterErrorsGOPATHEntryRelative.Inc()
fmt.Fprintf(os.Stderr, "go: GOPATH entry is relative; must be absolute path: %q.\nFor more details see: 'go help gopath'\n", p)
os.Exit(2)
}
@ -166,7 +166,7 @@ func main() {
}
if args[used] == "help" {
// Accept 'go mod help' and 'go mod help foo' for 'go help mod' and 'go help mod foo'.
counter.Inc("cmd/go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "-" + strings.Join(args[used:], "-"))
counter.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-") + "-" + strings.Join(args[used:], "-"))
help.Help(os.Stdout, append(slices.Clip(args[:used]), args[used+1:]...))
base.Exit()
}
@ -178,12 +178,12 @@ func main() {
if cmdName == "" {
cmdName = args[0]
}
counter.Inc("cmd/go/subcommand:unknown")
counter.Inc("go/subcommand:unknown")
fmt.Fprintf(os.Stderr, "go %s: unknown command\nRun 'go help%s' for usage.\n", cmdName, helpArg)
base.SetExitStatus(2)
base.Exit()
}
counter.Inc("cmd/go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-"))
counter.Inc("go/subcommand:" + strings.ReplaceAll(cfg.CmdName, " ", "-"))
invoke(cmd, args[used-1:])
base.Exit()
}
@ -248,7 +248,7 @@ func invoke(cmd *base.Command, args []string) {
} else {
base.SetFromGOFLAGS(&cmd.Flag)
cmd.Flag.Parse(args[1:])
counter.CountFlags("cmd/go/flag:"+strings.ReplaceAll(cfg.CmdName, " ", "-")+"-", cmd.Flag)
counter.CountFlags("go/flag:"+strings.ReplaceAll(cfg.CmdName, " ", "-")+"-", cmd.Flag)
args = cmd.Flag.Args()
}
@ -333,7 +333,7 @@ func handleChdirFlag() {
_, dir, _ = strings.Cut(a, "=")
os.Args = slices.Delete(os.Args, used, used+1)
}
counter.Inc("cmd/go/flag:C")
counter.Inc("go/flag:C")
if err := os.Chdir(dir); err != nil {
base.Fatalf("go: %v", err)

File diff suppressed because it is too large Load Diff