From 928de04f7a68df9aae55bc0941a03d1a5ec4e82d Mon Sep 17 00:00:00 2001 From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com> Date: Sat, 13 Feb 2021 07:27:57 +0530 Subject: [PATCH] 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. --- cmd/healthinfo_linux.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/cmd/healthinfo_linux.go b/cmd/healthinfo_linux.go index 8db9de5e6..1871591b2 100644 --- a/cmd/healthinfo_linux.go +++ b/cmd/healthinfo_linux.go @@ -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 {