From 4f24e8437a6e15619149ec36492cf15ec9c33a39 Mon Sep 17 00:00:00 2001 From: Timothy Yen Date: Wed, 29 Sep 2021 11:52:47 -0700 Subject: [PATCH] Alias types defined in types.go to uber tally types This eases using the brex tally scope as uber tally scopes in 3p libraries that expect a uber tally scope --- go.mod | 1 + go.sum | 4 +- types.go | 143 ++++++++++--------------------------------------------- 3 files changed, 27 insertions(+), 121 deletions(-) diff --git a/go.mod b/go.mod index db9eb627..c431b15c 100644 --- a/go.mod +++ b/go.mod @@ -8,4 +8,5 @@ require ( github.com/prometheus/client_golang v1.6.0 github.com/prometheus/client_model v0.2.0 github.com/stretchr/testify v1.4.0 + github.com/uber-go/tally v3.3.17+incompatible ) diff --git a/go.sum b/go.sum index 11fc5536..6e67991e 100644 --- a/go.sum +++ b/go.sum @@ -2,7 +2,6 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -76,10 +75,11 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/uber-go/tally v3.3.17+incompatible h1:nFHIuW3VQ22wItiE9kPXic8dEgExWOsVOHwpmoIvsMw= +github.com/uber-go/tally v3.3.17+incompatible/go.mod h1:YDTIBxdXyOU/sCWilKB4bgyufu1cEi0jdVnRdxvjnmU= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/types.go b/types.go index 76d3749e..e5c218b8 100644 --- a/types.go +++ b/types.go @@ -21,137 +21,42 @@ package tally import ( - "fmt" - "sort" "time" -) - -// Scope is a namespace wrapper around a stats reporter, ensuring that -// all emitted values have a given prefix or set of tags. -// -// IMPORTANT: When using Prometheus reporters, users must take care to -// not create metrics from both parent scopes and subscopes -// that have the same metric name but different tag keys, -// as metric allocation will panic. -type Scope interface { - // Counter returns the Counter object corresponding to the name. - Counter(name string) Counter - - // Gauge returns the Gauge object corresponding to the name. - Gauge(name string) Gauge - - // Timer returns the Timer object corresponding to the name. - Timer(name string) Timer - - // Histogram returns the Histogram object corresponding to the name. - // To use default value and duration buckets configured for the scope - // simply pass tally.DefaultBuckets or nil. - // You can use tally.ValueBuckets{x, y, ...} for value buckets. - // You can use tally.DurationBuckets{x, y, ...} for duration buckets. - // You can use tally.MustMakeLinearValueBuckets(start, width, count) for linear values. - // You can use tally.MustMakeLinearDurationBuckets(start, width, count) for linear durations. - // You can use tally.MustMakeExponentialValueBuckets(start, factor, count) for exponential values. - // You can use tally.MustMakeExponentialDurationBuckets(start, factor, count) for exponential durations. - Histogram(name string, buckets Buckets) Histogram - - // Tagged returns a new child scope with the given tags and current tags. - Tagged(tags map[string]string) Scope - // SubScope returns a new child scope appending a further name prefix. - SubScope(name string) Scope - - // Capabilities returns a description of metrics reporting capabilities. - Capabilities() Capabilities -} - -// Counter is the interface for emitting counter type metrics. -type Counter interface { - // Inc increments the counter by a delta. - Inc(delta int64) -} - -// Gauge is the interface for emitting gauge metrics. -type Gauge interface { - // Update sets the gauges absolute value. - Update(value float64) -} + ubertally "github.com/uber-go/tally" +) -// Timer is the interface for emitting timer metrics. -type Timer interface { - // Record a specific duration directly. - Record(value time.Duration) +// Scope aliases to uber's Scope +type Scope = ubertally.Scope - // Start gives you back a specific point in time to report via Stop. - Start() Stopwatch -} +// Counter aliases to uber's Counter +type Counter = ubertally.Counter -// Histogram is the interface for emitting histogram metrics -type Histogram interface { - // RecordValue records a specific value directly. - // Will use the configured value buckets for the histogram. - RecordValue(value float64) +// Gauge aliases to uber's Gauge +type Gauge = ubertally.Gauge - // RecordDuration records a specific duration directly. - // Will use the configured duration buckets for the histogram. - RecordDuration(value time.Duration) +// Timer aliases to uber's Timer +type Timer = ubertally.Timer - // Start gives you a specific point in time to then record a duration. - // Will use the configured duration buckets for the histogram. - Start() Stopwatch -} +// Histogram aliases to uber's Histogram +type Histogram = ubertally.Histogram -// Stopwatch is a helper for simpler tracking of elapsed time, use the -// Stop() method to report time elapsed since its created back to the -// timer or histogram. -type Stopwatch struct { - start time.Time - recorder StopwatchRecorder -} +// Stopwatch aliases to uber's Stopwatch +type Stopwatch = ubertally.Stopwatch -// NewStopwatch creates a new immutable stopwatch for recording the start -// time to a stopwatch reporter. +// NewStopwatch aliases to uber's NewStopwatch func NewStopwatch(start time.Time, r StopwatchRecorder) Stopwatch { - return Stopwatch{start: start, recorder: r} + return ubertally.NewStopwatch(start, r) } -// Stop reports time elapsed since the stopwatch start to the recorder. -func (sw Stopwatch) Stop() { - sw.recorder.RecordStopwatch(sw.start) -} - -// StopwatchRecorder is a recorder that is called when a stopwatch is -// stopped with Stop(). -type StopwatchRecorder interface { - RecordStopwatch(stopwatchStart time.Time) -} +// StopwatchRecorder aliases to uber's StopwatchRecorder +type StopwatchRecorder = ubertally.StopwatchRecorder -// Buckets is an interface that can represent a set of buckets -// either as float64s or as durations. -type Buckets interface { - fmt.Stringer - sort.Interface +// Buckets aliases to uber's Buckets +type Buckets = ubertally.Buckets - // AsValues returns a representation of the buckets as float64s - AsValues() []float64 +// BucketPair aliases to uber's BucketPair +type BucketPair = ubertally.BucketPair - // AsDurations returns a representation of the buckets as time.Durations - AsDurations() []time.Duration -} - -// BucketPair describes the lower and upper bounds -// for a derived bucket from a buckets set. -type BucketPair interface { - LowerBoundValue() float64 - UpperBoundValue() float64 - LowerBoundDuration() time.Duration - UpperBoundDuration() time.Duration -} - -// Capabilities is a description of metrics reporting capabilities. -type Capabilities interface { - // Reporting returns whether the reporter has the ability to actively report. - Reporting() bool - - // Tagging returns whether the reporter has the capability for tagged metrics. - Tagging() bool -} +// Capabilities aliases to uber's Capabilities +type Capabilities = ubertally.Capabilities