Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filestream: fix 'requires pointer' error #33956

Merged
merged 7 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- 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]

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 @@ -267,11 +267,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)
belimawr marked this conversation as resolved.
Show resolved Hide resolved
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
77 changes: 74 additions & 3 deletions filebeat/input/filestream/prospector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,11 @@ func (mu *mockMetadataUpdater) checkOffset(id string, offset int64) 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 @@ -654,3 +654,74 @@ func mustPathIdentifier(renamed bool) fileIdentifier {
}
return pathIdentifier
}

func TestOnRenameIdentifierMustNotChange(t *testing.T) {
events := []loginp.FSEvent{
{
Op: loginp.OpRename,
OldPath: "/old/path/to/file",
NewPath: "/new/path/to/file",
Info: testFileInfo{},
},
}

p := fileProspector{
filewatcher: newMockFileWatcher(events, len(events)),
identifier: mustPathIdentifier(true),
stateChangeCloser: stateChangeCloserConfig{Renamed: true},
}
ctx := input.Context{Logger: logp.L(), Cancelation: context.Background()}

path := "/new/path/to/file"
expectedIdentifier := "foo"
id := expectedIdentifier + "::" + path

testStore := newMockMetadataUpdater()
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 must not change, expecting: %q, got: %q", expectedIdentifier, meta.IdentifierName)
}
}

func TestOnRenameFindCursorMetaErrorUseProspectorIdentifier(t *testing.T) {
events := []loginp.FSEvent{
{
Op: loginp.OpRename,
OldPath: "/old/path/to/file",
NewPath: "/new/path/to/file",
Info: testFileInfo{},
},
}

p := fileProspector{
filewatcher: newMockFileWatcher(events, len(events)),
identifier: mustPathIdentifier(true),
stateChangeCloser: stateChangeCloserConfig{Renamed: true},
}
ctx := input.Context{Logger: logp.L(), Cancelation: context.Background()}

path := "/new/path/to/file"
expectedIdentifier := "path"
id := expectedIdentifier + "::" + path

testStore := newMockMetadataUpdater()

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 must not change, expecting: %q, got: %q", expectedIdentifier, meta.IdentifierName)
}
}