diff --git a/README.md b/README.md index 42bdcd3b..1743989f 100644 --- a/README.md +++ b/README.md @@ -58,15 +58,20 @@ Use the inbuilt statsd reporter: ```go import ( "io" - "github.com/cactus/go-statsd-client/statsd" + "github.com/cactus/go-statsd-client/v5/statsd" "github.com/uber-go/tally" tallystatsd "github.com/uber-go/tally/statsd" // ... ) func newScope() (tally.Scope, io.Closer) { - statter, _ := statsd.NewBufferedClient("127.0.0.1:8125", - "stats", 100*time.Millisecond, 1440) + statter, _ := statsd.NewClientWithConfig(&statsd.ClientConfig{ + Address: "127.0.0.1:8125", + Prefix: "stats", + UseBuffered: true, + FlushInterval: 100 * time.Millisecond, + FlushBytes: 1440, + }) reporter := tallystatsd.NewReporter(statter, tallystatsd.Options{ SampleRate: 1.0, diff --git a/go.mod b/go.mod index 39fc33a3..97025ab6 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/uber-go/tally/v4 go 1.15 require ( - github.com/cactus/go-statsd-client/statsd v0.0.0-20200423205355-cb0885a1018c + github.com/cactus/go-statsd-client/v5 v5.0.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.11.0 github.com/prometheus/client_model v0.2.0 diff --git a/go.sum b/go.sum index af3d3d60..5691f567 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cactus/go-statsd-client/statsd v0.0.0-20200423205355-cb0885a1018c h1:HIGF0r/56+7fuIZw2V4isE22MK6xpxWx7BbV8dJ290w= -github.com/cactus/go-statsd-client/statsd v0.0.0-20200423205355-cb0885a1018c/go.mod h1:l/bIBLeOl9eX+wxJAzxS4TveKRtAqlyDpHjhkfO0MEI= +github.com/cactus/go-statsd-client/v5 v5.0.0 h1:KqvIQtc9qt34uq+nu4nd1PwingWfBt/IISgtUQ2nSJk= +github.com/cactus/go-statsd-client/v5 v5.0.0/go.mod h1:COEvJ1E+/E2L4q6QE5CkjWPi4eeDw9maJBMIuMPBZbY= github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -41,6 +41,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= diff --git a/statsd/example/statsd_main.go b/statsd/example/statsd_main.go index dd992326..63cc9e16 100644 --- a/statsd/example/statsd_main.go +++ b/statsd/example/statsd_main.go @@ -25,7 +25,7 @@ import ( "math/rand" "time" - "github.com/cactus/go-statsd-client/statsd" + "github.com/cactus/go-statsd-client/v5/statsd" tally "github.com/uber-go/tally/v4" statsdreporter "github.com/uber-go/tally/v4/statsd" ) diff --git a/statsd/reporter.go b/statsd/reporter.go index bc47c840..3e965581 100644 --- a/statsd/reporter.go +++ b/statsd/reporter.go @@ -23,10 +23,11 @@ package statsd import ( "fmt" "math" + "sort" "strconv" "time" - "github.com/cactus/go-statsd-client/statsd" + statsd "github.com/cactus/go-statsd-client/v5/statsd" tally "github.com/uber-go/tally/v4" ) @@ -73,15 +74,15 @@ func NewReporter(statsd statsd.Statter, opts Options) tally.StatsReporter { } func (r *cactusStatsReporter) ReportCounter(name string, tags map[string]string, value int64) { - r.statter.Inc(name, value, r.sampleRate) + r.statter.Inc(name, value, r.sampleRate, convertTags(tags)...) } func (r *cactusStatsReporter) ReportGauge(name string, tags map[string]string, value float64) { - r.statter.Gauge(name, int64(value), r.sampleRate) + r.statter.Gauge(name, int64(value), r.sampleRate, convertTags(tags)...) } func (r *cactusStatsReporter) ReportTimer(name string, tags map[string]string, interval time.Duration) { - r.statter.TimingDuration(name, interval, r.sampleRate) + r.statter.TimingDuration(name, interval, r.sampleRate, convertTags(tags)...) } func (r *cactusStatsReporter) ReportHistogramValueSamples( @@ -96,7 +97,7 @@ func (r *cactusStatsReporter) ReportHistogramValueSamples( fmt.Sprintf("%s.%s-%s", name, r.valueBucketString(bucketLowerBound), r.valueBucketString(bucketUpperBound)), - samples, r.sampleRate) + samples, r.sampleRate, convertTags(tags)...) } func (r *cactusStatsReporter) ReportHistogramDurationSamples( @@ -111,7 +112,7 @@ func (r *cactusStatsReporter) ReportHistogramDurationSamples( fmt.Sprintf("%s.%s-%s", name, r.durationBucketString(bucketLowerBound), r.durationBucketString(bucketUpperBound)), - samples, r.sampleRate) + samples, r.sampleRate, convertTags(tags)...) } func (r *cactusStatsReporter) valueBucketString( @@ -153,3 +154,18 @@ func (r *cactusStatsReporter) Tagging() bool { func (r *cactusStatsReporter) Flush() { // no-op } + +func convertTags(tags map[string]string) []statsd.Tag { + var keys []string + for k := range tags { + keys = append(keys, k) + } + sort.Strings(keys) + + var statsdTags []statsd.Tag + for _, tk := range keys { + statsdTags = append(statsdTags, statsd.Tag{tk, tags[tk]}) + } + + return statsdTags +}