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

Add ReportableScope interface for use with pull interface #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ func NewTestScope(
return newRootScope(ScopeOptions{Prefix: prefix, Tags: tags}, 0)
}

// NewReportableScope creates a new ReportableScope with a set of options.
// Must provide either a StatsReporter or a CachedStatsReporter.
func NewReportableScope(opts ScopeOptions) ReportableScope {
s := newRootScope(opts, 0)
return s
}

func newRootScope(opts ScopeOptions, interval time.Duration) *scope {
sanitizer := NewNoOpSanitizer()
if o := opts.SanitizeOptions; o != nil {
Expand Down Expand Up @@ -181,6 +188,10 @@ func newRootScope(opts ScopeOptions, interval time.Duration) *scope {
return s
}

func (s *scope) Report() {
s.reportLoopRun()
}

// report dumps all aggregated stats into the reporter. Should be called automatically by the root scope periodically.
func (s *scope) report(r StatsReporter) {
s.cm.RLock()
Expand Down
8 changes: 8 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ type Scope interface {
Capabilities() Capabilities
}

// ReportableScope is a wrapper arround Scope with Report method for manual reportig data.
type ReportableScope interface {
Scope

// Manual report metrics from scope and subscopes to reporter
Report()
}

// Counter is the interface for emitting counter type metrics.
type Counter interface {
// Inc increments the counter by a delta.
Expand Down