Skip to content

Commit

Permalink
check file path patterns on start
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryRomanov committed Oct 8, 2024
1 parent 9bea8d8 commit bd68692
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions plugin/input/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"
"time"

"github.com/bmatcuk/doublestar/v4"
"github.com/ozontech/file.d/cfg"
"github.com/ozontech/file.d/fd"
"github.com/ozontech/file.d/metric"
Expand Down Expand Up @@ -223,6 +224,20 @@ func (p *Plugin) Start(config pipeline.AnyConfig, params *pipeline.InputPluginPa
offsetFiles[offsetFilePath] = params.PipelineName
}

for _, pattern := range p.config.Paths.Include {
_, err := doublestar.PathMatch(pattern, ".")
if err != nil {
p.logger.Fatalf("wrong paths include pattern %q: %s", pattern, err.Error())
}
}

for _, pattern := range p.config.Paths.Exclude {
_, err := doublestar.PathMatch(pattern, ".")
if err != nil {
p.logger.Fatalf("wrong paths exclude pattern %q: %s", pattern, err.Error())
}
}

p.jobProvider = NewJobProvider(
p.config,
newMetricCollection(
Expand Down
4 changes: 2 additions & 2 deletions plugin/input/file/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (w *watcher) notify(e notify.Event, path string) {
for _, pattern := range w.paths.Exclude {
match, err := doublestar.PathMatch(pattern, path)
if err != nil {
w.logger.Fatalf("wrong paths exclude pattern %q: %s", pattern, err.Error())
w.logger.Errorf("wrong paths exclude pattern %q: %s", pattern, err.Error())
return
}
if match {
Expand Down Expand Up @@ -189,7 +189,7 @@ check_file:
for _, pattern := range w.paths.Include {
match, err := doublestar.PathMatch(pattern, path)
if err != nil {
w.logger.Fatalf("wrong paths include pattern %q: %s", pattern, err.Error())
w.logger.Errorf("wrong paths include pattern %q: %s", pattern, err.Error())
return
}

Expand Down

0 comments on commit bd68692

Please sign in to comment.