Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default reporting interval #226

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const (
// OmitInternalMetrics turns off internal metrics submission.
OmitInternalMetrics

_defaultInitialSliceSize = 16
_defaultInitialSliceSize = 16
_defaultReportingInterval = 2 * time.Second
)

var (
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading