Skip to content

Commit

Permalink
check if file is inactive every 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch committed Oct 2, 2020
1 parent 082f12b commit 850916c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions filebeat/input/filestream/filestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ func (f *logFile) startFileMonitoringIfNeeded() {

func (f *logFile) closeIfTimeout(ctx unison.Canceler) {
timer := time.NewTimer(f.closeAfterInterval)
defer timer.Stop()

for {
select {
case <-ctx.Done():
Expand All @@ -163,12 +165,21 @@ func (f *logFile) closeIfTimeout(ctx unison.Canceler) {
}

func (f *logFile) closeIfInactive(ctx unison.Canceler) {
// TODO it can be optimized
for ctx.Err() == nil {
age := time.Since(f.lastTimeRead)
if age > f.closeInactive {
f.cancelReading()
// This can be made configureble if users need a more flexible
// cheking for inactive files.
ticker := time.NewTicker(5 * time.Minute)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return
case <-ticker.C:
age := time.Since(f.lastTimeRead)
if age > f.closeInactive {
f.cancelReading()
return
}
}
}
}
Expand Down

0 comments on commit 850916c

Please sign in to comment.