diff --git a/scope.go b/scope.go index 1418348d..0b301040 100644 --- a/scope.go +++ b/scope.go @@ -39,7 +39,8 @@ const ( // OmitInternalMetrics turns off internal metrics submission. OmitInternalMetrics - _defaultInitialSliceSize = 16 + _defaultInitialSliceSize = 16 + _defaultReportingInterval = 2 * time.Second ) var ( @@ -124,6 +125,12 @@ func NewRootScope(opts ScopeOptions, interval time.Duration) (Scope, io.Closer) return s, s } +// NewRootScopeWithDefaultInterval invokes NewRootScope with the default +// reporting interval of 2s. +func NewRootScopeWithDefaultInterval(opts ScopeOptions) (Scope, io.Closer) { + return NewRootScope(opts, _defaultReportingInterval) +} + // NewTestScope creates a new Scope without a stats reporter with the // given prefix and adds the ability to take snapshots of metrics emitted // to it. diff --git a/scope_test.go b/scope_test.go index 70d91aaa..a439576d 100644 --- a/scope_test.go +++ b/scope_test.go @@ -395,6 +395,26 @@ func TestWriteReportLoop(t *testing.T) { r.WaitAll() } +func TestWriteReportLoopDefaultInterval(t *testing.T) { + r := newTestStatsReporter() + s, closer := NewRootScopeWithDefaultInterval( + ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, + ) + defer closer.Close() + + r.cg.Add(1) + s.Counter("bar").Inc(1) + r.gg.Add(1) + s.Gauge("zed").Update(1) + r.tg.Add(1) + s.Timer("ticky").Record(time.Millisecond * 175) + r.hg.Add(1) + s.Histogram("baz", MustMakeLinearValueBuckets(0, 10, 10)). + RecordValue(42.42) + + r.WaitAll() +} + func TestCachedReportLoop(t *testing.T) { r := newTestStatsReporter() s, closer := NewRootScope(ScopeOptions{CachedReporter: r, MetricsOption: OmitInternalMetrics}, 10)