feat(go.d): allow to debug a specific job (#20394)
Ilya Mashchenko committed
Jun 2, 2025 at 16:12 UTC
1578ef73deb803e7429ceb83c546f4be6ceaa4d9
4 files changed
+15
src/go/cmd/godplugin/main.go
+1
@@ -55,6 +55,7 @@ func main() {
55
CollectorsConfigWatchPath: cfg.collectorsWatchPath,
56
VarLibDir: cfg.varLibDir,
57
RunModule: opts.Module,
58
+ RunJob: opts.Job,
59
MinUpdateEvery: opts.UpdateEvery,
60
})
61
src/go/plugin/go.d/agent/agent.go
+6
@@ -38,6 +38,7 @@ type Config struct {
38
VarLibDir string
39
ModuleRegistry module.Registry
40
RunModule string
41
+ RunJob []string
42
MinUpdateEvery int
43
}
44
@@ -55,6 +56,7 @@ type Agent struct {
56
VarLibDir string
57
58
RunModule string
59
+ RunJob []string
60
MinUpdateEvery int
61
62
ModuleRegistry module.Registry
@@ -78,6 +80,7 @@ func New(cfg Config) *Agent {
80
CollectorsConfigWatchPath: cfg.CollectorsConfigWatchPath,
81
VarLibDir: cfg.VarLibDir,
82
RunModule: cfg.RunModule,
83
+ RunJob: cfg.RunJob,
84
MinUpdateEvery: cfg.MinUpdateEvery,
85
ModuleRegistry: module.DefaultRegistry,
86
Out: safewriter.Stdout,
@@ -197,6 +200,9 @@ func (a *Agent) run(ctx context.Context) {
200
jobMgr.Out = a.Out
201
jobMgr.VarLibDir = a.VarLibDir
202
jobMgr.Modules = enabledModules
203
+ if a.RunModule != "" && a.RunModule != "all" {
204
+ jobMgr.RunJob = a.RunJob
205
+ }
206
jobMgr.ConfigDefaults = discCfg.Registry
207
jobMgr.FnReg = fnMgr
208
src/go/plugin/go.d/agent/jobmgr/manager.go
+7
@@ -8,6 +8,7 @@ import (
8
"io"
9
"log/slog"
10
"os"
11
+ "slices"
12
"strings"
13
"sync"
14
"time"
@@ -59,6 +60,7 @@ type Manager struct {
60
PluginName string
61
Out io.Writer
62
Modules module.Registry
63
+ RunJob []string
64
ConfigDefaults confgroup.Registry
65
VarLibDir string
66
FnReg FunctionRegistry
@@ -130,6 +132,11 @@ func (m *Manager) runProcessConfGroups(in chan []*confgroup.Group) {
132
for _, gr := range groups {
133
a, r := m.discoveredConfigs.add(gr)
134
m.Debugf("received configs: %d/+%d/-%d ('%s')", len(gr.Configs), len(a), len(r), gr.Source)
135
+ if len(m.RunJob) > 0 {
136
+ a = slices.DeleteFunc(a, func(config confgroup.Config) bool {
137
+ return !slices.ContainsFunc(m.RunJob, func(name string) bool { return config.Name() == name })
138
+ })
139
+ }
140
sendConfigs(m.ctx, m.rmCh, r...)
141
sendConfigs(m.ctx, m.addCh, a...)
142
}
src/go/plugin/go.d/cli/cli.go
+1
@@ -14,6 +14,7 @@ import (
14
type Option struct {
15
UpdateEvery int
16
Module string `short:"m" long:"modules" description:"module name to run" default:"all"`
17
+ Job []string `short:"j" long:"job" description:"job name to run"`
18
ConfDir []string `short:"c" long:"config-dir" description:"config dir to read"`
19
WatchPath []string `short:"w" long:"watch-path" description:"config path to watch"`
20
Debug bool `short:"d" long:"debug" description:"debug mode"`