diff options
author | David Štrop <[email protected]> | 2021-03-20 02:59:33 +0100 |
---|---|---|
committer | David Štrop <[email protected]> | 2021-03-20 02:59:33 +0100 |
commit | c8f3b79de529b85b4910157f2cafbc25349ad8de (patch) | |
tree | 6d3db5c8a3e477420c11b6d8b3cd57c36b652281 /plugins/metrics | |
parent | bd91ca0f3e444405f0f6cf9d1dabbeef93de2d85 (diff) |
fix(metrics): remove statsProvider from metrics collectors sync.Map
Signed-off-by: David Štrop <[email protected]>
Diffstat (limited to 'plugins/metrics')
-rw-r--r-- | plugins/metrics/plugin.go | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/plugins/metrics/plugin.go b/plugins/metrics/plugin.go index fefe92bd..651a2475 100644 --- a/plugins/metrics/plugin.go +++ b/plugins/metrics/plugin.go @@ -23,11 +23,6 @@ const ( maxHeaderSize = 1024 * 1024 * 100 // 104MB ) -type statsProvider struct { - collectors []prometheus.Collector - name string -} - // Plugin to manage application metrics using Prometheus. type Plugin struct { cfg *Config @@ -74,16 +69,14 @@ func (m *Plugin) Init(cfg config.Configurer, log logger.Logger) error { // Register invocation will be later in the Serve method for k, v := range collectors { - m.collectors.Store(k, statsProvider{ - collectors: []prometheus.Collector{v}, - name: k, - }) + m.collectors.Store(k, v) } return nil } // Register new prometheus collector. -func (m *Plugin) Register(c prometheus.Collector) error { +func (m *Plugin) Register(c +) error { return m.registry.Register(c) } @@ -92,13 +85,11 @@ func (m *Plugin) Serve() chan error { errCh := make(chan error, 1) m.collectors.Range(func(key, value interface{}) bool { // key - name - // value - statsProvider struct - c := value.(statsProvider) - for _, v := range c.collectors { - if err := m.registry.Register(v); err != nil { - errCh <- err - return false - } + // value - prometheus.Collector + c := value.(prometheus.Collector) + if err := m.registry.Register(c); err != nil { + errCh <- err + return false } return true @@ -211,10 +202,13 @@ func (m *Plugin) Collects() []interface{} { // Collector returns application specific collector by name or nil if collector not found. func (m *Plugin) AddStatProvider(name endure.Named, stat StatProvider) error { - m.collectors.Store(name.Name(), statsProvider{ - collectors: stat.MetricsCollector(), - name: name.Name(), - }) + for _, c := range stat.MetricsCollector() { + err := m.registry.Register(c) + if err != nil { + return err + } + } + return nil } |