Skip to content

Commit

Permalink
(rcrowley#86) Add UnregisterAll to Registry and StandardRegistry
Browse files Browse the repository at this point in the history
This new interface method and its standard implementation will make it
easier to test libraries that depend on go-metrics and assume the
default registry (which is analogous to the relationship between expvar
and http.DefaultServeMux).
  • Loading branch information
rcrowley committed Nov 8, 2014
1 parent 6f41298 commit dee209f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Registry interface {

// Unregister the metric with the given name.
Unregister(string)

// Unregister all metrics. (Mostly for testing.)
UnregisterAll()
}

// The standard implementation of a Registry is a mutex-protected map
Expand Down Expand Up @@ -112,6 +115,15 @@ func (r *StandardRegistry) Unregister(name string) {
delete(r.metrics, name)
}

// Unregister all metrics. (Mostly for testing.)
func (r *StandardRegistry) UnregisterAll() {
r.mutex.Lock()
defer r.mutex.Unlock()
for name, _ := range r.metrics {
delete(r.metrics, name)
}
}

func (r *StandardRegistry) register(name string, i interface{}) error {
if _, ok := r.metrics[name]; ok {
return DuplicateMetric(name)
Expand Down

0 comments on commit dee209f

Please sign in to comment.