Skip to content

Commit

Permalink
chore: add degradable error
Browse files Browse the repository at this point in the history
  • Loading branch information
VihasMakwana committed Jul 18, 2024
1 parent 1bfcecb commit 21b102b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 4 additions & 6 deletions metricbeat/module/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package process

import (
"errors"
"fmt"
"os"
"runtime"
Expand All @@ -31,11 +30,9 @@ import (
"github.com/elastic/elastic-agent-system-metrics/metric/system/cgroup"
"github.com/elastic/elastic-agent-system-metrics/metric/system/process"
"github.com/elastic/elastic-agent-system-metrics/metric/system/resolve"
"github.com/joeshaw/multierror"
)

var debugf = logp.NewLogger("system.process").Debugf
var typeMultiError *multierror.MultiError

func init() {
mb.Registry.MustAddMetricSet("system", "process", New,
Expand Down Expand Up @@ -114,7 +111,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
// monitor either a single PID, or the configured set of processes.
if m.setpid == 0 {
procs, roots, err := m.stats.Get()
if errors.As(err, &typeMultiError) && err != nil {
if err != nil && !process.IsDegradable(err) {
return fmt.Errorf("process stats: %w", err)
}

Expand All @@ -124,7 +121,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
RootFields: roots[evtI],
})
if !isOpen {
return nil
return err
}
}
return err
Expand All @@ -137,6 +134,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
MetricSetFields: proc,
RootFields: root,
})
return err
}

return nil
}
8 changes: 6 additions & 2 deletions metricbeat/module/system/process/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ func TestFetch(t *testing.T) {

f := mbtest.NewReportingMetricSetV2Error(t, getConfig())
events, errs := mbtest.ReportingFetchV2Error(f)
assert.Empty(t, errs)
for _, err := range errs {
assert.True(t, process.IsDegradable(err))
}
assert.NotEmpty(t, events)

time.Sleep(2 * time.Second)

events, errs = mbtest.ReportingFetchV2Error(f)
assert.Empty(t, errs)
for _, err := range errs {
assert.True(t, process.IsDegradable(err))
}
assert.NotEmpty(t, events)

t.Logf("fetched %d events, showing events[0]:", len(events))
Expand Down

0 comments on commit 21b102b

Please sign in to comment.