Skip to content

Commit

Permalink
ignore status update errors
Browse files Browse the repository at this point in the history
  • Loading branch information
harp-intel committed Nov 6, 2024
1 parent 848b814 commit 8a6fb66
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 71 deletions.
17 changes: 3 additions & 14 deletions cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
56 changes: 14 additions & 42 deletions cmd/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -774,19 +770,15 @@ 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
}
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -854,29 +836,23 @@ 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
}
// 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
}
// 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
Expand Down Expand Up @@ -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()
Expand All @@ -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
}
Expand Down
20 changes: 5 additions & 15 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
}

0 comments on commit 8a6fb66

Please sign in to comment.