Skip to content

Commit

Permalink
Enhanced Gauge API (uber-go#106), added files for go mod
Browse files Browse the repository at this point in the history
  • Loading branch information
mgkanani committed Jun 29, 2019
1 parent f266f90 commit 6f3c35b
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/uber-go/tally

require (
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
github.com/cactus/go-statsd-client v0.0.0-20180119084216-138b925ccdf6
github.com/golang/protobuf v0.0.0-20180715082332-14aad3d5ea4c // indirect
github.com/m3db/prometheus_client_golang v0.0.0-20180517030325-8ae269d24972
github.com/m3db/prometheus_client_model v0.0.0-20180517145114-8b2299a4bf7d
github.com/m3db/prometheus_common v0.0.0-20180517030744-25aaa3dff79b // indirect
github.com/m3db/prometheus_procfs v0.0.0-20170128160123-1878d9fbb537 // indirect
github.com/matttproud/golang_protobuf_extensions v0.0.0-20160424113007-c12348ce28de // indirect
github.com/stretchr/testify v1.3.0
go.uber.org/atomic v0.0.0-20180501173809-1ea20fb1cbb1
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19
gopkg.in/yaml.v2 v2.0.0-20180328195020-5420a8b6744d
)
30 changes: 30 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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/cactus/go-statsd-client v0.0.0-20180119084216-138b925ccdf6 h1:5OhT0at22K1HcjHnmuN2aFrgzg6crKU7TSZz4L/Tzs0=
github.com/cactus/go-statsd-client v0.0.0-20180119084216-138b925ccdf6/go.mod h1:cMRcwZDklk7hXp+Law83urTHUiHMzCev/r4JMYr/zU0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v0.0.0-20180715082332-14aad3d5ea4c h1:By+Kfmji+8gwiFGR0frGerZ3ie1O1WzAmj//2oXMrJU=
github.com/golang/protobuf v0.0.0-20180715082332-14aad3d5ea4c/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/m3db/prometheus_client_golang v0.0.0-20180517030325-8ae269d24972 h1:Pm9VRu7yJPYtidjxVov7S082D/atU6M02OemWBYYFl4=
github.com/m3db/prometheus_client_golang v0.0.0-20180517030325-8ae269d24972/go.mod h1:8R/f1xYhXWq59KD/mbRqoBulXejss7vYtYzWmruNUwI=
github.com/m3db/prometheus_client_model v0.0.0-20180517145114-8b2299a4bf7d h1:BtNPRz2kmh42OAVYjsOBjty2wE0FaIh7aPVtFNPcF48=
github.com/m3db/prometheus_client_model v0.0.0-20180517145114-8b2299a4bf7d/go.mod h1:Qfsxn+LypxzF+lNhak7cF7k0zxK7uB/ynGYoj80zcD4=
github.com/m3db/prometheus_common v0.0.0-20180517030744-25aaa3dff79b h1:DEtcqizQ9PnY4xudqHyze5F89jijy33fnPYYSCCYPXY=
github.com/m3db/prometheus_common v0.0.0-20180517030744-25aaa3dff79b/go.mod h1:EBmDQaMAy4B8i+qsg1wMXAelLNVbp49i/JOeVszQ/rs=
github.com/m3db/prometheus_procfs v0.0.0-20170128160123-1878d9fbb537 h1:01rKDALtW0OlTAjLYnNNQYETtPDTTxIX7iyJ1Nnsn3E=
github.com/m3db/prometheus_procfs v0.0.0-20170128160123-1878d9fbb537/go.mod h1:N8lv8fLh3U3koZx1Bnisj60GYUMDpWb09x1R+dmMOJo=
github.com/matttproud/golang_protobuf_extensions v0.0.0-20160424113007-c12348ce28de h1:TvEbtJWapv7jxI4C94AukCEq3o2arMqbgB2Vq6AjL2w=
github.com/matttproud/golang_protobuf_extensions v0.0.0-20160424113007-c12348ce28de/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
go.uber.org/atomic v0.0.0-20180501173809-1ea20fb1cbb1 h1:gpebDMg01ZrsWut7YY/Glag6rId/M6fQUnH31T9wEw4=
go.uber.org/atomic v0.0.0-20180501173809-1ea20fb1cbb1/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19 h1:WB265cn5OpO+hK3pikC9hpP1zI/KTwmyMFKloW9eOVc=
gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19/go.mod h1:o4V0GXN9/CAmCsvJ0oXYZvrZOe7syiDZSN1GWGZTGzc=
gopkg.in/yaml.v2 v2.0.0-20180328195020-5420a8b6744d h1:Oj/i2hmKXL5S0k5gnQUUa/HsP/3A5j/j3Zj8ASGTEvY=
gopkg.in/yaml.v2 v2.0.0-20180328195020-5420a8b6744d/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
9 changes: 9 additions & 0 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ func (g *gauge) Update(v float64) {
atomic.StoreUint64(&g.updated, 1)
}

func (g *gauge) Add(v float64) {
v += math.Float64frombits(atomic.LoadUint64(&g.curr))
g.Update(v)
}

func (g *gauge) Sub(v float64) {
g.Add(-v)
}

func (g *gauge) value() float64 {
return math.Float64frombits(atomic.LoadUint64(&g.curr))
}
Expand Down
8 changes: 8 additions & 0 deletions stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ func TestGauge(t *testing.T) {
gauge.report("", nil, r)
assert.Equal(t, float64(42), r.last)

gauge.Add(4.2)
gauge.report("", nil, r)
assert.Equal(t, float64(46.2), r.last)

gauge.Sub(-4)
gauge.report("", nil, r)
assert.Equal(t, float64(50.2), r.last)

gauge.Update(1234)
gauge.Update(5678)
gauge.report("", nil, r)
Expand Down
6 changes: 6 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ type Counter interface {
type Gauge interface {
// Update sets the gauges absolute value.
Update(value float64)

// Add updates gauges absolute value by adding 'value' to current value
Add(value float64)

// Sub updates gauges absolute value by subtracting 'value' from current value
Sub(value float64)
}

// Timer is the interface for emitting timer metrics.
Expand Down

0 comments on commit 6f3c35b

Please sign in to comment.