Skip to content

Commit

Permalink
filestream: fix 'requires pointer' error (#33956)
Browse files Browse the repository at this point in the history
This commit fixes the 'requires pointer' error log issued by
filestream when a file being harvested is renamed.

Filebeat already recovers from this error by using the file
identifier from the prospector instead of the metadata, so the log
message is downgraded to warn and contains more details about what
happened.

(cherry picked from commit 2263f3e)
  • Loading branch information
belimawr authored and mergify[bot] committed Dec 14, 2022
1 parent ae6fc84 commit f8317df
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
43 changes: 43 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,49 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Affecting all Beats*

- Fix namespacing for agent self-monitoring, CPU no longer reports as zero. {pull}32336[32336]
- Fix namespacing on self-monitoring {pull}32336[32336]
- Fix race condition when stopping runners {pull}32433[32433]
- Fix concurrent map writes when system/process code called from reporter code {pull}32491[32491]
- Fix Windows service install/uninstall when Win32_Service returns error, add logic to wait until the Windows Service is stopped before proceeding. {pull}33322[33322]
- Support for multiline zookeeper logs {issue}2496[2496]
- Allow `clock_nanosleep` in the default seccomp profiles for amd64 and 386. Newer versions of glibc (e.g. 2.31) require it. {issue}33792[33792]
- Disable lockfile when running under elastic-agent. {pull}33988[33988]

*Auditbeat*


*Filebeat*
- [Azure blob storage] Added support for more mime types & introduced offset tracking via cursor state. {pull}33981[33981]
- Fix EOF on single line not producing any event. {issue}30436[30436] {pull}33568[33568]
- Fix handling of error in states in direct aws-s3 listing input {issue}33513[33513] {pull}33722[33722]
- Fix `httpjson` input page number initialization and documentation. {pull}33400[33400]
- Add handling of AAA operations for Cisco ASA module. {issue}32257[32257] {pull}32789[32789]
- Fix gc.log always shipped even if gc fileset is disabled {issue}30995[30995]
- Fix handling of empty array in httpjson input. {pull}32001[32001]
- Fix reporting of `filebeat.events.active` in log events such that the current value is always reported instead of the difference from the last value. {pull}33597[33597]
- Fix splitting array of strings/arrays in httpjson input {issue}30345[30345] {pull}33609[33609]
- Fix Google workspace pagination and document ID generation. {pull}33666[33666]
- Fix PANW handling of messages with event.original already set. {issue}33829[33829] {pull}33830[33830]
- Rename identity as identity_name when the value is a string in Azure Platform Logs. {pull}33654[33654]
- Fix 'requires pointer' error while getting cursor metadata. {pull}33956[33956]
- Fix input cancellation handling when HTTP client does not support contexts. {issue}33962[33962] {pull}33968[33968]
- Update mito CEL extension library to v0.0.0-20221207004749-2f0f2875e464 {pull}33974[33974]
- Fix CEL result deserialisation when evaluation fails. {issue}33992[33992] {pull}33996[33996]
- Fix handling of non-200/non-429 status codes. {issue}33999[33999] {pull}34002[34002]

*Heartbeat*
- Fix broken zip URL monitors. NOTE: Zip URL Monitors will be removed in version 8.7 and replaced with project monitors. {pull}33723[33723]
- Fix bug where states.duration_ms was incorrect type. {pull}33563[33563]
- Fix handling of long UDP messages in UDP input. {issue}33836[33836] {pull}33837[33837]
- Fix browser monitor summary reporting as up when monitor is down. {issue}33374[33374] {pull}33819[33819]


*Auditbeat*


*Filebeat*


*Auditbeat*

Expand Down
7 changes: 4 additions & 3 deletions filebeat/input/filestream/prospector.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,12 @@ func (p *fileProspector) onRename(log *logp.Logger, ctx input.Context, fe loginp
} else {
// update file metadata as the path has changed
var meta fileMeta
err := s.FindCursorMeta(src, meta)
err := s.FindCursorMeta(src, &meta)
if err != nil {
log.Errorf("Error while getting cursor meta data of entry %s: %v", src.Name(), err)

meta.IdentifierName = p.identifier.Name()
log.Warnf("Error while getting cursor meta data of entry '%s': '%w'"+
", using prospector's identifier: '%s'",
src.Name(), err, meta.IdentifierName)
}
err = s.UpdateMetadata(src, fileMeta{Source: fe.NewPath, IdentifierName: meta.IdentifierName})
if err != nil {
Expand Down
73 changes: 70 additions & 3 deletions filebeat/input/filestream/prospector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ func (mu *mockMetadataUpdater) has(id string) bool {
}

func (mu *mockMetadataUpdater) FindCursorMeta(s loginp.Source, v interface{}) error {
_, ok := mu.table[s.Name()]
meta, ok := mu.table[s.Name()]
if !ok {
return fmt.Errorf("no such id")
return fmt.Errorf("no such id [%q]", s.Name())
}
return nil
return typeconv.Convert(v, meta)
}

func (mu *mockMetadataUpdater) ResetCursor(s loginp.Source, cur interface{}) error {
Expand Down Expand Up @@ -558,3 +558,70 @@ func mustPathIdentifier(renamed bool) fileIdentifier {
}
return pathIdentifier
}

func TestOnRenameFileIdentity(t *testing.T) {
testCases := map[string]struct {
identifier string
events []loginp.FSEvent
populateStore bool
errMsg string
}{
"identifier name from meta is kept": {
identifier: "foo",
errMsg: "must be the same as in the registry",
populateStore: true,
events: []loginp.FSEvent{
{
Op: loginp.OpRename,
OldPath: "/old/path/to/file",
NewPath: "/new/path/to/file",
Info: testFileInfo{},
},
},
},
"identifier from prospector is used": {
identifier: "path",
errMsg: "must come from prospector configuration",
populateStore: false,
events: []loginp.FSEvent{
{
Op: loginp.OpRename,
OldPath: "/old/path/to/file",
NewPath: "/new/path/to/file",
Info: testFileInfo{},
},
},
},
}

for k, tc := range testCases {
t.Run(k, func(t *testing.T) {
p := fileProspector{
filewatcher: newMockFileWatcher(tc.events, len(tc.events)),
identifier: mustPathIdentifier(true),
stateChangeCloser: stateChangeCloserConfig{Renamed: true},
}
ctx := input.Context{Logger: logp.L(), Cancelation: context.Background()}

path := "/new/path/to/file"
expectedIdentifier := tc.identifier
id := "path" + "::" + path

testStore := newMockMetadataUpdater()
if tc.populateStore {
testStore.table[id] = fileMeta{Source: path, IdentifierName: expectedIdentifier}
}

hg := newTestHarvesterGroup()
p.Run(ctx, testStore, hg)

got := testStore.table[id]
meta := fileMeta{}
typeconv.Convert(&meta, got)

if meta.IdentifierName != expectedIdentifier {
t.Errorf("fileMeta.IdentifierName %s, expecting: %q, got: %q", tc.errMsg, expectedIdentifier, meta.IdentifierName)
}
})
}
}

0 comments on commit f8317df

Please sign in to comment.