Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
fix: return default values for fields that were removed (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgimalac authored May 2, 2023
1 parent 31ec518 commit a44cf5f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
26 changes: 20 additions & 6 deletions cpu/cpu_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,25 @@ func getSystemInfo() (si SYSTEM_INFO) {
}

// GetCpuInfo returns map of interesting bits of information about the CPU
func GetCpuInfo() (cpuInfo map[string]string, err error) {
cpuInfo = make(map[string]string)
func GetCpuInfo() (map[string]string, error) {
// Initialize cpuInfo with all fields to avoid missing a field which
// could be expected by the backend or by users
// TODO: make sure that the backend actually works with any subset of fields
cpuInfo := map[string]string{
"mhz": "0",
"model_name": "",
"vendor_id": "",
"family": "",
"cpu_pkgs": "0",
"cpu_numa_nodes": "0",
"cpu_cores": "0",
"cpu_logical_processors": "0",
"cache_size_l1": "0",
"cache_size_l2": "0",
"cache_size_l3": "0",
"model": "0",
"stepping": "0",
}

k, err := registry.OpenKey(registry.LOCAL_MACHINE,
registryHive,
Expand Down Expand Up @@ -266,10 +283,7 @@ func GetCpuInfo() (cpuInfo map[string]string, err error) {
cpuInfo["model"] = strconv.Itoa(int((si.wProcessorRevision >> 8) & 0xFF))
cpuInfo["stepping"] = strconv.Itoa(int(si.wProcessorRevision & 0xFF))

// cpuInfo cannot be empty
err = nil

return
return cpuInfo, nil
}

func extract(caption, field string) string {
Expand Down
19 changes: 13 additions & 6 deletions platform/platform_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,18 @@ func getNativeArchInfo() string {
}

// GetArchInfo returns basic host architecture information
func GetArchInfo() (systemInfo map[string]string, err error) {
systemInfo = map[string]string{}
func GetArchInfo() (map[string]string, error) {
// Initialize systemInfo with all fields to avoid missing a field which
// could be expected by the backend or by users
// TODO: make sure that the backend actually works with any subset of fields
systemInfo := map[string]string{
"hostname": "",
"machine": "",
"os": "",
"kernel_release": "0.0.0",
"kernel_name": "",
"family": "",
}

hostname, err := os.Hostname()
if err == nil {
Expand Down Expand Up @@ -343,8 +353,5 @@ func GetArchInfo() (systemInfo map[string]string, err error) {
}
systemInfo["family"] = family

// systemInfo is never empty so we never return an error
err = nil

return
return systemInfo, nil
}

0 comments on commit a44cf5f

Please sign in to comment.