Add CPU info in the check update user-agent (#16447)

This commit is contained in:
Anis Elleuch 2023-01-23 17:07:55 +01:00 committed by GitHub
parent 31b0decd46
commit f37a5b6dae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -41,6 +41,7 @@ import (
"github.com/minio/pkg/env"
xnet "github.com/minio/pkg/net"
"github.com/minio/selfupdate"
gopsutilcpu "github.com/shirou/gopsutil/v3/cpu"
)
const (
@ -277,6 +278,18 @@ func getUserAgent(mode string) string {
}
}
if cpus, err := gopsutilcpu.Info(); err == nil && len(cpus) > 0 {
cpuMap := make(map[string]struct{}, len(cpus))
coreMap := make(map[string]struct{}, len(cpus))
for i := range cpus {
cpuMap[cpus[i].PhysicalID] = struct{}{}
coreMap[cpus[i].CoreID] = struct{}{}
}
cpu := cpus[0]
uaAppend(" CPU ", fmt.Sprintf("(total_cpus:%d, total_cores:%d; vendor:%s; family:%s; model:%s; stepping:%d; model_name:%s)",
len(cpuMap), len(coreMap), cpu.VendorID, cpu.Family, cpu.Model, cpu.Stepping, cpu.ModelName))
}
return strings.Join(userAgentParts, "")
}

View File

@ -179,7 +179,7 @@ func TestUserAgent(t *testing.T) {
if IsDocker() {
expectedStr = strings.ReplaceAll(expectedStr, "; source", "; docker; source")
}
if str != expectedStr {
if !strings.Contains(str, expectedStr) {
t.Errorf("Test %d: expected: %s, got: %s", i+1, expectedStr, str)
}
globalIsCICD = sci