Require goplugin build flag to enable go plugin support (#6393)
This commit is contained in:
parent
46b89b379a
commit
776e92ffab
|
@ -10,9 +10,6 @@ import (
|
||||||
_ "net/http/pprof" // Comment this line to disable pprof endpoint.
|
_ "net/http/pprof" // Comment this line to disable pprof endpoint.
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"plugin"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -21,6 +18,7 @@ import (
|
||||||
"github.com/influxdata/telegraf/agent"
|
"github.com/influxdata/telegraf/agent"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
"github.com/influxdata/telegraf/internal/config"
|
"github.com/influxdata/telegraf/internal/config"
|
||||||
|
"github.com/influxdata/telegraf/internal/goplugin"
|
||||||
"github.com/influxdata/telegraf/logger"
|
"github.com/influxdata/telegraf/logger"
|
||||||
_ "github.com/influxdata/telegraf/plugins/aggregators/all"
|
_ "github.com/influxdata/telegraf/plugins/aggregators/all"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
@ -116,36 +114,6 @@ func reloadLoop(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadExternalPlugins loads external plugins from shared libraries (.so, .dll, etc.)
|
|
||||||
// in the specified directory.
|
|
||||||
func loadExternalPlugins(rootDir string) error {
|
|
||||||
return filepath.Walk(rootDir, func(pth string, info os.FileInfo, err error) error {
|
|
||||||
// Stop if there was an error.
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore directories.
|
|
||||||
if info.IsDir() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore files that aren't shared libraries.
|
|
||||||
ext := strings.ToLower(path.Ext(pth))
|
|
||||||
if ext != ".so" && ext != ".dll" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load plugin.
|
|
||||||
_, err = plugin.Open(pth)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error loading %s: %s", pth, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func runAgent(ctx context.Context,
|
func runAgent(ctx context.Context,
|
||||||
inputFilters []string,
|
inputFilters []string,
|
||||||
outputFilters []string,
|
outputFilters []string,
|
||||||
|
@ -317,7 +285,7 @@ func main() {
|
||||||
// Load external plugins, if requested.
|
// Load external plugins, if requested.
|
||||||
if *fPlugins != "" {
|
if *fPlugins != "" {
|
||||||
log.Printf("I! Loading external plugins from: %s", *fPlugins)
|
log.Printf("I! Loading external plugins from: %s", *fPlugins)
|
||||||
if err := loadExternalPlugins(*fPlugins); err != nil {
|
if err := goplugin.LoadExternalPlugins(*fPlugins); err != nil {
|
||||||
log.Fatal("E! " + err.Error())
|
log.Fatal("E! " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
// +build !goplugin
|
||||||
|
|
||||||
|
package goplugin
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
func LoadExternalPlugins(rootDir string) error {
|
||||||
|
return errors.New("go plugin support is not enabled")
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
// +build goplugin
|
||||||
|
|
||||||
|
package goplugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"plugin"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// loadExternalPlugins loads external plugins from shared libraries (.so, .dll, etc.)
|
||||||
|
// in the specified directory.
|
||||||
|
func LoadExternalPlugins(rootDir string) error {
|
||||||
|
return filepath.Walk(rootDir, func(pth string, info os.FileInfo, err error) error {
|
||||||
|
// Stop if there was an error.
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore directories.
|
||||||
|
if info.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore files that aren't shared libraries.
|
||||||
|
ext := strings.ToLower(path.Ext(pth))
|
||||||
|
if ext != ".so" && ext != ".dll" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load plugin.
|
||||||
|
_, err = plugin.Open(pth)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error loading %s: %s", pth, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue