Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[system/process] Log pid in all cases #187

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions metric/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (procStats *Stats) pidFill(pid int, filter bool) (ProcState, bool, error) {
// OS-specific entrypoint, get basic info so we can at least run matchProcess
status, err := GetInfoForPid(procStats.Hostfs, pid)
if err != nil {
return status, true, fmt.Errorf("GetInfoForPid: %w", err)
return status, true, fmt.Errorf("GetInfoForPid failed for pid %d: %w", pid, err)
}
if procStats.skipExtended {
return status, true, nil
Expand All @@ -250,7 +250,7 @@ func (procStats *Stats) pidFill(pid int, filter bool) (ProcState, bool, error) {
status, err = FillPidMetrics(procStats.Hostfs, pid, status, procStats.isWhitelistedEnvVar)
if err != nil {
if !errors.Is(err, NonFatalErr{}) {
return status, true, fmt.Errorf("FillPidMetrics: %w", err)
return status, true, fmt.Errorf("FillPidMetrics failed for PID %d: %w", pid, err)
}
wrappedErr = errors.Join(wrappedErr, fmt.Errorf("non-fatal error fetching PID metrics for %d, metrics are valid, but partial: %w", pid, err))
procStats.logger.Debugf(wrappedErr.Error())
Expand Down Expand Up @@ -282,7 +282,7 @@ func (procStats *Stats) pidFill(pid int, filter bool) (ProcState, bool, error) {

status, err = FillMetricsRequiringMoreAccess(pid, status)
if err != nil {
return status, true, fmt.Errorf("FillMetricsRequiringMoreAccess: %w", err)
return status, true, fmt.Errorf("FillMetricsRequiringMoreAccess failed for pid %d: %w", pid, err)
}

// Generate `status.Cmdline` here for compatibility because on Windows
Expand Down
14 changes: 7 additions & 7 deletions metric/system/process/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func FetchNumThreads(pid int) (int, error) {

currentProcessHandle, err := syscall.GetCurrentProcess()
if err != nil {
return 0, fmt.Errorf("GetCurrentProcess failed: %w", err)
return 0, fmt.Errorf("GetCurrentProcess failed for PID %d: %w", pid, err)
}
// The pseudo handle need not be closed when it is no longer
// needed, calling CloseHandle has no effect. Adding here to
Expand All @@ -114,7 +114,7 @@ func FetchNumThreads(pid int) (int, error) {
var snapshotHandle syscall.Handle
err = PssCaptureSnapshot(targetProcessHandle, PSSCaptureThreads, 0, &snapshotHandle)
if err != nil {
return 0, fmt.Errorf("PssCaptureSnapshot failed: %w", err)
return 0, fmt.Errorf("PssCaptureSnapshot failed for PID %d: %w", pid, err)
}

info := PssThreadInformation{}
Expand Down Expand Up @@ -189,28 +189,28 @@ func getProcArgs(pid int) ([]string, error) {
false,
uint32(pid))
if err != nil {
return nil, fmt.Errorf("OpenProcess failed: %w", err)
return nil, fmt.Errorf("OpenProcess failed for PID %d: %w", pid, err)
}
defer func() {
_ = syscall.CloseHandle(handle)
}()
pbi, err := windows.NtQueryProcessBasicInformation(handle)
if err != nil {
return nil, fmt.Errorf("NtQueryProcessBasicInformation failed: %w", err)
return nil, fmt.Errorf("NtQueryProcessBasicInformation failed for PID %d: %w", pid, err)
}

userProcParams, err := windows.GetUserProcessParams(handle, pbi)
if err != nil {
return nil, fmt.Errorf("GetUserProcessParams failed: %w", err)
return nil, fmt.Errorf("GetUserProcessParams failed for PID %d: %w", pid, err)
}
argsW, err := windows.ReadProcessUnicodeString(handle, &userProcParams.CommandLine)
if err != nil {
return nil, fmt.Errorf("ReadProcessUnicodeString failed: %w", err)
return nil, fmt.Errorf("ReadProcessUnicodeString failed for PID %d: %w", pid, err)
}

procList, err := windows.ByteSliceToStringSlice(argsW)
if err != nil {
return nil, fmt.Errorf("ByteSliceToStringSlice failed: %w", err)
return nil, fmt.Errorf("ByteSliceToStringSlice failed for PID %d: %w", pid, err)
}
return procList, nil
}
Expand Down
Loading