Skip to content

Commit 45632ea

Browse files
author
Aleksey Ivanov
committed
Add ReportableScope interface for use in pull models
1 parent d0a004a commit 45632ea

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

scope.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ func NewTestScope(
120120
return newRootScope(ScopeOptions{Prefix: prefix, Tags: tags}, 0)
121121
}
122122

123+
// NewReportableScope creates a new ReportableScope with a set of options.
124+
// Must provide either a StatsReporter or a CachedStatsReporter.
125+
func NewReportableScope(opts ScopeOptions) ReportableScope {
126+
s := newRootScope(opts, 0)
127+
return s
128+
}
129+
123130
func newRootScope(opts ScopeOptions, interval time.Duration) *scope {
124131
sanitizer := NewNoOpSanitizer()
125132
if o := opts.SanitizeOptions; o != nil {
@@ -181,6 +188,10 @@ func newRootScope(opts ScopeOptions, interval time.Duration) *scope {
181188
return s
182189
}
183190

191+
func (s *scope) Report() {
192+
s.reportLoopRun()
193+
}
194+
184195
// report dumps all aggregated stats into the reporter. Should be called automatically by the root scope periodically.
185196
func (s *scope) report(r StatsReporter) {
186197
s.cm.RLock()

types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ type Scope interface {
5959
Capabilities() Capabilities
6060
}
6161

62+
// ReportableScope is a wrapper arround Scope with Report method for manual reportig data.
63+
type ReportableScope interface {
64+
Scope
65+
66+
// Manual report metrics from scope and subscopes to reporter
67+
Report()
68+
}
69+
6270
// Counter is the interface for emitting counter type metrics.
6371
type Counter interface {
6472
// Inc increments the counter by a delta.

0 commit comments

Comments
 (0)