cmd/go: use local state for telemetry

This change adds a new loader state to satisfy the requirements for
the (currently unused) telemetry stats for the go command.

This commit is part of the overall effort to eliminate global
modloader state.

Change-Id: I6d4e38c91e5413d7649dfc6301e3ba35ee36c9b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/711136
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Ian Alexander 2025-10-10 08:52:30 -04:00
parent 8239156571
commit 139f89226f

View file

@ -22,9 +22,12 @@ func Increment() {
// incrementConfig increments counters for the configuration // incrementConfig increments counters for the configuration
// the command is running in. // the command is running in.
func incrementConfig() { func incrementConfig() {
if !modload.WillBeEnabled(modload.LoaderState) { // TODO(jitsu): Telemetry for the go/mode counters should eventually be
// moved to modload.Init()
s := modload.NewState()
if !modload.WillBeEnabled(s) {
counter.Inc("go/mode:gopath") counter.Inc("go/mode:gopath")
} else if workfile := modload.FindGoWork(modload.LoaderState, base.Cwd()); workfile != "" { } else if workfile := modload.FindGoWork(s, base.Cwd()); workfile != "" {
counter.Inc("go/mode:workspace") counter.Inc("go/mode:workspace")
} else { } else {
counter.Inc("go/mode:module") counter.Inc("go/mode:module")