diff --git a/libbeat/processors/add_process_metadata/add_process_metadata_test.go b/libbeat/processors/add_process_metadata/add_process_metadata_test.go index 128b70a3d3c..d74297262cb 100644 --- a/libbeat/processors/add_process_metadata/add_process_metadata_test.go +++ b/libbeat/processors/add_process_metadata/add_process_metadata_test.go @@ -54,6 +54,22 @@ func newCGHandlerBuilder(handler testCGRsolver) processors.InitCgroupHandler { } } +func TestNilProcessor(t *testing.T) { + initCgroupPaths = func(rootfsMountpoint resolve.Resolver, ignoreRootCgroups bool) (processors.CGReader, error) { + return &processors.NilCGReader{}, nil + } + + proc, err := newProcessMetadataProcessorWithProvider(defaultConfig(), &procCache, false) + require.NoError(t, err) + + // make sure a nil cgroup reader doesn't blow anything up + unwrapped, _ := proc.(*addProcessMetadata) + metadata, err := unwrapped.provider.GetProcessMetadata(os.Getpid()) + require.NoError(t, err) + require.NotNil(t, metadata) + +} + func TestDefaultProcessorStartup(t *testing.T) { // set initCgroupPaths to system non-test defaults initCgroupPaths = func(rootfsMountpoint resolve.Resolver, ignoreRootCgroups bool) (processors.CGReader, error) { @@ -67,7 +83,7 @@ func TestDefaultProcessorStartup(t *testing.T) { unwrapped, _ := proc.(*addProcessMetadata) metadata, err := unwrapped.provider.GetProcessMetadata(os.Getpid()) require.NoError(t, err) - require.NotNil(t, metadata) + require.NotNil(t, metadata.fields) } func TestAddProcessMetadata(t *testing.T) { diff --git a/libbeat/processors/add_process_metadata/gosigar_cid_provider.go b/libbeat/processors/add_process_metadata/gosigar_cid_provider.go index 1fa291e3528..a9c3cadee56 100644 --- a/libbeat/processors/add_process_metadata/gosigar_cid_provider.go +++ b/libbeat/processors/add_process_metadata/gosigar_cid_provider.go @@ -55,7 +55,7 @@ func (p gosigarCidProvider) GetCid(pid int) (result string, err error) { cgroups, err := p.getProcessCgroups(pid) if err != nil { - p.log.Debugf("failed to get cgroups for pid=%v: %v", pid, err) + return "", fmt.Errorf("failed to get cgroups for pid=%v: %v", pid, err) } cid = p.getContainerID(cgroups)