diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..5b97bb8 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,23 @@ +run: + tests: false + timeout: 5m +linters: + enable-all: true + disable: + - exhaustive + - exhaustivestruct + - funlen + - gochecknoglobals + - gochecknoinits + - gocognit + - gocyclo + - goerr113 + - gomnd + - nestif + - noctx + - nlreturn + - scopelint + - wrapcheck + - wsl + - gofumpt + - godox \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 06263e9..b50a5ed 100755 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ sudo: false language: go go: - - "1.13.x" - "1.14.x" + - "1.15.x" - "1.x" env: @@ -14,13 +14,12 @@ cache: - $GOPATH/pkg/mod before_install: + - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin ${GOLANGCI_LINT_VERSION} + - GO111MODULE=off go get -u github.com/mattn/goveralls # Use `go install` in Go1.16 - go mod download - - go get -u golang.org/x/lint/golint - - go get github.com/mattn/goveralls script: - - golint ./... - - go vet ./... + - golangci-lint run ./... - go test -covermode=count -coverprofile=profile.cov ./... - goveralls -coverprofile=profile.cov -service=travis-ci diff --git a/go.mod b/go.mod index d503df7..a9d9fd7 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/hamba/statter go 1.11 require ( - github.com/cactus/go-statsd-client/statsd v0.0.0-20200728222731-a2baea3bbfc6 + github.com/cactus/go-statsd-client/v4 v4.0.0 github.com/prometheus/client_golang v1.7.1 github.com/stretchr/testify v1.6.1 ) diff --git a/go.sum b/go.sum index 058ec22..0ec32ba 100644 --- a/go.sum +++ b/go.sum @@ -7,10 +7,8 @@ github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= 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-20191106001114-12b4e2b38748 h1:bXxS5/Z3/dfc8iFniQfgogNBomo0u+1//9eP+jl8GVo= -github.com/cactus/go-statsd-client/statsd v0.0.0-20191106001114-12b4e2b38748/go.mod h1:l/bIBLeOl9eX+wxJAzxS4TveKRtAqlyDpHjhkfO0MEI= -github.com/cactus/go-statsd-client/statsd v0.0.0-20200728222731-a2baea3bbfc6 h1:arL5CcymFtWyyi5Xk44VpSxUfFfJqxCMbhZQ0lxLkDE= -github.com/cactus/go-statsd-client/statsd v0.0.0-20200728222731-a2baea3bbfc6/go.mod h1:l/bIBLeOl9eX+wxJAzxS4TveKRtAqlyDpHjhkfO0MEI= +github.com/cactus/go-statsd-client/v4 v4.0.0 h1:cjO9CI3GAHtj/Vmmt1/BRq8+hf5MXy/Pr/CM6Dy4dp0= +github.com/cactus/go-statsd-client/v4 v4.0.0/go.mod h1:m73kwJp6TN0Ja9P6ycdZhWM1MlfxY/95WZ//IptPQ+Y= 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= @@ -27,8 +25,6 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= @@ -41,8 +37,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/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/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -66,12 +62,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0 h1:vrDKnkGzuGvhNAL56c7DBz29ZL+KxnoR0x7enabFceM= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.4.1 h1:FFSuS004yOQEtDdTq+TAOLP5xUq63KqAFYyOi8zA+Y8= -github.com/prometheus/client_golang v1.4.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= -github.com/prometheus/client_golang v1.5.0 h1:Ctq0iGpCmr3jeP77kbF2UxgvRwzWWz+4Bh9/vJTyg1A= -github.com/prometheus/client_golang v1.5.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= -github.com/prometheus/client_golang v1.5.1 h1:bdHYieyGlH+6OLEk2YQha8THib30KP0/yD0YH9m6xcA= -github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1 h1:NTGy1Ja9pByO+xAeH/qiWnLrKtr3hJPNjaVUwnjpdpA= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= @@ -81,16 +71,11 @@ github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2 github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.4.1 h1:K0MGApIoQvMw27RTdJkPbr3JZ7DNbtxQNyi5STVM6Kw= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= -github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/prometheus/procfs v0.0.10 h1:QJQN3jYQhkamO4mhfUWqdDH2asK7ONOI9MTWjyAxNKM= -github.com/prometheus/procfs v0.0.10/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -103,8 +88,6 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 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/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -120,9 +103,6 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c h1:jceGD5YNJGgGMkJz79agzOln1K9TaZUjv5ird16qniQ= -golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/bytes/buffer_internal_test.go b/internal/bytes/buffer_internal_test.go index 3134bf8..6e76e9e 100755 --- a/internal/bytes/buffer_internal_test.go +++ b/internal/bytes/buffer_internal_test.go @@ -46,7 +46,7 @@ func TestBuffer(t *testing.T) { }{ { name: "WriteByte", - fn: func() { buf.WriteByte('v') }, + fn: func() { _ = buf.WriteByte('v') }, want: "v", }, { @@ -56,7 +56,7 @@ func TestBuffer(t *testing.T) { }, { name: "Write", - fn: func() { buf.Write([]byte("foo")) }, + fn: func() { _, _ = buf.Write([]byte("foo")) }, want: "foo", }, { diff --git a/l2met/l2met.go b/l2met/l2met.go index 30e7525..0a91f3b 100644 --- a/l2met/l2met.go +++ b/l2met/l2met.go @@ -18,11 +18,7 @@ type Logger interface { type SamplerFunc func(float32) bool func defaultSampler(rate float32) bool { - if rand.Float32() < rate { - return true - } - - return false + return rand.Float32() < rate //nolint:gosec } // OptsFunc represents a function that configures L2met. @@ -103,7 +99,7 @@ func (s *L2met) Timing(name string, value time.Duration, rate float32, tags ...s ) } -// render outputs the metric to the logger +// render outputs the metric to the logger. func (s *L2met) render(measure, name string, value interface{}, rate float32, t []string) { if !s.includeStat(rate) { return @@ -129,7 +125,7 @@ func (s *L2met) includeStat(rate float32) bool { return s.sampler(rate) } -// Close closes the client and flushes buffered stats, if applicable +// Close closes the client and flushes buffered stats, if applicable. func (s *L2met) Close() error { return nil } @@ -143,7 +139,7 @@ func (s *L2met) formatRate(rate float32) string { } buf := pool.Get() - buf.WriteByte('@') + _ = buf.WriteByte('@') buf.AppendFloat(float64(rate), 'f', -1, 32) res := string(buf.Bytes()) pool.Put(buf) @@ -174,10 +170,10 @@ func formatDuration(d time.Duration) string { break } - buf.WriteByte('.') + _ = buf.WriteByte('.') for om > 0 { - buf.WriteByte('0') + _ = buf.WriteByte('0') om-- } diff --git a/prometheus/prometheus.go b/prometheus/prometheus.go index 8190b88..18dcb9d 100644 --- a/prometheus/prometheus.go +++ b/prometheus/prometheus.go @@ -151,7 +151,7 @@ func (s *Prometheus) Timing(name string, value time.Duration, rate float32, tags m.With(lbls).Observe(float64(value) / float64(time.Millisecond)) } -// Close closes the client and flushes buffered stats, if applicable +// Close closes the client and flushes buffered stats, if applicable. func (s *Prometheus) Close() error { return nil } diff --git a/statsd/statsd.go b/statsd/statsd.go index 049aca2..0c67d82 100644 --- a/statsd/statsd.go +++ b/statsd/statsd.go @@ -4,7 +4,7 @@ package statsd import ( "time" - "github.com/cactus/go-statsd-client/statsd" + "github.com/cactus/go-statsd-client/v4/statsd" "github.com/hamba/statter/internal/bytes" "github.com/hamba/statter/internal/tags" ) @@ -16,7 +16,12 @@ type Statsd struct { // New returns a statsd instance. func New(addr, prefix string) (*Statsd, error) { - c, err := statsd.NewClient(addr, prefix) + config := &statsd.ClientConfig{ + Address: addr, + Prefix: prefix, + UseBuffered: false, + } + c, err := statsd.NewClientWithConfig(config) if err != nil { return nil, err } @@ -44,7 +49,7 @@ func (s *Statsd) Timing(name string, value time.Duration, rate float32, tags ... _ = s.client.TimingDuration(name, value, rate) } -// Close closes the client and flushes buffered stats, if applicable +// Close closes the client and flushes buffered stats, if applicable. func (s *Statsd) Close() error { return s.client.Close() } @@ -84,7 +89,14 @@ func NewBuffered(addr, prefix string, opts ...BufferedStatsdFunc) (*BufferedStat o(s) } - c, err := statsd.NewBufferedClient(addr, prefix, s.flushInterval, s.flushBytes) + config := &statsd.ClientConfig{ + Address: addr, + Prefix: prefix, + UseBuffered: true, + FlushInterval: s.flushInterval, + FlushBytes: s.flushBytes, + } + c, err := statsd.NewClientWithConfig(config) if err != nil { return nil, err } @@ -111,14 +123,14 @@ func (s *BufferedStatsd) Timing(name string, value time.Duration, rate float32, _ = s.client.TimingDuration(name, value, rate) } -// Close closes the client and flushes buffered stats, if applicable +// Close closes the client and flushes buffered stats, if applicable. func (s *BufferedStatsd) Close() error { return s.client.Close() } var pool = bytes.NewPool(512) -// formatTags formats into an InfluxDB style string +// formatTags formats into an InfluxDB style string. func formatTags(t []string) string { if len(t) == 0 { return "" @@ -128,9 +140,9 @@ func formatTags(t []string) string { buf := pool.Get() for i := 0; i < len(t); i += 2 { - buf.WriteByte(',') + _ = buf.WriteByte(',') buf.WriteString(t[i]) - buf.WriteByte('=') + _ = buf.WriteByte('=') buf.WriteString(t[i+1]) } diff --git a/statsd/statsd_internal_test.go b/statsd/statsd_internal_test.go index 43206f4..7bdc758 100644 --- a/statsd/statsd_internal_test.go +++ b/statsd/statsd_internal_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/cactus/go-statsd-client/statsd" - "github.com/cactus/go-statsd-client/statsd/statsdtest" + "github.com/cactus/go-statsd-client/v4/statsd" + "github.com/cactus/go-statsd-client/v4/statsd/statsdtest" "github.com/stretchr/testify/assert" )