Skip to content

Commit

Permalink
Merge pull request #208 from Shopify/fix/statsd-client
Browse files Browse the repository at this point in the history
Updating client version for statsd
  • Loading branch information
pedro-stanaka committed Nov 17, 2023
2 parents 402d74e + 9e2da93 commit b86453a
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 33 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
uses: actions/checkout@v3.1.0

- name: golangci-lint
uses: golangci/golangci-lint-action@v3.2.0
uses: golangci/golangci-lint-action@v3
with:
version: v1.49.0
version: v1.55.2

mod-tidy:
name: Go Mod Tidy
Expand Down Expand Up @@ -57,16 +57,17 @@ jobs:
strategy:
matrix:
go-version:
- 1.17.x
- 1.18.x
- 1.19.x
- 1.18.x # EOL: 01 Feb 2023
- 1.19.x # EOL: 08 Aug 2023
- 1.20.x
- 1.21.x

steps:
- name: Checkout
uses: actions/checkout@v3.1.0
uses: actions/checkout@v3

- name: Setup go
uses: actions/setup-go@v3.3.0
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

Expand Down
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ output:

linters:
enable:
- depguard
- dupl
- goconst
- gocritic
- gofmt
- goimports
- golint
- gosec
- govet
- lll
- maligned
- megacheck
- misspell
- nakedret
Expand All @@ -37,7 +34,7 @@ linters-settings:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
min-occurrences: 3 # now is inclusive
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
Expand Down
2 changes: 1 addition & 1 deletion bin/style
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Style
class << self
INSTALLER_URL = 'https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh'
EXECUTABLE = 'golangci-lint'
VERSION = '1.49.0'
VERSION = '1.55.2'
VERSION_TAG = "v#{VERSION}"

def call
Expand Down
2 changes: 1 addition & 1 deletion dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: goose

up:
- go:
version: "1.19.2"
version: "1.21.4"
modules: true

commands:
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module github.com/Shopify/goose
go 1.15

require (
github.com/DataDog/datadog-go v4.8.1+incompatible
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/DataDog/datadog-go/v5 v5.3.0
github.com/bugsnag/bugsnag-go/v2 v2.1.1
github.com/bugsnag/panicwrap v1.3.4
github.com/google/pprof v0.0.0-20210804190019-f964ff605595
Expand Down
24 changes: 22 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/DataDog/datadog-go v4.8.1+incompatible h1:KgnZAqwHyxgl6Fdhu2GtdZT7xFizdUBhDI05Wly0zg0=
github.com/DataDog/datadog-go v4.8.1+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go/v5 v5.3.0 h1:2q2qjFOb3RwAZNU+ez27ZVDwErJv5/VpbBPprz7Z+s8=
github.com/DataDog/datadog-go/v5 v5.3.0/go.mod h1:XRDJk1pTc00gm+ZDiBKsjh7oOOtJfYfglVCmFb8C2+Q=
github.com/Microsoft/go-winio v0.5.0 h1:Elr9Wn+sGKPlkaBvwu4mTrxtmOp3F3yV9qhaHbXGjwU=
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/bitly/go-simplejson v0.5.0 h1:6IH+V8/tVMab511d5bn4M7EwGXZf9Hj6i2xSwkNEM+Y=
Expand All @@ -19,6 +19,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/pprof v0.0.0-20210804190019-f964ff605595 h1:uNrRgpnKjTfxu4qHaZAAs3eKTYV1EzGF3dAykpnxgDE=
github.com/google/pprof v0.0.0-20210804190019-f964ff605595/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
Expand Down Expand Up @@ -56,22 +57,41 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d h1:LO7XpTYMwTqxjLcGWPijK3vRXg1aWdlNOVOHRq45d7c=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2 h1:c8PlLMqBbOHoqtjteWm5/kbe6rNY2pbRfbIMVnepueo=
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 3 additions & 1 deletion srvutil/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/Shopify/goose/statsd"
)

const httpScheme = "http://"

func TestRequestMetricsMiddleware(t *testing.T) {
var recordedTags []string
statsd.SetBackend(statsd.NewForwardingBackend(func(_ context.Context, mType string, name string, value interface{}, tags []string, _ float64) error {
Expand Down Expand Up @@ -58,7 +60,7 @@ func TestRequestMetricsMiddleware(t *testing.T) {
defer s.Tomb().Kill(nil)
safely.Run(s)

u := "http://" + s.Addr().String() + "/hello/world"
u := httpScheme + s.Addr().String() + "/hello/world"

req, err := http.NewRequest("GET", u, nil)
req.Header.Set("Authorization", "secret")
Expand Down
8 changes: 4 additions & 4 deletions srvutil/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ExampleNewServer() {
defer s.Tomb().Kill(nil)
safely.Run(s)

u := "http://" + s.Addr().String() + "/hello/world"
u := httpScheme + s.Addr().String() + "/hello/world"

res, _ := http.Get(u)
io.Copy(os.Stdout, res.Body)
Expand All @@ -64,7 +64,7 @@ func TestNewServer(t *testing.T) {
defer s.Tomb().Kill(nil)
safely.Run(s)

u := "http://" + s.Addr().String()
u := httpScheme + s.Addr().String()
t.Logf("test server running on %s", u)

assert.Contains(t, logOutput.String(), "level=info msg=\"starting server\" bind=\"127.0.0.1:0\"")
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestNewServerFromFactory(t *testing.T) {
defer s.Tomb().Kill(nil)
safely.Run(s)

u := "http://" + s.Addr().String()
u := httpScheme + s.Addr().String()
t.Logf("test server running on %s", u)

assert.Contains(t, logOutput.String(), "level=info msg=\"starting server\" bind=\"127.0.0.1:0\"")
Expand Down Expand Up @@ -205,7 +205,7 @@ func TestStoppableKeepaliveListener_Accept(t *testing.T) {
s := NewServer(tb, "127.0.0.1:0", sl)
safely.Run(s)

u := "http://" + s.Addr().String()
u := httpScheme + s.Addr().String()
t.Logf("test server running on %s", u)

done := make(chan struct{})
Expand Down
27 changes: 16 additions & 11 deletions statsd/datadog_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/DataDog/datadog-go/statsd"
"github.com/DataDog/datadog-go/v5/statsd"
)

// NewDatadogBackend instantiates a new datadog/statsd connection. When running
Expand All @@ -16,13 +16,18 @@ import (
// `tags` is a set of tags that will be included with every metric submitted.
// STATSD_DEFAULT_TAGS env variable will be read automatically and added to default tags.
func NewDatadogBackend(endpoint, namespace string, tags []string) (Backend, error) {
client, err := statsd.New(endpoint)
defaultTags := append(defaultTagsFromEnv(), tags...)
client, err := statsd.New(
endpoint,
statsd.WithNamespace(namespace),
statsd.WithTags(defaultTags),
statsd.WithoutTelemetry(),
statsd.WithoutOriginDetection(),
statsd.WithClientSideAggregation(),
)
if err != nil {
return nil, err
}
client.Namespace = namespace
defaultTags := append(defaultTagsFromEnv(), tags...)
client.Tags = defaultTags
return &datadogBackend{
client: client,
}, nil
Expand All @@ -32,26 +37,26 @@ type datadogBackend struct {
client *statsd.Client
}

func (b *datadogBackend) Gauge(ctx context.Context, name string, value float64, tags []string, rate float64) error {
func (b *datadogBackend) Gauge(_ context.Context, name string, value float64, tags []string, rate float64) error {
return b.client.Gauge(name, value, tags, rate)
}

func (b *datadogBackend) Count(ctx context.Context, name string, value int64, tags []string, rate float64) error {
func (b *datadogBackend) Count(_ context.Context, name string, value int64, tags []string, rate float64) error {
return b.client.Count(name, value, tags, rate)
}

func (b *datadogBackend) Histogram(ctx context.Context, name string, value float64, tags []string, rate float64) error {
func (b *datadogBackend) Histogram(_ context.Context, name string, value float64, tags []string, rate float64) error {
return b.client.Histogram(name, value, tags, rate)
}

func (b *datadogBackend) Distribution(ctx context.Context, name string, value float64, tags []string, rate float64) error {
func (b *datadogBackend) Distribution(_ context.Context, name string, value float64, tags []string, rate float64) error {
return b.client.Distribution(name, value, tags, rate)
}

func (b *datadogBackend) Set(ctx context.Context, name string, value string, tags []string, rate float64) error {
func (b *datadogBackend) Set(_ context.Context, name string, value string, tags []string, rate float64) error {
return b.client.Set(name, value, tags, rate)
}

func (b *datadogBackend) Timing(ctx context.Context, name string, value time.Duration, tags []string, rate float64) error {
func (b *datadogBackend) Timing(_ context.Context, name string, value time.Duration, tags []string, rate float64) error {
return b.client.Timing(name, value, tags, rate)
}

0 comments on commit b86453a

Please sign in to comment.