diff --git a/metric/system/process/process.go b/metric/system/process/process.go index 53f646b5b..f0f4a23ac 100644 --- a/metric/system/process/process.go +++ b/metric/system/process/process.go @@ -169,7 +169,7 @@ func (procStats *Stats) GetSelf() (ProcState, error) { func (procStats *Stats) pidIter(pid int, procMap ProcsMap, proclist []ProcState) (ProcsMap, []ProcState) { status, saved, err := procStats.pidFill(pid, true) if err != nil { - if !errors.Is(err, NotEnoughPrivilegesErr{}) { + if !errors.Is(err, NonFatalErr{}) { procStats.logger.Debugf("Error fetching PID info for %d, skipping: %s", pid, err) return procMap, proclist } @@ -184,21 +184,25 @@ func (procStats *Stats) pidIter(pid int, procMap ProcsMap, proclist []ProcState) return procMap, proclist } -// NotEnoughPrivilegesErr is returned when the current access -// rights are not enough to get some metrics. -// This error can be safely ignored and only means the function/method -// could not gather all metrics, however whatever has been gethered -// is still valid. -type NotEnoughPrivilegesErr struct { +// NonFatalErr is returned when there was an error +// collecting metrics, however the metrics already +// gathered and returned are still valid. +// This error can be safely ignored, this will result +// in having partial metrics for a process rather than +// no metrics at all. +// +// It was introduced to allow for partial metrics collection +// on privileged process on Windows. +type NonFatalErr struct { Err error } -func (c NotEnoughPrivilegesErr) Error() string { +func (c NonFatalErr) Error() string { return "Not enough privileges to fetch information: " + c.Err.Error() } -func (c NotEnoughPrivilegesErr) Is(other error) bool { - _, is := other.(NotEnoughPrivilegesErr) +func (c NonFatalErr) Is(other error) bool { + _, is := other.(NonFatalErr) return is } diff --git a/metric/system/process/process_windows.go b/metric/system/process/process_windows.go index d3094f848..61882d6ec 100644 --- a/metric/system/process/process_windows.go +++ b/metric/system/process/process_windows.go @@ -143,12 +143,12 @@ func FillPidMetrics(_ resolve.Resolver, pid int, state ProcState, _ func(string) func FillMetricsRequiringMoreAccess(pid int, state ProcState) (ProcState, error) { argList, err := getProcArgs(pid) if err != nil { - return state, fmt.Errorf("error fetching process args: %w", NotEnoughPrivilegesErr{Err: err}) + return state, fmt.Errorf("error fetching process args: %w", NonFatalErr{Err: err}) } state.Args = argList if numThreads, err := FetchNumThreads(pid); err != nil { - return state, fmt.Errorf("error fetching num threads: %w", NotEnoughPrivilegesErr{Err: err}) + return state, fmt.Errorf("error fetching num threads: %w", NonFatalErr{Err: err}) } else { state.NumThreads = opt.IntWith(numThreads) }