Browse Source

go.d add support for symlinked vnode config files (#18445)

Ilya Mashchenko 6 months ago
parent
commit
c24d9caeac
1 changed files with 29 additions and 1 deletions
  1. 29 1
      src/go/plugin/go.d/agent/vnodes/vnodes.go

+ 29 - 1
src/go/plugin/go.d/agent/vnodes/vnodes.go

@@ -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