diff --git a/collector/collector.go b/collector/collector.go index b142a55fa9..8886a44fe4 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -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 { @@ -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 }