Skip to content

Commit

Permalink
periodically clean up positions file, removing any files which no lon…
Browse files Browse the repository at this point in the history
…ger exist
  • Loading branch information
slim-bean committed Apr 17, 2019
1 parent 3f8963c commit c681c76
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/promtail/positions/positions.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (p *Positions) run() {
return
case <-ticker.C:
p.save()
p.cleanup()
}
}
}
Expand All @@ -124,6 +125,21 @@ func (p *Positions) save() {
}
}

func (p *Positions) cleanup() {
for k := range p.positions {
if _, err := os.Stat(k); err == nil {
// File still exists.
} else if os.IsNotExist(err) {
// File no longer exists.
p.Remove(k)
} else {
// Can't determine if file exists or not, some other error.
level.Warn(p.logger).Log("msg", "could not determine if log file "+
"still exists while cleaning positions file", "error", err)
}
}
}

func readPositionsFile(filename string) (map[string]int64, error) {
buf, err := ioutil.ReadFile(filepath.Clean(filename))
if err != nil {
Expand Down

0 comments on commit c681c76

Please sign in to comment.