Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
dyncfgv2
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 committed Feb 15, 2024
1 parent 0036acb commit da5ae82
Show file tree
Hide file tree
Showing 365 changed files with 18,906 additions and 8,895 deletions.
55 changes: 19 additions & 36 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ func serve(a *Agent) {
var wg sync.WaitGroup

var exit bool
var reload bool

for {
ctx, cancel := context.WithCancel(context.Background())
ctx = context.WithValue(ctx, "reload", reload)

wg.Add(1)
go func() { defer wg.Done(); a.run(ctx) }()
Expand Down Expand Up @@ -136,7 +134,6 @@ func serve(a *Agent) {
os.Exit(0)
}

reload = true
time.Sleep(time.Second)
}
}
Expand Down Expand Up @@ -169,7 +166,7 @@ func (a *Agent) run(ctx context.Context) {

discCfg := a.buildDiscoveryConf(enabledModules)

discoveryManager, err := discovery.NewManager(discCfg)
discMgr, err := discovery.NewManager(discCfg)
if err != nil {
a.Error(err)
if isTerminal {
Expand All @@ -178,64 +175,50 @@ func (a *Agent) run(ctx context.Context) {
return
}

functionsManager := functions.NewManager()

jobsManager := jobmgr.NewManager()
jobsManager.PluginName = a.Name
jobsManager.Out = a.Out
jobsManager.Modules = enabledModules

// TODO: API will be changed in https://github.com/netdata/netdata/pull/16702
//if logger.Level.Enabled(slog.LevelDebug) {
// dyncfgDiscovery, _ := dyncfg.NewDiscovery(dyncfg.Config{
// Plugin: a.Name,
// API: netdataapi.New(a.Out),
// Modules: enabledModules,
// ModuleConfigDefaults: discCfg.Registry,
// Functions: functionsManager,
// })
//
// discoveryManager.Add(dyncfgDiscovery)
//
// jobsManager.Dyncfg = dyncfgDiscovery
//}
fnMgr := functions.NewManager()

jobMgr := jobmgr.New()
jobMgr.PluginName = a.Name
jobMgr.Out = a.Out
jobMgr.Modules = enabledModules
jobMgr.FnReg = fnMgr

if reg := a.setupVnodeRegistry(); reg == nil || reg.Len() == 0 {
vnodes.Disabled = true
} else {
jobsManager.Vnodes = reg
jobMgr.Vnodes = reg
}

if a.LockDir != "" {
jobsManager.FileLock = filelock.New(a.LockDir)
jobMgr.FileLock = filelock.New(a.LockDir)
}

var statusSaveManager *filestatus.Manager
var fsMgr *filestatus.Manager
if !isTerminal && a.StateFile != "" {
statusSaveManager = filestatus.NewManager(a.StateFile)
jobsManager.StatusSaver = statusSaveManager
fsMgr = filestatus.NewManager(a.StateFile)
jobMgr.FileStatus = fsMgr
if store, err := filestatus.LoadStore(a.StateFile); err != nil {
a.Warningf("couldn't load state file: %v", err)
} else {
jobsManager.StatusStore = store
jobMgr.FileStatusStore = store
}
}

in := make(chan []*confgroup.Group)
var wg sync.WaitGroup

wg.Add(1)
go func() { defer wg.Done(); functionsManager.Run(ctx) }()
go func() { defer wg.Done(); fnMgr.Run(ctx) }()

wg.Add(1)
go func() { defer wg.Done(); jobsManager.Run(ctx, in) }()
go func() { defer wg.Done(); jobMgr.Run(ctx, in) }()

wg.Add(1)
go func() { defer wg.Done(); discoveryManager.Run(ctx, in) }()
go func() { defer wg.Done(); discMgr.Run(ctx, in) }()

if statusSaveManager != nil {
if fsMgr != nil {
wg.Add(1)
go func() { defer wg.Done(); statusSaveManager.Run(ctx) }()
go func() { defer wg.Done(); fsMgr.Run(ctx) }()
}

wg.Wait()
Expand Down
8 changes: 4 additions & 4 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ func prepareRegistry(mux *sync.Mutex, stats map[string]int, names ...string) mod

func prepareMockModule(name string, mux *sync.Mutex, stats map[string]int) module.Module {
return &module.MockModule{
InitFunc: func() bool {
InitFunc: func() error {
mux.Lock()
defer mux.Unlock()
stats[name+"_init"]++
return true
return nil
},
CheckFunc: func() bool {
CheckFunc: func() error {
mux.Lock()
defer mux.Unlock()
stats[name+"_check"]++
return true
return nil
},
ChartsFunc: func() *module.Charts {
mux.Lock()
Expand Down
93 changes: 0 additions & 93 deletions agent/confgroup/cache.go

This file was deleted.

134 changes: 0 additions & 134 deletions agent/confgroup/cache_test.go

This file was deleted.

Loading

0 comments on commit da5ae82

Please sign in to comment.