fix: osinfos incomplete in case of warnings (#11505)

The function used for getting host information
(host.SensorsTemperaturesWithContext) returns warnings in some cases.

Returning with error in such cases means we miss out on the other useful
information already fetched (os info).

If the OS info has been succesfully fetched, it should always be
included in the output irrespective of whether the other data (CPU
sensors, users) could be fetched or not.
This commit is contained in:
Shireesh Anjal 2021-02-13 07:27:57 +05:30 committed by GitHub
parent 93fd248b52
commit 928de04f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,10 @@ func getLocalOsInfo(ctx context.Context, r *http.Request) madmin.ServerOsInfo {
addr = GetLocalPeer(globalEndpoints)
}
info, err := host.InfoWithContext(ctx)
srvrOsInfo := madmin.ServerOsInfo{Addr: addr}
var err error
srvrOsInfo.Info, err = host.InfoWithContext(ctx)
if err != nil {
return madmin.ServerOsInfo{
Addr: addr,
@ -45,23 +48,18 @@ func getLocalOsInfo(ctx context.Context, r *http.Request) madmin.ServerOsInfo {
}
}
sensors, err := host.SensorsTemperaturesWithContext(ctx)
srvrOsInfo.Sensors, err = host.SensorsTemperaturesWithContext(ctx)
if err != nil {
return madmin.ServerOsInfo{
Addr: addr,
Error: fmt.Sprintf("sensors-temp: %v", err),
// Set error only when it's not of WARNINGS type
if _, isWarning := err.(*host.Warnings); !isWarning {
srvrOsInfo.Error = fmt.Sprintf("sensors-temp: %v", err)
}
}
// ignore user err, as it cannot be obtained reliably inside containers
users, _ := host.UsersWithContext(ctx)
srvrOsInfo.Users, _ = host.UsersWithContext(ctx)
return madmin.ServerOsInfo{
Addr: addr,
Info: info,
Sensors: sensors,
Users: users,
}
return srvrOsInfo
}
func getLocalDiskHwInfo(ctx context.Context, r *http.Request) madmin.ServerDiskHwInfo {