diff --git a/filebeat/input/filestream/fswatch.go b/filebeat/input/filestream/fswatch.go index 2db95427cad..0b1e5df46f4 100644 --- a/filebeat/input/filestream/fswatch.go +++ b/filebeat/input/filestream/fswatch.go @@ -28,6 +28,7 @@ import ( "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/common/match" "github.com/elastic/beats/v7/libbeat/logp" + "github.com/elastic/go-concert/timed" "github.com/elastic/go-concert/unison" ) @@ -118,16 +119,11 @@ func (w *fileWatcher) Run(ctx unison.Canceler) { // run initial scan before starting regular w.watch(ctx) - ticker := time.NewTicker(w.interval) - defer ticker.Stop() - for { - select { - case <-ctx.Done(): - return - case <-ticker.C: - w.watch(ctx) - } - } + timed.Periodic(ctx, w.interval, func() error { + w.watch(ctx) + + return nil + }) } func (w *fileWatcher) watch(ctx unison.Canceler) {