Skip to content

Commit

Permalink
refactor: Store the log pattern poll waker in the Tailer struct.
Browse files Browse the repository at this point in the history
We would like to use this in per-pattern goroutines.

Issue: #331
  • Loading branch information
jaqx0r committed May 25, 2024
1 parent 45d2de8 commit 926ef7b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internal/tailer/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ type Tailer struct {
wg sync.WaitGroup // Wait for our subroutines to finish
lines chan<- *logline.LogLine

globPatternsMu sync.RWMutex // protects `globPatterns'
globPatterns map[string]struct{} // glob patterns to match newly created logs in dir paths against
ignoreRegexPattern *regexp.Regexp
logPatternPollWaker waker.Waker // Used to poll for new logs
globPatternsMu sync.RWMutex // protects `globPatterns'
globPatterns map[string]struct{} // glob patterns to match newly created logs in dir paths against
ignoreRegexPattern *regexp.Regexp

socketPaths []string

Expand Down Expand Up @@ -111,7 +112,8 @@ type logPatternPollWaker struct {
}

func (opt logPatternPollWaker) apply(t *Tailer) error {
t.StartLogPatternPollLoop(opt.Waker)
t.logPatternPollWaker = opt.Waker
t.StartLogPatternPollLoop()
return nil
}

Expand Down Expand Up @@ -345,8 +347,8 @@ func (t *Tailer) StartStaleLogstreamExpirationLoop(waker waker.Waker) {
}

// StartLogPatternPollLoop runs a permanent goroutine to poll for new log files.
func (t *Tailer) StartLogPatternPollLoop(waker waker.Waker) {
if waker == nil {
func (t *Tailer) StartLogPatternPollLoop() {
if t.logPatternPollWaker == nil {
glog.Info("Log pattern polling disabled")
return
}
Expand All @@ -363,7 +365,7 @@ func (t *Tailer) StartLogPatternPollLoop(waker waker.Waker) {
select {
case <-t.ctx.Done():
return
case <-waker.Wake():
case <-t.logPatternPollWaker.Wake():
if err := t.Poll(); err != nil {
glog.Info(err)
}
Expand Down

0 comments on commit 926ef7b

Please sign in to comment.