From 8a6fb66e899b70b6fa80ad5ebca57c7db356e82f Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Wed, 6 Nov 2024 05:42:00 -0800 Subject: [PATCH] ignore status update errors --- cmd/config/config.go | 17 +++--------- cmd/metrics/metrics.go | 56 ++++++++++----------------------------- internal/common/common.go | 20 ++++---------- 3 files changed, 22 insertions(+), 71 deletions(-) diff --git a/cmd/config/config.go b/cmd/config/config.go index b9baeb9..48eb5c0 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -322,27 +322,16 @@ func printConfig(myTargets []target.Target, localTempDir string) (err error) { return } multiSpinner.Start() - err = multiSpinner.Status(myTarget.GetName(), "collecting data") - if err != nil { - err = fmt.Errorf("failed to set spinner status: %v", err) - return - } + _ = multiSpinner.Status(myTarget.GetName(), "collecting data") // run the scripts var scriptOutputs map[string]script.ScriptOutput if scriptOutputs, err = script.RunScripts(myTarget, scriptsToRun, true, localTempDir); err != nil { err = fmt.Errorf("failed to run collection scripts: %v", err) - errSpinner := multiSpinner.Status(myTarget.GetName(), "error collecting data") - if errSpinner != nil { - slog.Error(errSpinner.Error()) - } + _ = multiSpinner.Status(myTarget.GetName(), "error collecting data") multiSpinner.Finish() return } - err = multiSpinner.Status(myTarget.GetName(), "collection complete") - if err != nil { - err = fmt.Errorf("failed to set spinner status: %v", err) - return - } + _ = multiSpinner.Status(myTarget.GetName(), "collection complete") multiSpinner.Finish() // process the tables, i.e., get field values from raw script output tableNames := []string{report.ConfigurationTableName} diff --git a/cmd/metrics/metrics.go b/cmd/metrics/metrics.go index fcfef29..917644a 100644 --- a/cmd/metrics/metrics.go +++ b/cmd/metrics/metrics.go @@ -758,13 +758,9 @@ func prepareTarget(targetContext *targetContext, targetTempRoot string, localTem myTarget := targetContext.target var err error // create a temporary directory on the target - if err = statusUpdate(myTarget.GetName(), "configuring target"); err != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", err.Error())) - } + _ = statusUpdate(myTarget.GetName(), "configuring target") if targetContext.tempDir, err = myTarget.CreateTempDirectory(targetTempRoot); err != nil { - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %v", err)); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %v", err)) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -774,9 +770,7 @@ func prepareTarget(targetContext *targetContext, targetTempRoot string, localTem var nmiWatchdogEnabled bool if nmiWatchdogEnabled, err = NMIWatchdogEnabled(myTarget); err != nil { err = fmt.Errorf("failed to retrieve NMI watchdog status: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -784,9 +778,7 @@ func prepareTarget(targetContext *targetContext, targetTempRoot string, localTem if nmiWatchdogEnabled { if err = DisableNMIWatchdog(myTarget, localTempDir); err != nil { err = fmt.Errorf("failed to disable NMI watchdog: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -798,18 +790,14 @@ func prepareTarget(targetContext *targetContext, targetTempRoot string, localTem if !flagNoRoot { if targetContext.perfMuxIntervals, err = GetMuxIntervals(myTarget, localTempDir); err != nil { err = fmt.Errorf("failed to get perf mux intervals: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return } if err = SetAllMuxIntervals(myTarget, flagPerfMuxInterval, localTempDir); err != nil { err = fmt.Errorf("failed to set all perf mux intervals: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -818,9 +806,7 @@ func prepareTarget(targetContext *targetContext, targetTempRoot string, localTem // get the full path to the perf binary if targetContext.perfPath, err = getPerfPath(myTarget, localPerfPath); err != nil { err = fmt.Errorf("failed to find perf: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %v", err)); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %v", err)) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -836,15 +822,11 @@ func prepareMetrics(targetContext *targetContext, localTempDir string, channelEr return } // load metadata - if statusUpdateErr := statusUpdate(myTarget.GetName(), "collecting metadata"); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), "collecting metadata") var err error if targetContext.metadata, err = LoadMetadata(myTarget, flagNoRoot, targetContext.perfPath, localTempDir); err != nil { err = fmt.Errorf("failed to load metadata: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -854,9 +836,7 @@ func prepareMetrics(targetContext *targetContext, localTempDir string, channelEr var uncollectableEvents []string if targetContext.groupDefinitions, uncollectableEvents, err = LoadEventGroups(flagEventFilePath, targetContext.metadata); err != nil { err = fmt.Errorf("failed to load event definitions: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -864,9 +844,7 @@ func prepareMetrics(targetContext *targetContext, localTempDir string, channelEr // load metric definitions if targetContext.metricDefinitions, err = LoadMetricDefinitions(flagMetricFilePath, flagMetricsList, uncollectableEvents, targetContext.metadata); err != nil { err = fmt.Errorf("failed to load metric definitions: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -874,9 +852,7 @@ func prepareMetrics(targetContext *targetContext, localTempDir string, channelEr // configure metrics if err = ConfigureMetrics(targetContext.metricDefinitions, GetEvaluatorFunctions(), targetContext.metadata); err != nil { err = fmt.Errorf("failed to configure metrics: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) targetContext.err = err channelError <- targetError{target: myTarget, err: err} return @@ -907,9 +883,7 @@ func collectOnTarget(targetContext *targetContext, localTempDir string, localOut // get the perf command if processes, perfCommand, err = getPerfCommand(myTarget, targetContext.perfPath, targetContext.groupDefinitions, localTempDir); err != nil { err = fmt.Errorf("failed to get perf command: %w", err) - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) break } beginTimestamp := time.Now() @@ -919,9 +893,7 @@ func collectOnTarget(targetContext *targetContext, localTempDir string, localOut if perfErr != nil { if !getSignalReceived() { err = perfErr - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("Error: %s", err.Error())) } break } diff --git a/internal/common/common.go b/internal/common/common.go index 7db9709..3fc5882 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -377,14 +377,10 @@ func collectOnTarget(cmd *cobra.Command, myTarget target.Target, scriptsToRun [] // create a temporary directory on the target var targetTempDir string var err error - if statusUpdateErr := statusUpdate(myTarget.GetName(), "creating temporary directory"); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), "creating temporary directory") targetTempRoot, _ := cmd.Flags().GetString(FlagTargetTempDirName) if targetTempDir, err = myTarget.CreateTempDirectory(targetTempRoot); err != nil { - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("error creating temporary directory: %v", err)); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("error creating temporary directory: %v", err)) err = fmt.Errorf("error creating temporary directory on %s: %v", myTarget.GetName(), err) channelError <- err return @@ -399,20 +395,14 @@ func collectOnTarget(cmd *cobra.Command, myTarget target.Target, scriptsToRun [] }() } // run the scripts on the target - if statusUpdateErr := statusUpdate(myTarget.GetName(), "collecting data"); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), "collecting data") scriptOutputs, err := script.RunScripts(myTarget, scriptsToRun, true, localTempDir) if err != nil { - if statusUpdateErr := statusUpdate(myTarget.GetName(), fmt.Sprintf("error collecting data: %v", err)); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), fmt.Sprintf("error collecting data: %v", err)) err = fmt.Errorf("error running data collection scripts on %s: %v", myTarget.GetName(), err) channelError <- err return } - if statusUpdateErr := statusUpdate(myTarget.GetName(), "collection complete"); statusUpdateErr != nil { - slog.Error("failed to set status", slog.String("target", myTarget.GetName()), slog.String("error", statusUpdateErr.Error())) - } + _ = statusUpdate(myTarget.GetName(), "collection complete") channelTargetScriptOutputs <- TargetScriptOutputs{targetName: myTarget.GetName(), scriptOutputs: scriptOutputs} }