Skip to content

Commit

Permalink
Add ReportableScope interface for use in pull models
Browse files Browse the repository at this point in the history
  • Loading branch information
Intar committed Aug 13, 2018
1 parent d0a004a commit 9d72177
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit 9d72177

Please sign in to comment.