Skip to content

Commit

Permalink
Merge branch 'main' into test-queue-localstack
Browse files Browse the repository at this point in the history
  • Loading branch information
bhapas authored Jul 17, 2023
2 parents 386493a + b481143 commit 84be169
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions filebeat/input/filestream/fswatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package filestream

import (
"context"
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -693,6 +694,62 @@ scanner:
})
}

const benchmarkFileCount = 1000

func BenchmarkGetFiles(b *testing.B) {
dir := b.TempDir()
basenameFormat := "file-%d.log"

for i := 0; i < benchmarkFileCount; i++ {
filename := filepath.Join(dir, fmt.Sprintf(basenameFormat, i))
content := fmt.Sprintf("content-%d\n", i)
err := os.WriteFile(filename, []byte(strings.Repeat(content, 1024)), 0777)
require.NoError(b, err)
}

s := fileScanner{
paths: []string{filepath.Join(dir, "*.log")},
cfg: fileScannerConfig{
Fingerprint: fingerprintConfig{
Enabled: false,
},
},
}

for i := 0; i < b.N; i++ {
files := s.GetFiles()
require.Len(b, files, benchmarkFileCount)
}
}

func BenchmarkGetFilesWithFingerprint(b *testing.B) {
dir := b.TempDir()
basenameFormat := "file-%d.log"

for i := 0; i < benchmarkFileCount; i++ {
filename := filepath.Join(dir, fmt.Sprintf(basenameFormat, i))
content := fmt.Sprintf("content-%d\n", i)
err := os.WriteFile(filename, []byte(strings.Repeat(content, 1024)), 0777)
require.NoError(b, err)
}

s := fileScanner{
paths: []string{filepath.Join(dir, "*.log")},
cfg: fileScannerConfig{
Fingerprint: fingerprintConfig{
Enabled: true,
Offset: 0,
Length: 1024,
},
},
}

for i := 0; i < b.N; i++ {
files := s.GetFiles()
require.Len(b, files, benchmarkFileCount)
}
}

func createWatcherWithConfig(t *testing.T, paths []string, cfgStr string) loginp.FSWatcher {
cfg, err := conf.NewConfigWithYAML([]byte(cfgStr), cfgStr)
require.NoError(t, err)
Expand Down

0 comments on commit 84be169

Please sign in to comment.