Skip to content

Commit

Permalink
metricbeat: fix error when raid metrics are enabled on non-raid system
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mauri870 committed Nov 28, 2024
1 parent 42e25f7 commit 58c5454
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion metricbeat/module/system/raid/blockinfo/getdev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions metricbeat/module/system/raid/raid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package raid

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 58c5454

Please sign in to comment.