Skip to content

Commit 905b3b0

Browse files
Upgrade and fix golangci-lint errors (#44)
This also makes the repo use github actions for linting
1 parent 640870f commit 905b3b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+466
-381
lines changed

.circleci/config.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ jobs:
77
steps:
88
- checkout
99
- run:
10-
name: Verify
11-
command: make verify
10+
name: Test
11+
command: |
12+
make gocov test

.github/workflows/golangci-lint.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- master
8+
- main
9+
pull_request:
10+
jobs:
11+
golangci:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: golangci-lint
17+
uses: golangci/golangci-lint-action@v2
18+
with:
19+
version: v1.46.1
20+
# Optional: golangci-lint command line arguments.
21+
args: '--config=.golangci.yml -v'
22+
23+
# Optional: show only new issues if it's a pull request. The default value is `false`.
24+
# only-new-issues: true
25+
26+
# Optional: if set to true then the action will use pre-installed Go.
27+
# skip-go-installation: true
28+
29+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
30+
skip-pkg-cache: true
31+
32+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
33+
skip-build-cache: true

.golangci.yml

+114-19
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ run:
22
timeout: 5m
33
tests: true
44
skip-dirs:
5-
- cmd/backfill_test
6-
- lib/sfxthrift/datamodelservice
75
- src/external_libs
6+
- gocat
87
- genfiles$
98
- vendor$
9+
- ketama
1010
# which files to skip: they will be analyzed, but issues from them
1111
# won't be reported. Default value is empty list, but there is
1212
# no need to include all autogenerated files, we confidently recognize
1313
# autogenerated files. If it's not please let us know.
1414
skip-files:
1515
- ".*\\.pb\\.go"
1616
- ".*\\.gen\\.go"
17-
- ".*\\.java"
17+
- ".*_easyjson\\.go"
1818
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
1919
# If invoked with -mod=readonly, the go command is disallowed from the implicit
2020
# automatic updating of go.mod described above. Instead, it fails when any changes
@@ -41,6 +41,8 @@ linters-settings:
4141
min-confidence: 0.3
4242
gocyclo:
4343
min-complexity: 10
44+
gocognit:
45+
min-complexity: 30
4446
maligned:
4547
suggest-new: true
4648
gofmt:
@@ -50,10 +52,10 @@ linters-settings:
5052
settings:
5153
printf: # analyzer name, run `go tool vet help` to see all analyzers
5254
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
53-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
54-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
55-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
56-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
55+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
56+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
57+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
58+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
5759
enabled-tags:
5860
- performance
5961
gocritic:
@@ -88,25 +90,118 @@ linters-settings:
8890
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
8991
# might be left in the code accidentally and should be resolved before merging
9092
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
91-
- OPTIMIZE # marks code that should be optimized before merging
92-
- HACK # marks hack-arounds that should be removed before merging
93+
- OPTIMIZE # marks code that should be optimized before merging
94+
- HACK # marks hack-arounds that should be removed before merging
9395
funlen:
9496
lines: 500 # TODO: need to set this to 150 statements and work on it
9597
statements: 150
98+
ifshort:
99+
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
100+
# Has higher priority than max-decl-chars.
101+
max-decl-lines: 1
102+
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
103+
max-decl-chars: 30
104+
cyclop:
105+
# the maximal code complexity to report
106+
max-complexity: 15
107+
# should ignore tests (default false)
108+
skip-tests: false
109+
gosec:
110+
# To select a subset of rules to run.
111+
# Available rules: https://github.com/securego/gosec#available-rules
112+
includes:
113+
- G101 # Look for hard coded credentials
114+
- G102 # Bind to all interfaces
115+
- G106 # Audit the use of ssh.InsecureIgnoreHostKey
116+
- G107 # Url provided to HTTP request as taint input
117+
- G108 # Profiling endpoint automatically exposed on /debug/pprof
118+
- G109 # Potential Integer overflow made by strconv.Atoi result conversion to int16/32
119+
- G110 # Potential DoS vulnerability via decompression bomb
120+
- G306 # Poor file permissions used when writing to a new file
121+
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
122+
- G501 # Import blocklist: crypto/md5
123+
- G502 # Import blocklist: crypto/des
124+
- G503 # Import blocklist: crypto/rc4
125+
- G504 # Import blocklist: net/http/cgi
126+
- G505 # Import blocklist: crypto/sha1
127+
- G601 # Implicit memory aliasing of items from a range statement
128+
# To specify a set of rules to explicitly exclude.
129+
# Available rules: https://github.com/securego/gosec#available-rules
130+
excludes:
131+
- G204 # Audit use of command execution
132+
# To specify the configuration of rules.
133+
# The configuration of rules is not fully documented by gosec:
134+
# https://github.com/securego/gosec#configuration
135+
# https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/rules/rulelist.go#L60-L102
136+
config:
137+
G306: "0600"
138+
G101:
139+
pattern: "(?i)pwd|password|private_key|secret"
140+
ignore_entropy: false
141+
entropy_threshold: "80.0"
142+
per_char_threshold: "3.0"
143+
truncate: "32"
144+
staticcheck:
145+
# Select the Go version to target. The default is '1.13'.
146+
go: "1.17"
147+
# https://staticcheck.io/docs/options#checks
148+
checks:
149+
- "all"
150+
- "-SA1029" # disable the check for using string in context value keys
151+
- "-SA1019" # disable the check for net.Temporary as we use it still
152+
dupl:
153+
# tokens count to trigger issue, 150 by default
154+
threshold: 100
96155

97156
linters:
98-
enable-all: true
99-
disable:
100-
- lll
101-
- gochecknoglobals
102-
- errcheck
103-
- unparam
157+
disable-all: true
158+
enable: # please use alphabetical order when enabling any linters
159+
- asciicheck
160+
- bodyclose
161+
- cyclop
162+
- deadcode
163+
- depguard
164+
- durationcheck
165+
- errorlint
166+
- errname
167+
- exportloopref
168+
- forbidigo
169+
- gci
170+
- gocognit
171+
- goconst
172+
- gocyclo
173+
- godox
174+
- gofmt
175+
- gofumpt
176+
- goheader
177+
- goimports
178+
- gomodguard
179+
- goprintffuncname
104180
- gosec
105-
- interfacer
106-
- dupl
107-
# TODO: need to enable this two for better coding guidelines in terms of space between condition
181+
- gosimple
182+
- govet
183+
- ifshort
184+
- ineffassign
185+
- makezero
186+
- megacheck
187+
- misspell
188+
- nakedret
189+
- nilerr
190+
- noctx
191+
- prealloc
192+
- predeclared
193+
- revive
194+
- staticcheck
195+
- structcheck
196+
- stylecheck
197+
- testpackage
198+
- thelper
199+
- tparallel
200+
- unconvert
201+
- unparam
202+
- unused
203+
- wastedassign
108204
- whitespace
109-
- wsl
110205
fast: true
111206

112207
# output configuration options

config/globbing/glob_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func TestEscapeMetaCharacters(t *testing.T) {
10-
var cases = []struct {
10+
cases := []struct {
1111
desc string
1212
pattern string
1313
match []string

dp/dpbuffered/bufferedforwarder.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package dpbuffered
22

33
import (
4-
"sync"
5-
"sync/atomic"
6-
74
"context"
85
"fmt"
96
"net/http"
107
"runtime"
8+
"sync"
9+
"sync/atomic"
1110

1211
"github.com/signalfx/golib/v3/datapoint"
1312
"github.com/signalfx/golib/v3/datapoint/dpsink"
@@ -103,9 +102,9 @@ func (forwarder *BufferedForwarder) DebugEndpoints() map[string]http.Handler {
103102

104103
var _ dpsink.Sink = &BufferedForwarder{}
105104

106-
type errDPBufferFull string
105+
type dpBufferFullError string
107106

108-
func (e errDPBufferFull) Error() string {
107+
func (e dpBufferFullError) Error() string {
109108
return "Forwarder " + string(e) + " unable to send more datapoints. Buffer full"
110109
}
111110

@@ -117,7 +116,7 @@ func (forwarder *BufferedForwarder) AddDatapoints(ctx context.Context, points []
117116
atomic.AddInt64(&forwarder.stats.totalDatapointsBuffered, int64(len(points)))
118117
if *forwarder.config.MaxTotalDatapoints <= atomic.LoadInt64(&forwarder.stats.totalDatapointsBuffered) {
119118
atomic.AddInt64(&forwarder.stats.totalDatapointsBuffered, int64(-len(points)))
120-
return errDPBufferFull(forwarder.identifier)
119+
return dpBufferFullError(forwarder.identifier)
121120
}
122121
select {
123122
case forwarder.dpChan <- points:
@@ -129,9 +128,9 @@ func (forwarder *BufferedForwarder) AddDatapoints(ctx context.Context, points []
129128
}
130129
}
131130

132-
type errEBufferFull string
131+
type eBufferFullError string
133132

134-
func (e errEBufferFull) Error() string {
133+
func (e eBufferFullError) Error() string {
135134
return "Forwarder " + string(e) + " unable to send more events. Buffer full"
136135
}
137136

@@ -143,7 +142,7 @@ func (forwarder *BufferedForwarder) AddEvents(ctx context.Context, events []*eve
143142
atomic.AddInt64(&forwarder.stats.totalEventsBuffered, int64(len(events)))
144143
if *forwarder.config.MaxTotalEvents <= atomic.LoadInt64(&forwarder.stats.totalEventsBuffered) {
145144
atomic.AddInt64(&forwarder.stats.totalEventsBuffered, int64(-len(events)))
146-
return errEBufferFull(forwarder.identifier)
145+
return eBufferFullError(forwarder.identifier)
147146
}
148147
select {
149148
case forwarder.eChan <- events:
@@ -155,9 +154,9 @@ func (forwarder *BufferedForwarder) AddEvents(ctx context.Context, events []*eve
155154
}
156155
}
157156

158-
type errTBufferFull string
157+
type tBufferFullError string
159158

160-
func (e errTBufferFull) Error() string {
159+
func (e tBufferFullError) Error() string {
161160
return "Forwarder " + string(e) + " unable to send more traces. Buffer full"
162161
}
163162

@@ -166,7 +165,7 @@ func (forwarder *BufferedForwarder) AddSpans(ctx context.Context, traces []*trac
166165
atomic.AddInt64(&forwarder.stats.totalTracesBuffered, int64(len(traces)))
167166
if *forwarder.config.MaxTotalSpans <= atomic.LoadInt64(&forwarder.stats.totalTracesBuffered) {
168167
atomic.AddInt64(&forwarder.stats.totalTracesBuffered, int64(-len(traces)))
169-
return errTBufferFull(forwarder.identifier)
168+
return tBufferFullError(forwarder.identifier)
170169
}
171170
select {
172171
case forwarder.tChan <- traces:

dp/dpbuffered/bufferedforwarder_test.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package dpbuffered
22

33
import (
4-
"testing"
5-
"time"
6-
74
"bytes"
85
"context"
6+
"errors"
97
"io"
10-
"sync"
11-
128
"net/http"
9+
"sync"
10+
"testing"
11+
"time"
1312

1413
"github.com/signalfx/golib/v3/datapoint"
1514
"github.com/signalfx/golib/v3/datapoint/dpsink"
@@ -336,7 +335,7 @@ func TestBufferedForwarderMaxTotalDatapoints(t *testing.T) {
336335
}
337336
found := false
338337
for i := 0; i < 100; i++ {
339-
if err := bf.AddDatapoints(ctx, datas); err == errDPBufferFull(*config.Name) {
338+
if err := bf.AddDatapoints(ctx, datas); errors.Is(err, dpBufferFullError(*config.Name)) {
340339
assert.NotEmpty(t, err.Error())
341340
found = true
342341
break
@@ -369,7 +368,7 @@ func TestBufferedForwarderMaxTotalEvents(t *testing.T) {
369368
spans := []*trace.Span{{}, {}}
370369
found := false
371370
for i := 0; i < 100; i++ {
372-
if err := bf.AddEvents(ctx, events); err == errEBufferFull(*config.Name) {
371+
if err := bf.AddEvents(ctx, events); errors.Is(err, eBufferFullError(*config.Name)) {
373372
assert.NotEmpty(t, err.Error())
374373
found = true
375374
break
@@ -378,7 +377,7 @@ func TestBufferedForwarderMaxTotalEvents(t *testing.T) {
378377
assert.True(t, found, "With small buffer size, I should error out with a full buffer")
379378
found = false
380379
for i := 0; i < 100; i++ {
381-
if err := bf.AddSpans(ctx, spans); err == errTBufferFull(*config.Name) {
380+
if err := bf.AddSpans(ctx, spans); errors.Is(err, tBufferFullError(*config.Name)) {
382381
assert.NotEmpty(t, err.Error())
383382
found = true
384383
break

grpc/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// SignalFxTokenAuth is a credentials.PerRPCCredentials object that sets an auth token on each gRPC request
1111
// as expected by our ingest service.
1212
type SignalFxTokenAuth struct {
13-
Token string
13+
Token string
1414
DisableTransportSecurity bool
1515
}
1616

grpc/auth_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func TestGRPCAuth(t *testing.T) {
1212
Convey("grpc auth", t, func() {
1313
a := &SignalFxTokenAuth{
14-
Token: "test",
14+
Token: "test",
1515
DisableTransportSecurity: false,
1616
}
1717

protocol/carbon/carbon.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package carbon
22

33
import (
4+
stderrors "errors"
45
"strconv"
56
"strings"
67
"time"
@@ -38,7 +39,7 @@ func NewCarbonDatapoint(line string, metricDeconstructor metricdeconstructor.Met
3839
originalMetricName := parts[0]
3940
metricName, mtype, dimensions, err := metricDeconstructor.Parse(originalMetricName)
4041

41-
if err == metricdeconstructor.ErrSkipMetric {
42+
if stderrors.Is(err, metricdeconstructor.ErrSkipMetric) {
4243
return nil, nil
4344
}
4445
if err != nil {

0 commit comments

Comments
 (0)