Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from netdata:master #236

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/go/cmd/godplugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type config struct {
collectorsDir multipath.MultiPath
collectorsWatchPath []string
serviceDiscoveryDir multipath.MultiPath
vnodesDir multipath.MultiPath
stateFile string
lockDir string
}
Expand All @@ -79,7 +78,6 @@ func newConfig(opts *cli.Option, env *envConfig) *config {
cfg.collectorsDir = cfg.initCollectorsDir(opts)
cfg.collectorsWatchPath = cfg.initCollectorsWatchPaths(opts, env)
cfg.serviceDiscoveryDir = cfg.initServiceDiscoveryConfigDir()
cfg.vnodesDir = cfg.initVnodesDir()
cfg.stateFile = cfg.initStateFile(env)
cfg.lockDir = env.lockDir

Expand Down Expand Up @@ -156,18 +154,6 @@ func (c *config) initServiceDiscoveryConfigDir() multipath.MultiPath {
return mpath
}

func (c *config) initVnodesDir() multipath.MultiPath {
c.mustPluginDir()

var mpath multipath.MultiPath

for _, v := range c.pluginDir {
mpath = append(mpath, filepath.Join(v, "vnodes"))
}

return mpath
}

func (c *config) initCollectorsWatchPaths(opts *cli.Option, env *envConfig) []string {
if env.watchPath == "" {
return opts.WatchPath
Expand Down
1 change: 0 additions & 1 deletion src/go/cmd/godplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func main() {
CollectorsConfigDir: cfg.collectorsDir,
ServiceDiscoveryConfigDir: cfg.serviceDiscoveryDir,
CollectorsConfigWatchPath: cfg.collectorsWatchPath,
VnodesConfigDir: cfg.vnodesDir,
StateFile: cfg.stateFile,
LockDir: cfg.lockDir,
RunModule: opts.Module,
Expand Down
5 changes: 1 addition & 4 deletions src/go/plugin/go.d/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Config struct {
CollectorsConfigDir []string
CollectorsConfigWatchPath []string
ServiceDiscoveryConfigDir []string
VnodesConfigDir []string
StateFile string
LockDir string
ModuleRegistry module.Registry
Expand All @@ -54,7 +53,6 @@ type Agent struct {
CollectorsConfDir multipath.MultiPath
CollectorsConfigWatchPath []string
ServiceDiscoveryConfigDir multipath.MultiPath
VnodesConfigDir multipath.MultiPath

StateFile string
LockDir string
Expand All @@ -81,7 +79,6 @@ func New(cfg Config) *Agent {
CollectorsConfDir: cfg.CollectorsConfigDir,
ServiceDiscoveryConfigDir: cfg.ServiceDiscoveryConfigDir,
CollectorsConfigWatchPath: cfg.CollectorsConfigWatchPath,
VnodesConfigDir: cfg.VnodesConfigDir,
StateFile: cfg.StateFile,
LockDir: cfg.LockDir,
RunModule: cfg.RunModule,
Expand Down Expand Up @@ -201,7 +198,7 @@ func (a *Agent) run(ctx context.Context) {
jobMgr.ConfigDefaults = discCfg.Registry
jobMgr.FnReg = fnMgr

if reg := a.setupVnodeRegistry(); reg != nil && reg.Len() > 0 {
if reg := a.setupVnodeRegistry(); len(reg) > 0 {
jobMgr.Vnodes = reg
}

Expand Down
13 changes: 8 additions & 5 deletions src/go/plugin/go.d/agent/functions/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ type input interface {
}

var stdinInput = func() input {
r := &stdinReader{chLines: make(chan string)}
r := &stdinReader{
linesCh: make(chan string),
}

go r.run()

return r
}()

type stdinReader struct {
chLines chan string
linesCh chan string
}

func (in *stdinReader) run() {
sc := bufio.NewScanner(bufio.NewReader(os.Stdin))

for sc.Scan() {
text := sc.Text()
in.chLines <- text
in.linesCh <- sc.Text()
}
}

func (in *stdinReader) lines() chan string {
return in.chLines
return in.linesCh
}
20 changes: 10 additions & 10 deletions src/go/plugin/go.d/agent/functions/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ FUNCTION UID 1 "fn1 arg1 arg2" 0xFFFF "method=api,role=test"
`,
expected: []Function{
{
key: "FUNCTION",
key: lineFunction,
UID: "UID",
Timeout: time.Second,
Name: "fn1",
Expand All @@ -110,7 +110,7 @@ FUNCTION UID 1 "fn2 arg1 arg2" 0xFFFF "method=api,role=test"
`,
expected: []Function{
{
key: "FUNCTION",
key: lineFunction,
UID: "UID",
Timeout: time.Second,
Name: "fn1",
Expand All @@ -121,7 +121,7 @@ FUNCTION UID 1 "fn2 arg1 arg2" 0xFFFF "method=api,role=test"
Payload: nil,
},
{
key: "FUNCTION",
key: lineFunction,
UID: "UID",
Timeout: time.Second,
Name: "fn2",
Expand All @@ -143,7 +143,7 @@ FUNCTION_PAYLOAD_END
`,
expected: []Function{
{
key: "FUNCTION_PAYLOAD",
key: lineFunctionPayload,
UID: "UID",
Timeout: time.Second,
Name: "fn1",
Expand All @@ -170,7 +170,7 @@ FUNCTION_PAYLOAD_END
`,
expected: []Function{
{
key: "FUNCTION_PAYLOAD",
key: lineFunctionPayload,
UID: "UID",
Timeout: time.Second,
Name: "fn1",
Expand All @@ -181,7 +181,7 @@ FUNCTION_PAYLOAD_END
Payload: []byte("payload line1\npayload line2"),
},
{
key: "FUNCTION_PAYLOAD",
key: lineFunctionPayload,
UID: "UID",
Timeout: time.Second,
Name: "fn2",
Expand Down Expand Up @@ -211,7 +211,7 @@ FUNCTION_PAYLOAD_END
`,
expected: []Function{
{
key: "FUNCTION_PAYLOAD",
key: lineFunctionPayload,
UID: "UID",
Timeout: time.Second,
Name: "fn1",
Expand All @@ -222,7 +222,7 @@ FUNCTION_PAYLOAD_END
Payload: []byte("payload line1\npayload line2"),
},
{
key: "FUNCTION",
key: lineFunction,
UID: "UID",
Timeout: time.Second,
Name: "fn2",
Expand All @@ -233,7 +233,7 @@ FUNCTION_PAYLOAD_END
Payload: nil,
},
{
key: "FUNCTION",
key: lineFunction,
UID: "UID",
Timeout: time.Second,
Name: "fn3",
Expand All @@ -244,7 +244,7 @@ FUNCTION_PAYLOAD_END
Payload: nil,
},
{
key: "FUNCTION_PAYLOAD",
key: lineFunctionPayload,
UID: "UID",
Timeout: time.Second,
Name: "fn4",
Expand Down
14 changes: 10 additions & 4 deletions src/go/plugin/go.d/agent/functions/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import (
"time"
)

const (
lineFunction = "FUNCTION"
lineFunctionPayload = "FUNCTION_PAYLOAD"
lineFunctionPayloadEnd = "FUNCTION_PAYLOAD_END"
)

type Function struct {
key string
UID string
Expand Down Expand Up @@ -49,9 +55,9 @@ func (p *inputParser) parse(line string) (*Function, error) {
}

switch {
case strings.HasPrefix(line, "FUNCTION "):
case strings.HasPrefix(line, lineFunction+" "):
return p.parseFunction(line)
case strings.HasPrefix(line, "FUNCTION_PAYLOAD "):
case strings.HasPrefix(line, lineFunctionPayload+" "):
fn, err := p.parseFunction(line)
if err != nil {
return nil, err
Expand All @@ -66,15 +72,15 @@ func (p *inputParser) parse(line string) (*Function, error) {
}

func (p *inputParser) handlePayloadLine(line string) (*Function, error) {
if line == "FUNCTION_PAYLOAD_END" {
if line == lineFunctionPayloadEnd {
p.readingPayload = false
p.currentFn.Payload = []byte(p.payloadBuf.String())
fn := p.currentFn
p.currentFn = nil
return fn, nil
}

if strings.HasPrefix(line, "FUNCTION") {
if strings.HasPrefix(line, lineFunction) {
p.readingPayload = false
p.currentFn = nil
p.payloadBuf.Reset()
Expand Down
Loading
Loading