diff --git a/clients/pkg/promtail/targets/file/filetarget.go b/clients/pkg/promtail/targets/file/filetarget.go index 0ade51902b492..6b2d97249405d 100644 --- a/clients/pkg/promtail/targets/file/filetarget.go +++ b/clients/pkg/promtail/targets/file/filetarget.go @@ -262,7 +262,9 @@ func (t *FileTarget) sync() error { } } } - + + matches = removeFilesInIgnoredDirectories(matches) + if len(matches) == 0 { level.Debug(t.logger).Log("msg", "no files matched requested path, nothing will be tailed", "path", t.path, "pathExclude", t.pathExclude) } @@ -321,6 +323,17 @@ func (t *FileTarget) sync() error { return nil } +// given a list of files return the list of files minus those in directories with ignore files +func removeFilesInIgnoredDirectories(matches []string ) []string { + for j := 0; j < len(matches); j++ { + if d,err := doublestar.Glob(filepath.Join(filepath.Dir(matches[j]), "*promtail_ignore*")); len(d) > 0 { + // exclude this specific match + matches = append(matches[:j], matches[j+1:]...) + } + return matches + +} + func (t *FileTarget) startWatching(dirs map[string]struct{}) { for dir := range dirs { if _, ok := t.getWatch(dir); ok {