Fix path handling in File-SD watcher to allow directory monitoring on Windows

Previously, `d.paths` were normalized to backslashes on Windows, even when if
the config file used Unix style.  The end result meant always watching `./`, so
changes for this config were always ignored:

    scrape_configs:
      - job_name: 'envmsc1'
        file_sd_configs:
        - files:
          - 'targets/envmsc1.d/*.yml'
          - 'targets/envmsc1.d/*.yaml'

Additionally, unlike the other platforms, no warning was emitted on startup
about not being able to install the watch if the directory didn't exist.  Now it
is logged.

Signed-off-by: Matt Harbison <mharbison@atto.com>
This commit is contained in:
Matt Harbison 2023-06-23 16:37:04 -04:00
parent 391ecaec9a
commit 02277bbe0d
1 changed files with 2 additions and 2 deletions

View File

@ -226,8 +226,8 @@ func (d *Discovery) watchFiles() {
panic("no watcher configured")
}
for _, p := range d.paths {
if idx := strings.LastIndex(p, "/"); idx > -1 {
p = p[:idx]
if dir, _ := filepath.Split(p); dir != "" {
p = dir
} else {
p = "./"
}