From 58c5454d1aae7b46580f5d21cf078ad556f78499 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Thu, 28 Nov 2024 15:13:01 -0300 Subject: [PATCH] metricbeat: fix error when raid metrics are enabled on non-raid system When the Linux Metrics integration (beta) is installed with the raid metrics option enabled it causes an error if the host does not have a RAID configuration. This error causes the Agent to go into a degraded state. This happens because we report not having `/sys/block/md*` dirs as an error, this only means that no RAID configuration is in place. To fix this, do not report this case as an error. --- .../module/system/raid/blockinfo/getdev.go | 2 +- metricbeat/module/system/raid/raid_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/metricbeat/module/system/raid/blockinfo/getdev.go b/metricbeat/module/system/raid/blockinfo/getdev.go index 02527c80636..6c2c0b6758d 100644 --- a/metricbeat/module/system/raid/blockinfo/getdev.go +++ b/metricbeat/module/system/raid/blockinfo/getdev.go @@ -44,7 +44,7 @@ func ListAll(path string) ([]MDDevice, error) { } if len(mds) == 0 { - return nil, fmt.Errorf("no matches from path %s", path) + return nil, nil } return mds, nil diff --git a/metricbeat/module/system/raid/raid_test.go b/metricbeat/module/system/raid/raid_test.go index 4c35394413a..5a1fbaa2aac 100644 --- a/metricbeat/module/system/raid/raid_test.go +++ b/metricbeat/module/system/raid/raid_test.go @@ -18,6 +18,8 @@ package raid import ( + "os" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -46,6 +48,20 @@ func TestFetch(t *testing.T) { events[0].BeatEvent("system", "raid").Fields.StringToPrint()) } +func TestFetchNoRAID(t *testing.T) { + // Ensure that we don't error out when no RAID devices are present + tmpDir := t.TempDir() + assert.NoError(t, os.MkdirAll(filepath.Join(tmpDir, "sys/block"), 0755)) + c := getConfig() + c["hostfs"] = tmpDir + + f := mbtest.NewReportingMetricSetV2Error(t, c) + events, errs := mbtest.ReportingFetchV2Error(f) + + assert.Empty(t, errs) + assert.Empty(t, events) +} + func getConfig() map[string]interface{} { return map[string]interface{}{ "module": "system",