|
@@ -41,6 +41,9 @@ type Registry interface {
|
|
|
|
|
|
|
|
// Unregister the metric with the given name.
|
|
// Unregister the metric with the given name.
|
|
|
Unregister(string)
|
|
Unregister(string)
|
|
|
|
|
+
|
|
|
|
|
+ // Unregister all metrics. (Mostly for testing.)
|
|
|
|
|
+ UnregisterAll()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// The standard implementation of a Registry is a mutex-protected map
|
|
// The standard implementation of a Registry is a mutex-protected map
|
|
@@ -112,6 +115,15 @@ func (r *StandardRegistry) Unregister(name string) {
|
|
|
delete(r.metrics, name)
|
|
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 {
|
|
func (r *StandardRegistry) register(name string, i interface{}) error {
|
|
|
if _, ok := r.metrics[name]; ok {
|
|
if _, ok := r.metrics[name]; ok {
|
|
|
return DuplicateMetric(name)
|
|
return DuplicateMetric(name)
|