From 21b102baa4866c2ac2baa27372bbab8dcb5f78ac Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Thu, 18 Jul 2024 16:44:19 +0530 Subject: [PATCH] chore: add degradable error --- metricbeat/module/system/process/process.go | 10 ++++------ metricbeat/module/system/process/process_test.go | 8 ++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/metricbeat/module/system/process/process.go b/metricbeat/module/system/process/process.go index 538fa70d13e..dfc7e5752a7 100644 --- a/metricbeat/module/system/process/process.go +++ b/metricbeat/module/system/process/process.go @@ -20,7 +20,6 @@ package process import ( - "errors" "fmt" "os" "runtime" @@ -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, @@ -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) } @@ -124,7 +121,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { RootFields: roots[evtI], }) if !isOpen { - return nil + return err } } return err @@ -137,6 +134,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { MetricSetFields: proc, RootFields: root, }) - return err } + + return nil } diff --git a/metricbeat/module/system/process/process_test.go b/metricbeat/module/system/process/process_test.go index 98b48b75d6e..60a13040254 100644 --- a/metricbeat/module/system/process/process_test.go +++ b/metricbeat/module/system/process/process_test.go @@ -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))