From 59c3c091390c3d5563be7d9e264e9a54f6924e73 Mon Sep 17 00:00:00 2001 From: Juan Manuel Perez Date: Tue, 14 Nov 2023 17:14:48 +0100 Subject: [PATCH] do not abort if we do not know which user is running the process Signed-off-by: Juan Manuel Perez --- exporter.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/exporter.go b/exporter.go index 3f050c412..1119fb62a 100644 --- a/exporter.go +++ b/exporter.go @@ -154,16 +154,14 @@ func main() { os.Exit(1) } - u, err := user.Current() - if err != nil { - _ = level.Error(logger).Log("err", err) - os.Exit(1) - } - - _ = level.Info(logger).Log("msg", fmt.Sprintf("Running as %v", u.Username)) + if u, err := user.Current(); err != nil { + _ = level.Warn(logger).Log("msg", "Unable to determine which user is running this exporter. More info: https://github.com/golang/go/issues/37348") + } else { + _ = level.Info(logger).Log("msg", fmt.Sprintf("Running as %v", u.Username)) - if strings.Contains(u.Username, "ContainerAdministrator") || strings.Contains(u.Username, "ContainerUser") { - _ = level.Warn(logger).Log("msg", "Running as a preconfigured Windows Container user. This may mean you do not have Windows HostProcess containers configured correctly and some functionality will not work as expected.") + if strings.Contains(u.Username, "ContainerAdministrator") || strings.Contains(u.Username, "ContainerUser") { + _ = level.Warn(logger).Log("msg", "Running as a preconfigured Windows Container user. This may mean you do not have Windows HostProcess containers configured correctly and some functionality will not work as expected.") + } } _ = level.Info(logger).Log("msg", fmt.Sprintf("Enabled collectors: %v", strings.Join(enabledCollectorList, ", ")))