Skip to content

Commit 830be12

Browse files
huikangrboyer
andauthored
golang-lint metrics label (#659)
* Add golangci-lint Co-authored-by: R.B. Boyer <[email protected]>
1 parent 3805ead commit 830be12

File tree

4 files changed

+113
-3
lines changed

4 files changed

+113
-3
lines changed

.github/workflows/check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,36 @@ permissions:
1010
contents: read
1111

1212
jobs:
13+
lint:
14+
name: "Run golangci-lint"
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
GO_VERSION: [ "1.16","1.17","1.18" ]
19+
steps:
20+
- name: "Fetch source code"
21+
uses: actions/checkout@v2
22+
23+
- name: Install Go toolchain
24+
uses: actions/setup-go@v2
25+
with:
26+
go-version: ${{ matrix.GO_VERSION }}
27+
- name: Cache Go modules
28+
uses: actions/cache@v3
29+
with:
30+
path: |
31+
~/.cache/go-build
32+
~/go/pkg/mod
33+
key: go-mod-${{ matrix.GO_VERSION }}-${{ hashFiles('go.sum') }}
34+
restore-keys: |
35+
go-mod-${{ matrix.GO_VERSION }}
36+
- name: "Download golang-lint"
37+
run: |
38+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
39+
golangci-lint --version
40+
- name: "lint"
41+
run: |
42+
golangci-lint run -v
1343
unit-tests:
1444
name: "Unit Tests"
1545
runs-on: ubuntu-latest

.golangci.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
# (TODO) uncomment after fixing the lint issues
5+
# - gofmt
6+
- govet
7+
# - unconvert
8+
# - staticcheck
9+
# - ineffassign
10+
# - unparam
11+
- forbidigo
12+
13+
issues:
14+
# Disable the default exclude list so that all excludes are explicitly
15+
# defined in this file.
16+
exclude-use-default: false
17+
18+
exclude-rules:
19+
# Temp Ignore SA9004: only the first constant in this group has an explicit type
20+
# https://staticcheck.io/docs/checks#SA9004
21+
- linters: [staticcheck]
22+
text: 'SA9004:'
23+
24+
- linters: [staticcheck]
25+
text: 'SA1019: Package github.com/golang/protobuf/jsonpb is deprecated'
26+
27+
- linters: [staticcheck]
28+
text: 'SA1019: Package github.com/golang/protobuf/proto is deprecated'
29+
30+
- linters: [staticcheck]
31+
text: 'SA1019: ptypes.MarshalAny is deprecated'
32+
33+
- linters: [staticcheck]
34+
text: 'SA1019: ptypes.UnmarshalAny is deprecated'
35+
36+
- linters: [staticcheck]
37+
text: 'SA1019: package github.com/golang/protobuf/ptypes is deprecated'
38+
39+
# An argument that always receives the same value is often not a problem.
40+
- linters: [unparam]
41+
text: 'always receives'
42+
43+
# Often functions will implement an interface that returns an error without
44+
# needing to return an error. Sometimes the error return value is unnecessary
45+
# but a linter can not tell the difference.
46+
- linters: [unparam]
47+
text: 'result \d+ \(error\) is always nil'
48+
49+
# Allow unused parameters to start with an underscore. Arguments with a name
50+
# of '_' are already ignored.
51+
# Ignoring longer names that start with underscore allow for better
52+
# self-documentation than a single underscore by itself. Underscore arguments
53+
# should generally only be used when a function is implementing an interface.
54+
- linters: [unparam]
55+
text: '`_[^`]*` is unused'
56+
57+
# Temp ignore some common unused parameters so that unparam can be added
58+
# incrementally.
59+
- linters: [unparam]
60+
text: '`(t|resp|req|entMeta)` is unused'
61+
62+
linters-settings:
63+
gofmt:
64+
simplify: true
65+
forbidigo:
66+
# Forbid the following identifiers (list of regexp).
67+
forbid:
68+
- '\brequire\.New\b(# Use package-level functions with explicit TestingT)?'
69+
- '\bassert\.New\b(# Use package-level functions with explicit TestingT)?'
70+
- '\bmetrics\.IncrCounter\b(# Use labeled metrics)?'
71+
- '\bmetrics\.AddSample\b(# Use labeled metrics)?'
72+
- '\bmetrics\.MeasureSince\b(# Use labeled metrics)?'
73+
- '\bmetrics\.SetGauge\b(# Use labeled metrics)?'
74+
# Exclude godoc examples from forbidigo checks.
75+
# Default: true
76+
exclude_godoc_examples: false
77+
78+
run:
79+
timeout: 10m
80+
concurrency: 4

cmd/serf/command/agent/invoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var sanitizeTagRegexp = regexp.MustCompile(`[^A-Z0-9_]`)
4040
// In all events, data is passed in via stdin to facilitate piping. See
4141
// the various stdin functions below for more information.
4242
func invokeEventScript(logger *log.Logger, script string, self serf.Member, event serf.Event) error {
43-
defer metrics.MeasureSince([]string{"agent", "invoke", script}, time.Now())
43+
defer metrics.MeasureSinceWithLabels([]string{"agent", "invoke", script}, time.Now(), nil)
4444
output, _ := circbuf.NewBuffer(maxBufSize)
4545

4646
// Determine the shell invocation based on OS

cmd/serf/command/agent/ipc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func (i *AgentIPC) listen() {
379379
continue
380380
}
381381
i.logger.Printf("[INFO] agent.ipc: Accepted client: %v", conn.RemoteAddr())
382-
metrics.IncrCounter([]string{"agent", "ipc", "accept"}, 1)
382+
metrics.IncrCounterWithLabels([]string{"agent", "ipc", "accept"}, 1, nil)
383383

384384
// Wrap the connection in a client
385385
client := &IPCClient{
@@ -468,7 +468,7 @@ func (i *AgentIPC) handleRequest(client *IPCClient, reqHeader *requestHeader) er
468468
client.Send(&respHeader, nil)
469469
return fmt.Errorf(handshakeRequired)
470470
}
471-
metrics.IncrCounter([]string{"agent", "ipc", "command"}, 1)
471+
metrics.IncrCounterWithLabels([]string{"agent", "ipc", "command"}, 1, nil)
472472

473473
// Ensure the client has authenticated after the handshake if necessary
474474
if i.authKey != "" && !client.didAuth && command != authCommand && command != handshakeCommand {

0 commit comments

Comments
 (0)