Skip to content

Commit

Permalink
Fix the performance regression when ingesting files on Windows (#37301)…
Browse files Browse the repository at this point in the history
… (#37360)

Adding additional file system metadata caused additional system calls
that degraded the file reading performance.

(cherry picked from commit 8f50ca3)

Co-authored-by: Denis <denis.rechkunov@elastic.co>
  • Loading branch information
mergify[bot] and rdner authored Dec 18, 2023
1 parent 3433663 commit 9001376
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 119 deletions.
3 changes: 2 additions & 1 deletion filebeat/input/filestream/copytruncate_prospector.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
input "github.com/elastic/beats/v7/filebeat/input/v2"
"github.com/elastic/beats/v7/libbeat/common/file"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/go-concert/unison"
)
Expand Down Expand Up @@ -330,7 +331,7 @@ func (p *copyTruncateFileProspector) onRotatedFile(
return
}
descCopy := fe.Descriptor
descCopy.Info = fi
descCopy.Info = file.ExtendFileInfo(fi)
originalSrc := p.identifier.GetSource(loginp.FSEvent{NewPath: originalPath, Descriptor: descCopy})
p.rotatedFiles.addOriginalFile(originalPath, originalSrc)
p.rotatedFiles.addRotatedFile(originalPath, fe.NewPath, src)
Expand Down
9 changes: 8 additions & 1 deletion filebeat/input/filestream/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
v2 "github.com/elastic/beats/v7/filebeat/input/v2"
"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/beats/v7/libbeat/common/acker"
"github.com/elastic/beats/v7/libbeat/common/file"
"github.com/elastic/beats/v7/libbeat/common/transform/typeconv"
"github.com/elastic/beats/v7/libbeat/statestore"
"github.com/elastic/beats/v7/libbeat/statestore/storetest"
Expand Down Expand Up @@ -372,7 +373,13 @@ func (e *inputTestingEnvironment) getRegistryState(key string) (registryEntry, e

func getIDFromPath(filepath, inputID string, fi os.FileInfo) string {
identifier, _ := newINodeDeviceIdentifier(nil)
src := identifier.GetSource(loginp.FSEvent{Descriptor: loginp.FileDescriptor{Info: fi}, Op: loginp.OpCreate, NewPath: filepath})
src := identifier.GetSource(loginp.FSEvent{
Descriptor: loginp.FileDescriptor{
Info: file.ExtendFileInfo(fi),
},
Op: loginp.OpCreate,
NewPath: filepath,
})
return "filestream::" + inputID + "::" + src.Name()
}

Expand Down
9 changes: 6 additions & 3 deletions filebeat/input/filestream/fswatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/elastic/beats/v7/filebeat/input/file"
loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
commonfile "github.com/elastic/beats/v7/libbeat/common/file"
"github.com/elastic/beats/v7/libbeat/common/match"
conf "github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp"
Expand Down Expand Up @@ -406,7 +407,7 @@ type ingestTarget struct {
filename string
originalFilename string
symlink bool
info os.FileInfo
info commonfile.ExtendedFileInfo
}

func (s *fileScanner) getIngestTarget(filename string) (it ingestTarget, err error) {
Expand All @@ -421,10 +422,11 @@ func (s *fileScanner) getIngestTarget(filename string) (it ingestTarget, err err
it.filename = filename
it.originalFilename = filename

it.info, err = os.Lstat(it.filename) // to determine if it's a symlink
info, err := os.Lstat(it.filename) // to determine if it's a symlink
if err != nil {
return it, fmt.Errorf("failed to lstat %q: %w", it.filename, err)
}
it.info = commonfile.ExtendFileInfo(info)

if it.info.IsDir() {
return it, fmt.Errorf("file %q is a directory", it.filename)
Expand All @@ -438,10 +440,11 @@ func (s *fileScanner) getIngestTarget(filename string) (it ingestTarget, err err
}

// now we know it's a symlink, we stat with link resolution
it.info, err = os.Stat(it.filename)
info, err := os.Stat(it.filename)
if err != nil {
return it, fmt.Errorf("failed to stat the symlink %q: %w", it.filename, err)
}
it.info = commonfile.ExtendFileInfo(info)

it.originalFilename, err = filepath.EvalSymlinks(it.filename)
if err != nil {
Expand Down
Loading

0 comments on commit 9001376

Please sign in to comment.