| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package jobmgr |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "strings" |
| 8 | |
| 9 | "github.com/netdata/netdata/go/plugins/plugin/framework/confgroup" |
| 10 | "github.com/netdata/netdata/go/plugins/plugin/framework/dyncfg" |
| 11 | "github.com/netdata/netdata/go/plugins/plugin/framework/functions" |
| 12 | ) |
| 13 | |
| 14 | func (m *Manager) dyncfgSecretStorePrefixValue() string { |
| 15 | return m.secretsCtl.Prefix() |
| 16 | } |
| 17 | |
| 18 | func (m *Manager) dyncfgSecretStoreExec(fn dyncfg.Function) { |
| 19 | if fn.Command() == dyncfg.CommandSchema { |
| 20 | m.dyncfgSecretStoreSeqExec(fn) |
| 21 | return |
| 22 | } |
| 23 | m.enqueueDyncfgFunction(fn) |
| 24 | } |
| 25 | |
| 26 | func (m *Manager) dyncfgSecretStoreSeqExec(fn dyncfg.Function) { |
| 27 | m.secretsCtl.SeqExec(fn) |
| 28 | } |
| 29 | |
| 30 | func (m *Manager) restartDependentCollectorJob(fullName string) error { |
| 31 | entry, ok := m.lookupExposedByFullName(fullName) |
| 32 | if !ok { |
| 33 | return fmt.Errorf("job '%s' is not exposed", fullName) |
| 34 | } |
| 35 | |
| 36 | oldStatus := entry.Status |
| 37 | switch oldStatus { |
| 38 | case dyncfg.StatusRunning, dyncfg.StatusFailed: |
| 39 | default: |
| 40 | return fmt.Errorf("job '%s' restart is not allowed in '%s' state", fullName, oldStatus) |
| 41 | } |
| 42 | |
| 43 | m.collectorCallbacks.Stop(entry.Cfg) |
| 44 | |
| 45 | if err := m.collectorCallbacks.Start(entry.Cfg); err != nil { |
| 46 | entry.Status = dyncfg.StatusFailed |
| 47 | m.collectorHandler.NotifyJobStatus(entry.Cfg, dyncfg.StatusFailed) |
| 48 | m.collectorCallbacks.OnStatusChange(entry, oldStatus, dyncfg.NewFunction(functions.Function{})) |
| 49 | return fmt.Errorf("job '%s' restart failed: %w", fullName, err) |
| 50 | } |
| 51 | |
| 52 | entry.Status = dyncfg.StatusRunning |
| 53 | m.collectorHandler.NotifyJobStatus(entry.Cfg, dyncfg.StatusRunning) |
| 54 | m.collectorCallbacks.OnStatusChange(entry, oldStatus, dyncfg.NewFunction(functions.Function{})) |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | func (m *Manager) lookupExposedByFullName(fullName string) (*dyncfg.Entry[confgroup.Config], bool) { |
| 59 | fullName = strings.TrimSpace(fullName) |
| 60 | if fullName == "" { |
| 61 | return nil, false |
| 62 | } |
| 63 | return m.collectorExposed.LookupByKey(fullName) |
| 64 | } |