Skip to content

Commit 8f50ca3

Browse files
authored
Fix the performance regression when ingesting files on Windows (#37301)
Adding additional file system metadata caused additional system calls that degraded the file reading performance.
1 parent 89e4737 commit 8f50ca3

18 files changed

+199
-119
lines changed

filebeat/input/filestream/copytruncate_prospector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
3030
input "github.com/elastic/beats/v7/filebeat/input/v2"
31+
"github.com/elastic/beats/v7/libbeat/common/file"
3132
"github.com/elastic/elastic-agent-libs/logp"
3233
"github.com/elastic/go-concert/unison"
3334
)
@@ -330,7 +331,7 @@ func (p *copyTruncateFileProspector) onRotatedFile(
330331
return
331332
}
332333
descCopy := fe.Descriptor
333-
descCopy.Info = fi
334+
descCopy.Info = file.ExtendFileInfo(fi)
334335
originalSrc := p.identifier.GetSource(loginp.FSEvent{NewPath: originalPath, Descriptor: descCopy})
335336
p.rotatedFiles.addOriginalFile(originalPath, originalSrc)
336337
p.rotatedFiles.addRotatedFile(originalPath, fe.NewPath, src)

filebeat/input/filestream/environment_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
v2 "github.com/elastic/beats/v7/filebeat/input/v2"
3838
"github.com/elastic/beats/v7/libbeat/beat"
3939
"github.com/elastic/beats/v7/libbeat/common/acker"
40+
"github.com/elastic/beats/v7/libbeat/common/file"
4041
"github.com/elastic/beats/v7/libbeat/common/transform/typeconv"
4142
"github.com/elastic/beats/v7/libbeat/statestore"
4243
"github.com/elastic/beats/v7/libbeat/statestore/storetest"
@@ -372,7 +373,13 @@ func (e *inputTestingEnvironment) getRegistryState(key string) (registryEntry, e
372373

373374
func getIDFromPath(filepath, inputID string, fi os.FileInfo) string {
374375
identifier, _ := newINodeDeviceIdentifier(nil)
375-
src := identifier.GetSource(loginp.FSEvent{Descriptor: loginp.FileDescriptor{Info: fi}, Op: loginp.OpCreate, NewPath: filepath})
376+
src := identifier.GetSource(loginp.FSEvent{
377+
Descriptor: loginp.FileDescriptor{
378+
Info: file.ExtendFileInfo(fi),
379+
},
380+
Op: loginp.OpCreate,
381+
NewPath: filepath,
382+
})
376383
return "filestream::" + inputID + "::" + src.Name()
377384
}
378385

filebeat/input/filestream/fswatch.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
"github.com/elastic/beats/v7/filebeat/input/file"
3434
loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
35+
commonfile "github.com/elastic/beats/v7/libbeat/common/file"
3536
"github.com/elastic/beats/v7/libbeat/common/match"
3637
conf "github.com/elastic/elastic-agent-libs/config"
3738
"github.com/elastic/elastic-agent-libs/logp"
@@ -406,7 +407,7 @@ type ingestTarget struct {
406407
filename string
407408
originalFilename string
408409
symlink bool
409-
info os.FileInfo
410+
info commonfile.ExtendedFileInfo
410411
}
411412

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

424-
it.info, err = os.Lstat(it.filename) // to determine if it's a symlink
425+
info, err := os.Lstat(it.filename) // to determine if it's a symlink
425426
if err != nil {
426427
return it, fmt.Errorf("failed to lstat %q: %w", it.filename, err)
427428
}
429+
it.info = commonfile.ExtendFileInfo(info)
428430

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

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

446449
it.originalFilename, err = filepath.EvalSymlinks(it.filename)
447450
if err != nil {

0 commit comments

Comments
 (0)