From 9d7217766f1ffd27e3c8b440442ed03f0eafe4cf Mon Sep 17 00:00:00 2001 From: Aleksey Ivanov Date: Mon, 13 Aug 2018 09:51:24 +0300 Subject: [PATCH] Add ReportableScope interface for use in pull models --- scope.go | 11 +++++++++++ types.go | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/scope.go b/scope.go index f8ff2f00..25df4b7e 100644 --- a/scope.go +++ b/scope.go @@ -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 { @@ -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() diff --git a/types.go b/types.go index 12ab0db4..386642ab 100644 --- a/types.go +++ b/types.go @@ -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.