make collector a singleton

This commit is contained in:
Ahrav Dutta 2024-11-08 14:32:16 -08:00
parent 9722ad7a41
commit a72e25accf
2 changed files with 8 additions and 1 deletions

View file

@ -29,6 +29,13 @@ type collector struct {
bucketsPerRole *prometheus.GaugeVec
}
var metricsInstance metricsCollector
func init() { metricsInstance = newS3MetricsCollector() }
// getMetricsCollector returns the singleton metrics collector instance..
func getMetricsCollector() metricsCollector { return metricsInstance }
func newS3MetricsCollector() metricsCollector {
return &collector{
objectsScanned: promauto.NewCounterVec(prometheus.CounterOpts{

View file

@ -99,7 +99,7 @@ func (s *Source) Init(
if err != nil {
return err
}
s.metricsCollector = newS3MetricsCollector()
s.metricsCollector = getMetricsCollector()
s.setMaxObjectSize(conn.GetMaxObjectSize())