diff --git a/internal/collector/filetime/filetime.go b/internal/collector/filetime/filetime.go index 0dbdd2fe..e80b6ed1 100644 --- a/internal/collector/filetime/filetime.go +++ b/internal/collector/filetime/filetime.go @@ -19,6 +19,7 @@ package filetime import ( "fmt" + "io/fs" "log/slog" "os" "path/filepath" @@ -139,16 +140,11 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error { } func (c *Collector) collectGlobFilePath(ch chan<- prometheus.Metric, filePattern string) error { - basePath, pattern := doublestar.SplitPattern(filePattern) + basePath, pattern := doublestar.SplitPattern(filepath.ToSlash(filePattern)) basePathFS := os.DirFS(basePath) - matches, err := doublestar.Glob(basePathFS, pattern, doublestar.WithFilesOnly(), doublestar.WithCaseInsensitive()) - if err != nil { - return fmt.Errorf("failed to glob: %w", err) - } - - for _, match := range matches { - filePath := filepath.Join(basePath, match) + err := doublestar.GlobWalk(basePathFS, pattern, func(path string, d fs.DirEntry) error { + filePath := filepath.Join(basePath, path) fileInfo, err := os.Stat(filePath) if err != nil { @@ -157,7 +153,7 @@ func (c *Collector) collectGlobFilePath(ch chan<- prometheus.Metric, filePattern slog.Any("err", err), ) - continue + return nil } ch <- prometheus.MustNewConstMetric( @@ -166,6 +162,11 @@ func (c *Collector) collectGlobFilePath(ch chan<- prometheus.Metric, filePattern float64(fileInfo.ModTime().UTC().UnixMicro())/1e6, filePath, ) + + return nil + }, doublestar.WithFilesOnly(), doublestar.WithCaseInsensitive()) + if err != nil { + return fmt.Errorf("failed to glob: %w", err) } return nil