Skip to content

Commit af57a97

Browse files
Merge pull request #13 from istreamlabs/upgrade-dd-client
Upgrade DataDog client to 3.x, add support for Distribution()
2 parents 413bd8b + 8b9db6d commit af57a97

File tree

13 files changed

+86
-78
lines changed

13 files changed

+86
-78
lines changed

Gopkg.lock

Lines changed: 0 additions & 53 deletions
This file was deleted.

Gopkg.toml

Lines changed: 0 additions & 10 deletions
This file was deleted.

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module github.com/istreamlabs/go-metrics
33
go 1.12
44

55
require (
6-
github.com/DataDog/datadog-go v2.3.0+incompatible
7-
github.com/mattn/go-colorable v0.0.9
8-
github.com/mattn/go-isatty v0.0.3
6+
github.com/DataDog/datadog-go v3.4.1+incompatible
7+
github.com/mattn/go-colorable v0.1.6 // indirect
8+
github.com/mattn/go-isatty v0.0.12
99
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
10-
golang.org/x/sys v0.0.0-20180314180151-89ac7f292d17
10+
github.com/stretchr/testify v1.5.1 // indirect
11+
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
1112
)

go.sum

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
github.com/DataDog/datadog-go v2.2.0+incompatible h1:V5BKkxACZLjzHjSgBbr2gvLA2Ae49yhc6CSY7MLy5k4=
2-
github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
3-
github.com/DataDog/datadog-go v2.3.0+incompatible h1:ypCT7tHzMUrUKjdHX6GGEsGq0yi0IYMaljwN5b6hbIc=
4-
github.com/DataDog/datadog-go v2.3.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
5-
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
6-
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
7-
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
8-
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
1+
github.com/DataDog/datadog-go v3.4.1+incompatible h1:hRUopimy+td4Lc3QDvP/hsbQKI3n5xsmGJTRghwaA7U=
2+
github.com/DataDog/datadog-go v3.4.1+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
3+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
6+
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
7+
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
8+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
99
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
1010
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
11-
golang.org/x/sys v0.0.0-20180314180151-89ac7f292d17 h1:N8O/0j49esAfvJVDdHct24vdhaAPxjtIUhpkpX+7E5Y=
12-
golang.org/x/sys v0.0.0-20180314180151-89ac7f292d17/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
11+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
12+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13+
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
14+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
16+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
17+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
18+
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19+
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
20+
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
21+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
22+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
23+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
24+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

metrics/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ type Client interface {
7070
// Timing creates a histogram of a duration.
7171
Timing(name string, value time.Duration)
7272

73-
// Historgram creates a numeric floating point metric with min/max/avg/p95/etc
73+
// Historgram creates a numeric floating point metric with min/max/avg/p95/etc.
7474
Histogram(name string, value float64)
75+
76+
// Distribution tracks the statistical distribution of a set of values.
77+
Distribution(name string, value float64)
78+
79+
// Close closes all client connections and flushes any buffered data.
80+
Close() error
7581
}

metrics/datadog.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ func (c *DataDogClient) tagsList() []string {
5757
return mapToStrings(c.tagMap)
5858
}
5959

60+
// Close closes all client connections and flushes any buffered data.
61+
func (c *DataDogClient) Close() error {
62+
return c.client.Close()
63+
}
64+
6065
// Count adds some integer value to a metric.
6166
func (c *DataDogClient) Count(name string, value int64) {
6267
c.client.Count(name, value, c.tagsList(), c.rate)
@@ -95,3 +100,8 @@ func (c *DataDogClient) Timing(name string, value time.Duration) {
95100
func (c *DataDogClient) Histogram(name string, value float64) {
96101
c.client.Histogram(name, value, c.tagsList(), c.rate)
97102
}
103+
104+
// Distribution tracks the statistical distribution of a set of values.
105+
func (c *DataDogClient) Distribution(name string, value float64) {
106+
c.client.Distribution(name, value, c.tagsList(), c.rate)
107+
}

metrics/datadog_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestDataDogClient(t *testing.T) {
3939
datadog.Decr("one")
4040
datadog.Gauge("memory", 1024)
4141
datadog.Histogram("histo", 123)
42+
datadog.Distribution("distro", 999)
4243

4344
if rater, ok := datadog.(withRater); ok {
4445
ratedClient := rater.WithRate(0.5)
@@ -76,4 +77,6 @@ func TestDataDogClient(t *testing.T) {
7677
if !reflect.DeepEqual(e.Tags, []string{"tag1:value1"}) {
7778
t.Fatalf("Expected event to have tags '[tag1:value1]'. Found '%v'", e.Tags)
7879
}
80+
81+
datadog.Close()
7982
}

metrics/logger.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ func (c *LoggerClient) getTags() string {
148148
return "map[" + tags + "]"
149149
}
150150

151+
// Close on LoggerClient is a no-op
152+
func (c *LoggerClient) Close() error {
153+
return nil
154+
}
155+
151156
// Count adds some value to a metric.
152157
func (c *LoggerClient) Count(name string, value int64) {
153158
c.print("Count", name, value, float64(value)*c.rate)
@@ -182,3 +187,8 @@ func (c *LoggerClient) Timing(name string, value time.Duration) {
182187
func (c *LoggerClient) Histogram(name string, value float64) {
183188
c.print("Histogram", name, value, value)
184189
}
190+
191+
// Distribution tracks the statistical distribution of a set of values.
192+
func (c *LoggerClient) Distribution(name string, value float64) {
193+
c.print("Distribution", name, value, value)
194+
}

metrics/logger_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ func TestLoggerClient(t *testing.T) {
4646
client.Decr("one")
4747
client.Gauge("memory", 1024)
4848
client.Histogram("histo", 123)
49+
client.Distribution("distro", 999)
50+
client.Close()
4951

5052
ExpectEqual(t, "Count one:1 map[]", recorder.messages[0])
5153
ExpectEqual(t, "Event title\ndesc map[]", recorder.messages[1])
5254
ExpectEqual(t, "Timing two:2s map[tag1:override]", recorder.messages[2])
5355
ExpectEqual(t, "Count one:-1 map[]", recorder.messages[3])
5456
ExpectEqual(t, "Gauge memory:1024 map[]", recorder.messages[4])
5557
ExpectEqual(t, "Histogram histo:123 map[]", recorder.messages[5])
58+
ExpectEqual(t, "Distribution distro:999 map[]", recorder.messages[6])
5659

5760
// Make sure the call works, but since it is randomly sampled we have no
5861
// assertion to make.

metrics/null.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func (c *NullClient) WithRate(rate float64) Client {
2727
return &NullClient{}
2828
}
2929

30+
// Close on a NullClient is a no-op
31+
func (c *NullClient) Close() error {
32+
return nil
33+
}
34+
3035
// Count adds some value to a metric.
3136
func (c *NullClient) Count(name string, value int64) {
3237
}
@@ -54,3 +59,7 @@ func (c *NullClient) Timing(name string, value time.Duration) {
5459
// Histogram sets a numeric value while tracking min/max/avg/p95/etc.
5560
func (c *NullClient) Histogram(name string, value float64) {
5661
}
62+
63+
// Distribution tracks the statistical distribution of a set of values.
64+
func (c *NullClient) Distribution(name string, value float64) {
65+
}

0 commit comments

Comments
 (0)