Skip to content

Commit

Permalink
Remove caching of collectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdurham committed Oct 3, 2023
1 parent d4879a5 commit 69c6eb3
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ const (
)

var (
factories = make(map[string]func(config *NodeCollectorConfig, logger log.Logger) (Collector, error))
initiatedCollectorsMtx = sync.Mutex{}
initiatedCollectors = make(map[string]Collector)
collectorStateGlobal = make(map[string]bool)
collectorFlagState = make(map[string]*bool)
availableCollectors = make([]string, 0)
forcedCollectors = map[string]bool{} // collectors which have been explicitly enabled or disabled
factories = make(map[string]func(config *NodeCollectorConfig, logger log.Logger) (Collector, error))
collectorStateGlobal = make(map[string]bool)
collectorFlagState = make(map[string]*bool)
availableCollectors = make([]string, 0)
forcedCollectors = map[string]bool{} // collectors which have been explicitly enabled or disabled
)

func GetDefaults() map[string]bool {
Expand Down Expand Up @@ -141,22 +139,16 @@ func NewNodeCollector(config *NodeCollectorConfig, enabledCollectors map[string]
f[filter] = true
}
collectors := make(map[string]Collector)
initiatedCollectorsMtx.Lock()
defer initiatedCollectorsMtx.Unlock()

for key, enabled := range enabledCollectors {
if !enabled || (len(f) > 0 && !f[key]) {
continue
}
if collector, ok := initiatedCollectors[key]; ok {
collectors[key] = collector
} else {
collector, err := factories[key](config, log.With(logger, "collector", key))
if err != nil {
return nil, err
}
collectors[key] = collector
initiatedCollectors[key] = collector
collector, err := factories[key](config, log.With(logger, "collector", key))
if err != nil {
return nil, err
}
collectors[key] = collector
}
return &NodeCollector{Collectors: collectors, logger: logger}, nil
}
Expand Down

0 comments on commit 69c6eb3

Please sign in to comment.