Skip to content

Commit 67afe45

Browse files
committed
Expose the global default metrics
This should make it easier to test code that uses go-metrics. In tests the code can be passed a different instance of Metrics, and in production code paths it can use the global Metrics returned from Default(). Without this change patching the global can cause flaky tests when other tests attempt to emit metrics at the same time.
1 parent 3901aee commit 67afe45

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

start.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sync/atomic"
77
"time"
88

9-
"github.com/hashicorp/go-immutable-radix"
9+
iradix "github.com/hashicorp/go-immutable-radix"
1010
)
1111

1212
// Config is used to configure metrics settings
@@ -48,6 +48,11 @@ func init() {
4848
globalMetrics.Store(&Metrics{sink: &BlackholeSink{}})
4949
}
5050

51+
// Default returns the shared global metrics instance.
52+
func Default() *Metrics {
53+
return globalMetrics.Load().(*Metrics)
54+
}
55+
5156
// DefaultConfig provides a sane default configuration
5257
func DefaultConfig(serviceName string) *Config {
5358
c := &Config{

0 commit comments

Comments
 (0)