github.com/rudderlabs/rudder-go-kit@v0.30.0/stats/metric/manager.go (about)

     1  /*
     2  Package metric implements an abstraction for safely managing metrics in concurrent environments.
     3  */
     4  package metric
     5  
     6  const (
     7  	PublishedMetrics string = "published_metrics"
     8  )
     9  
    10  func NewManager() Manager {
    11  	return &manager{
    12  		registries: map[string]Registry{
    13  			PublishedMetrics: NewRegistry(),
    14  		},
    15  	}
    16  }
    17  
    18  var Instance Manager = NewManager()
    19  
    20  // Manager is the entry-point for retrieving metric registries
    21  type Manager interface {
    22  	// GetRegistry gets a registry by its key
    23  	GetRegistry(key string) Registry
    24  	// Reset cleans all registries
    25  	Reset()
    26  }
    27  
    28  type manager struct {
    29  	registries map[string]Registry
    30  }
    31  
    32  func (r *manager) GetRegistry(key string) Registry {
    33  	return r.registries[key]
    34  }
    35  
    36  func (r *manager) Reset() {
    37  	for key := range r.registries {
    38  		r.registries[key] = NewRegistry()
    39  	}
    40  }