From 51a785484db6cbb01b65b3ac2661b59cd377a30e Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Thu, 18 Jul 2024 18:42:00 +0530 Subject: [PATCH] chore: update process summary --- .../module/system/process_summary/process_summary.go | 10 +++++----- .../system/process_summary/process_summary_test.go | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/metricbeat/module/system/process_summary/process_summary.go b/metricbeat/module/system/process_summary/process_summary.go index c64a0c1d3e1..2f30319203c 100644 --- a/metricbeat/module/system/process_summary/process_summary.go +++ b/metricbeat/module/system/process_summary/process_summary.go @@ -68,9 +68,9 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // descriptive error must be returned. func (m *MetricSet) Fetch(r mb.ReporterV2) error { - procList, err := process.ListStates(m.sys) - if err != nil { - return fmt.Errorf("error fetching process list: %w", err) + procList, degradeErr := process.ListStates(m.sys) + if degradeErr != nil && !process.IsDegradable(degradeErr) { + return fmt.Errorf("error fetching process list: %w", degradeErr) } procStates := map[string]int{} @@ -83,7 +83,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { } outMap := mapstr.M{} - err = typeconv.Convert(&outMap, procStates) + err := typeconv.Convert(&outMap, procStates) if err != nil { return fmt.Errorf("error formatting process stats: %w", err) } @@ -101,7 +101,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { MetricSetFields: outMap, }) - return nil + return degradeErr } // threadStats returns a map of state counts for running threads on a system diff --git a/metricbeat/module/system/process_summary/process_summary_test.go b/metricbeat/module/system/process_summary/process_summary_test.go index 7ec35634e43..254ea10548d 100644 --- a/metricbeat/module/system/process_summary/process_summary_test.go +++ b/metricbeat/module/system/process_summary/process_summary_test.go @@ -46,7 +46,9 @@ func TestFetch(t *testing.T) { f := mbtest.NewReportingMetricSetV2Error(t, getConfig()) events, errs := mbtest.ReportingFetchV2Error(f) - require.Empty(t, errs) + for _, err := range errs { + assert.True(t, process.IsDegradable(err)) + } require.NotEmpty(t, events) event := events[0].BeatEvent("system", "process_summary").Fields t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), @@ -62,7 +64,9 @@ func TestStateNames(t *testing.T) { f := mbtest.NewReportingMetricSetV2Error(t, getConfig()) events, errs := mbtest.ReportingFetchV2Error(f) - require.Empty(t, errs) + for _, err := range errs { + assert.True(t, process.IsDegradable(err)) + } require.NotEmpty(t, events) event := events[0].BeatEvent("system", "process_summary").Fields