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

[process] - Add a boolean to detect partial matches #199

Merged
merged 2 commits into from
Dec 24, 2024
Merged
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
11 changes: 9 additions & 2 deletions metric/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ func (procStats *Stats) Get() ([]mapstr.M, []mapstr.M, error) {
procs = append(procs, proc)
rootEvents = append(rootEvents, rootMap)
}
if len(failedPIDs) > 0 {
if wrappedErr != nil && len(failedPIDs) > 0 {
procStats.logger.Debugf("error fetching process metrics: %v", wrappedErr)
return procs, rootEvents, NonFatalErr{Err: fmt.Errorf(errFetchingPIDs, len(failedPIDs))}
}
return procs, rootEvents, nil
return procs, rootEvents, toNonFatal(wrappedErr)
}

// GetOne fetches process data for a given PID if its name matches the regexes provided from the host.
Expand Down Expand Up @@ -224,6 +224,10 @@ func (procStats *Stats) pidIter(pid int, procMap ProcsMap, proclist []ProcState)
procStats.logger.Debugf("Process name does not match the provided regex; PID=%d; name=%s", pid, status.Name)
return procMap, proclist, nonFatalErr
}
// there was some non-fatal error and given state is partial
if nonFatalErr != nil {
status.Partial = true
}
procMap[pid] = status
proclist = append(proclist, status)

Expand Down Expand Up @@ -422,12 +426,15 @@ func (procStats *Stats) isWhitelistedEnvVar(varName string) bool {
}

func extractFailedPIDs(procMap ProcsMap) []int {
// calculate the total amount of partial/failed PIDs
list := make([]int, 0)
for pid, state := range procMap {
if state.Failed {
list = append(list, pid)
// delete the failed state so we don't return the state to caller
delete(procMap, pid)
} else if state.Partial {
list = append(list, pid)
}
}
return list
Expand Down
4 changes: 3 additions & 1 deletion metric/system/process/process_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ type ProcState struct {
// meta
SampleTime time.Time `struct:"-,omitempty"`

// boolean to indicate that given PID has failed due to some error.
// boolean to indicate that given PID has completeley failed due to some error.
Failed bool `struct:"-,omitempty"`
// boolean to indicate that given state is partially filled.
Partial bool `struct:"-,omitempty"`
}

// ProcCPUInfo is the main struct for CPU metrics
Expand Down
Loading