Skip to content

Commit

Permalink
go.d add support for symlinked vnode config files (netdata#18445)
Browse files Browse the repository at this point in the history
(cherry picked from commit c24d9ca)
  • Loading branch information
ilyam8 authored and stelfrag committed Sep 6, 2024
1 parent 98c5645 commit 86da19d
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/go/plugin/go.d/agent/vnodes/vnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,39 @@ func (vn *Vnodes) readConfDir() {
return nil
}

if !d.Type().IsRegular() || !isConfigFile(path) {
if d.Type()&os.ModeSymlink != 0 {
dst, err := os.Readlink(path)
if err != nil {
vn.Warningf("failed to resolve symlink '%s': %v", path, err)
return nil
}

if !filepath.IsAbs(dst) {
dst = filepath.Join(filepath.Dir(path), filepath.Clean(dst))
}

fi, err := os.Stat(dst)
if err != nil {
vn.Warningf("failed to stat resolved path '%s': %v", dst, err)
return nil
}
if !fi.Mode().IsRegular() {
vn.Debugf("'%s' is not a regular file, skipping it", dst)
return nil
}
path = dst
} else if !d.Type().IsRegular() {
vn.Debugf("'%s' is not a regular file, skipping it", path)
return nil
}

if !isConfigFile(path) {
vn.Debugf("'%s' is not a config file (wrong extension), skipping it", path)
return nil
}

var cfg []VirtualNode

if err := loadConfigFile(&cfg, path); err != nil {
vn.Warning(err)
return nil
Expand Down

0 comments on commit 86da19d

Please sign in to comment.