Skip to content

Commit

Permalink
[system/process]: mark module as healthy if metrics are partially fi…
Browse files Browse the repository at this point in the history
…lled for single process as well. (#40924)

* fix: mark module as healthy if metrics are partially filled for single processes

* chore: fix lint

* chore: wrap the error and return

* chore: fix lint

---------

Co-authored-by: subham sarkar <subham.sarkar@elastic.co>
  • Loading branch information
VihasMakwana and shmsr authored Oct 8, 2024
1 parent 4c1489d commit dc94114
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions metricbeat/module/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return nil, err
}

sys := base.Module().(resolve.Resolver)
sys, ok := base.Module().(resolve.Resolver)
if !ok {
return nil, fmt.Errorf("resolver cannot be cast from the module")
}
enableCgroups := false
if runtime.GOOS == "linux" {
if config.Cgroups == nil || *config.Cgroups {
Expand Down Expand Up @@ -131,14 +134,17 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
return err
} else {
proc, root, err := m.stats.GetOneRootEvent(m.setpid)
if err != nil {
if err != nil && !errors.Is(err, process.NonFatalErr{}) {
// return only if the error is fatal in nature
return fmt.Errorf("error fetching pid %d: %w", m.setpid, err)
} else if (err != nil && errors.Is(err, process.NonFatalErr{})) {
err = mb.PartialMetricsError{Err: err}
}
// if error is non-fatal, emit partial metrics.
r.Event(mb.Event{
MetricSetFields: proc,
RootFields: root,
})
return err
}

return nil
}

0 comments on commit dc94114

Please sign in to comment.