Skip to content

Commit

Permalink
symbolication: reduce error logs for short-lived executables
Browse files Browse the repository at this point in the history
short lived executables might no longer exist by the time we want
to copy symbols, this hopefully reduces the amount of error logs
that the uploader outputs for those executables
  • Loading branch information
Gandem committed Jul 10, 2024
1 parent 4eee7ad commit 8a5165f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions symbolication/datadog_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"os/exec"
"runtime"
"strings"
"time"

lru "github.com/elastic/go-freelru"
Expand Down Expand Up @@ -127,6 +128,14 @@ func (d *DatadogUploader) HandleExecutable(elfRef *pfelf.Reference, fileID libpf
return
}

_, err = os.Stat(inputFilePath)
if err != nil {
d.uploadCache.Remove(fileID)
log.Debugf("Skipping symbol extraction for short-lived executable %s: %v", fileName,
err)
return
}

err = d.handleSymbols(inputFilePath, e)
if err != nil {
d.uploadCache.Remove(fileID)
Expand Down Expand Up @@ -217,9 +226,9 @@ func (d *DatadogUploader) copySymbols(ctx context.Context, inputPath, outputPath
inputPath,
outputPath,
}
err := exec.CommandContext(ctx, "objcopy", args...).Run()
_, err := exec.CommandContext(ctx, "objcopy", args...).Output()
if err != nil {
return fmt.Errorf("failed to extract debug symbols: %w", err)
return fmt.Errorf("failed to extract debug symbols: %w", cleanCmdError(err))
}
return nil
}
Expand Down Expand Up @@ -355,3 +364,18 @@ func debugSymbolsPathForElf(ef *pfelf.File, fileName string) (string, error) {
}
return filePath, nil
}

// cleanCmdError simplifies error messages from os/exec.Cmd.Run.
// For ExitErrors, it trims and returns stderr. By default, ExitError prints the exit
// status but not stderr.
//
// cleanCmdError returns other errors unmodified.
func cleanCmdError(err error) error {
var xerr *exec.ExitError
if errors.As(err, &xerr) {
if stderr := strings.TrimSpace(string(xerr.Stderr)); stderr != "" {
return fmt.Errorf("%w: %s", err, stderr)
}
}
return err
}

0 comments on commit 8a5165f

Please sign in to comment.