]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: pull in golang.org/x/telemetry@7d78a97
authorMichael Matloob <matloob@golang.org>
Tue, 14 May 2024 18:48:52 +0000 (14:48 -0400)
committerMichael Matloob <matloob@golang.org>
Tue, 14 May 2024 19:09:33 +0000 (19:09 +0000)
Commands run:
    go get golang.org/x/telemetry@7d78a97
    go mod tidy
    go mod vendor

Change-Id: Iea0fbe11bcc69fac35fba0ee3d02cd14344a3ee9
Reviewed-on: https://go-review.googlesource.com/c/go/+/585455
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/go.mod
src/cmd/go.sum
src/cmd/vendor/golang.org/x/telemetry/internal/counter/file.go
src/cmd/vendor/golang.org/x/telemetry/internal/telemetry/proginfo.go [new file with mode: 0644]
src/cmd/vendor/golang.org/x/telemetry/internal/upload/reports.go
src/cmd/vendor/golang.org/x/telemetry/internal/upload/run.go
src/cmd/vendor/modules.txt

index 77730885146eb0f7caa5b3c81ef0fdb29b21ec92..cb485826767c69b4f48cabe0bbc06bb3cd844285 100644 (file)
@@ -9,7 +9,7 @@ require (
        golang.org/x/mod v0.17.1-0.20240514174713-c0bdc7bd01c9
        golang.org/x/sync v0.7.0
        golang.org/x/sys v0.20.0
-       golang.org/x/telemetry v0.0.0-20240510223629-51e8b5d718eb
+       golang.org/x/telemetry v0.0.0-20240514182607-7d78a974cc44
        golang.org/x/term v0.18.0
        golang.org/x/tools v0.20.1-0.20240429173604-74c9cfe4d22f
 )
index a53cc50859ca80acbf85d2c9121e534b61892c1d..48561550ab660a63f71935a5485eeb0e4652c39f 100644 (file)
@@ -32,8 +32,8 @@ golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
 golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
 golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/telemetry v0.0.0-20240510223629-51e8b5d718eb h1:UTGVF0T+nFaQu6f7USlW8TktAybpMdEjJcF5HyX4dxo=
-golang.org/x/telemetry v0.0.0-20240510223629-51e8b5d718eb/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
+golang.org/x/telemetry v0.0.0-20240514182607-7d78a974cc44 h1:aVJH+bdTb68otvUnahQ3CwIZTrJdYAW/gji9t6wuqcE=
+golang.org/x/telemetry v0.0.0-20240514182607-7d78a974cc44/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
 golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
 golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
 golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
index 43297f9b749b6f790eecc57184aeef89d0c9ba47..a0a1bd4cfb2769f3082ce5f3a190dd735b73ac14 100644 (file)
@@ -14,13 +14,11 @@ import (
        "path/filepath"
        "runtime"
        "runtime/debug"
-       "strings"
        "sync"
        "sync/atomic"
        "time"
        "unsafe"
 
-       "golang.org/x/mod/module"
        "golang.org/x/telemetry/internal/mmap"
        "golang.org/x/telemetry/internal/telemetry"
 )
@@ -135,10 +133,10 @@ func (f *file) init(begin, end time.Time) {
                return
        }
 
-       goVers, progPkgPath, prog, progVers := programInfo(info)
+       goVers, progPath, progVers := telemetry.ProgramInfo(info)
        f.meta = fmt.Sprintf("TimeBegin: %s\nTimeEnd: %s\nProgram: %s\nVersion: %s\nGoVersion: %s\nGOOS: %s\nGOARCH: %s\n\n",
                begin.Format(time.RFC3339), end.Format(time.RFC3339),
-               progPkgPath, progVers, goVers, runtime.GOOS, runtime.GOARCH)
+               progPath, progVers, goVers, runtime.GOOS, runtime.GOARCH)
        if len(f.meta) > maxMetaLen { // should be impossible for our use
                f.err = fmt.Errorf("metadata too long")
                return
@@ -146,28 +144,10 @@ func (f *file) init(begin, end time.Time) {
        if progVers != "" {
                progVers = "@" + progVers
        }
-       prefix := fmt.Sprintf("%s%s-%s-%s-%s-", prog, progVers, goVers, runtime.GOOS, runtime.GOARCH)
+       prefix := fmt.Sprintf("%s%s-%s-%s-%s-", path.Base(progPath), progVers, goVers, runtime.GOOS, runtime.GOARCH)
        f.namePrefix = filepath.Join(dir, prefix)
 }
 
-func programInfo(info *debug.BuildInfo) (goVers, progPkgPath, prog, progVers string) {
-       goVers = info.GoVersion
-       if strings.Contains(goVers, "devel") || strings.Contains(goVers, "-") {
-               goVers = "devel"
-       }
-       progPkgPath = info.Path
-       if progPkgPath == "" {
-               progPkgPath = strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
-       }
-       prog = path.Base(progPkgPath)
-       progVers = info.Main.Version
-       if strings.Contains(progVers, "devel") || module.IsPseudoVersion(progVers) {
-               // we don't want to track pseudo versions, but may want to track prereleases.
-               progVers = "devel"
-       }
-       return goVers, progPkgPath, prog, progVers
-}
-
 // filename returns the name of the file to use for f,
 // given the current time now.
 // It also returns the time when that name will no longer be valid
diff --git a/src/cmd/vendor/golang.org/x/telemetry/internal/telemetry/proginfo.go b/src/cmd/vendor/golang.org/x/telemetry/internal/telemetry/proginfo.go
new file mode 100644 (file)
index 0000000..20be966
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package telemetry
+
+import (
+       "os"
+       "path/filepath"
+       "runtime/debug"
+       "strings"
+
+       "golang.org/x/mod/module"
+)
+
+// IsToolchainProgram reports whether a program with the given path is a Go
+// toolchain program.
+func IsToolchainProgram(progPath string) bool {
+       return strings.HasPrefix(progPath, "cmd/")
+}
+
+// ProgramInfo extracts the go version, program package path, and program
+// version to use for counter files.
+//
+// For programs in the Go toolchain, the program version will be the same as
+// the Go version, and will typically be of the form "go1.2.3", not a semantic
+// version of the form "v1.2.3". Go versions may also include spaces and
+// special characters.
+func ProgramInfo(info *debug.BuildInfo) (goVers, progPath, progVers string) {
+       goVers = info.GoVersion
+       if strings.Contains(goVers, "devel") || strings.Contains(goVers, "-") {
+               goVers = "devel"
+       }
+
+       progPath = info.Path
+       if progPath == "" {
+               progPath = strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
+       }
+
+       // Main module version information is not populated for the cmd module, but
+       // we can re-use the Go version here.
+       if IsToolchainProgram(progPath) {
+               progVers = goVers
+       } else {
+               progVers = info.Main.Version
+               if strings.Contains(progVers, "devel") || module.IsPseudoVersion(progVers) {
+                       // We don't want to track pseudo versions, but may want to track prereleases.
+                       progVers = "devel"
+               }
+       }
+
+       return goVers, progPath, progVers
+}
index bb95971932aa07f653be58b3f4075c335e17262c..a335132602ca0ced908cb4804bdce109df80b555 100644 (file)
@@ -147,6 +147,7 @@ func (u *Uploader) createReport(start time.Time, expiryDate string, countFiles [
        }
        var succeeded bool
        for _, f := range countFiles {
+               fok := false
                x, err := u.parseCountFile(f)
                if err != nil {
                        u.logger.Printf("Unparseable count file %s: %v", filepath.Base(f), err)
@@ -162,12 +163,14 @@ func (u *Uploader) createReport(start time.Time, expiryDate string, countFiles [
                                prog.Counters[k] += int64(v)
                        }
                        succeeded = true
+                       fok = true
+               }
+               if !fok {
+                       u.logger.Printf("no counters found in %s", f)
                }
        }
        if !succeeded {
-               // TODO(rfindley): this isn't right: a count file is not unparseable just
-               // because it has no counters
-               return "", fmt.Errorf("all %d count files for %s were unparseable", len(countFiles), expiryDate)
+               return "", fmt.Errorf("none of the %d count files for %s contained counters", len(countFiles), expiryDate)
        }
        // 1. generate the local report
        localContents, err := json.MarshalIndent(report, "", " ")
index 2fb9fa670a9faad67671b0f8a46d723d0a7636d7..714617a1968a62188c276402b9361bc24549bd30 100644 (file)
@@ -174,9 +174,13 @@ func debugLogFile(debugDir string) (*os.File, error) {
        }
        prog := path.Base(progPkgPath)
        progVers := info.Main.Version
-       fname := filepath.Join(debugDir, fmt.Sprintf("%s-%s-%s-%4d%02d%02d-%d.log",
-               prog, progVers, goVers, year, month, day, os.Getpid()))
-       fname = strings.ReplaceAll(fname, " ", "")
+       if progVers == "(devel)" { // avoid special characters in created file names
+               progVers = "devel"
+       }
+       logBase := strings.ReplaceAll(
+               fmt.Sprintf("%s-%s-%s-%4d%02d%02d-%d.log", prog, progVers, goVers, year, month, day, os.Getpid()),
+               " ", "")
+       fname := filepath.Join(debugDir, logBase)
        if _, err := os.Stat(fname); err == nil {
                // This process previously called upload.Run
                return nil, nil
index 648b89f4d2e3f499f34471a63d79d77bd7855233..17d0ed0fe190a485d0cdf2da3f34440bb230b6e7 100644 (file)
@@ -45,7 +45,7 @@ golang.org/x/sync/semaphore
 golang.org/x/sys/plan9
 golang.org/x/sys/unix
 golang.org/x/sys/windows
-# golang.org/x/telemetry v0.0.0-20240510223629-51e8b5d718eb
+# golang.org/x/telemetry v0.0.0-20240514182607-7d78a974cc44
 ## explicit; go 1.20
 golang.org/x/telemetry
 golang.org/x/telemetry/counter