Skip to content

Commit 85c16f5

Browse files
authored
chore: Update golangci-lint and fix issues (#4303)
* Update golangci-lint * Use `--fix` * Manually fix linting issues
1 parent a9646af commit 85c16f5

File tree

76 files changed

+319
-341
lines changed

Some content is hidden

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

76 files changed

+319
-341
lines changed

.golangci.yml

Lines changed: 67 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,79 @@
1-
# This file contains all available configuration options
2-
# with their default values.
3-
4-
# options for analysis running
1+
version: "2"
52
run:
6-
go: "1.21"
7-
# default concurrency is a available CPU number
83
concurrency: 16
9-
10-
# timeout for analysis, e.g. 30s, 5m, default is 1m
11-
timeout: 10m
12-
13-
# exit code when at least one issue was found, default is 1
4+
go: "1.21"
5+
modules-download-mode: readonly
146
issues-exit-code: 1
15-
16-
# include test files or not, default is true
177
tests: true
18-
19-
# list of build tags, all linters use it. Default is empty list.
20-
build-tags: []
21-
22-
modules-download-mode: readonly
23-
24-
# output configuration options
258
output:
26-
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
279
formats:
28-
- format: colored-line-number
29-
30-
# print lines of code with issue, default is true
31-
print-issued-lines: true
32-
33-
# print linter name in the end of issue text, default is true
34-
print-linter-name: true
35-
36-
linters-settings:
37-
goimports:
38-
local-prefixes: github.com/grafana/pyroscope/,github.com/grafana/pyroscope/api,github.com/grafana/pyroscope/tools,github.com/grafana/pyroscope/ebpf
39-
40-
depguard:
41-
rules:
42-
main:
43-
deny:
44-
- pkg: "github.com/go-kit/kit/log"
45-
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
46-
47-
revive:
48-
rules:
49-
# This particular check seems to have problems with generic types and their receiver naming
50-
- name: receiver-naming
51-
disabled: true
52-
10+
text:
11+
path: stdout
12+
print-linter-name: true
13+
print-issued-lines: true
5314
linters:
5415
enable:
55-
- errcheck
16+
- depguard
5617
- goconst
57-
- gofmt
58-
- goimports
59-
- revive
60-
- ineffassign
61-
- staticcheck
6218
- misspell
19+
- revive
6320
- unconvert
6421
- unparam
65-
- govet
66-
- typecheck
67-
- depguard
68-
- exportloopref
69-
70-
issues:
71-
exclude:
72-
- Error return value of .*log\.Logger\)\.Log\x60 is not checked
73-
- Error return value of .*.Log.* is not checked
74-
- Error return value of `` is not checked
75-
# See https://github.com/grpc/grpc-go/issues/7090 for more information
76-
- grpc.Dial(.*) is deprecated
77-
78-
# which dirs to skip: they won't be analyzed;
79-
# can use regexp here: generated.*, regexp is applied on full path;
80-
# default value is empty list, but next dirs are always skipped independently
81-
# from this option's value:
82-
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
83-
exclude-dirs:
84-
- win_eventlog$
85-
- pkg/og
86-
87-
# which files to skip: they will be analyzed, but issues from them
88-
# won't be reported. Default value is empty list, but there is
89-
# no need to include all autogenerated files, we confidently recognize
90-
# autogenerated files. If it's not please let us know.
91-
exclude-files:
92-
- .*.pb.go
93-
- .*.y.go
94-
- .*.rl.go
95-
22+
settings:
23+
depguard:
24+
rules:
25+
main:
26+
deny:
27+
- pkg: github.com/go-kit/kit/log
28+
desc: Use github.com/go-kit/log instead of github.com/go-kit/kit/log
29+
revive:
30+
rules:
31+
- name: receiver-naming
32+
disabled: true
33+
exclusions:
34+
generated: lax
35+
presets:
36+
- comments
37+
- common-false-positives
38+
- legacy
39+
- std-error-handling
40+
rules:
41+
- path: (.+)\.go$
42+
text: Error return value of .*log\.Logger\)\.Log\x60 is not checked
43+
- path: (.+)\.go$
44+
text: Error return value of .*.Log.* is not checked
45+
- path: (.+)\.go$
46+
text: Error return value of `` is not checked
47+
- path: (.+)\.go$
48+
text: grpc.Dial(.*) is deprecated
49+
paths:
50+
- .*.pb.go
51+
- .*.y.go
52+
- .*.rl.go
53+
- win_eventlog$
54+
- pkg/og
55+
- third_party$
56+
- builtin$
57+
- examples$
58+
formatters:
59+
enable:
60+
- gofmt
61+
- goimports
62+
settings:
63+
goimports:
64+
local-prefixes:
65+
- github.com/grafana/pyroscope/
66+
- github.com/grafana/pyroscope/api
67+
- github.com/grafana/pyroscope/tools
68+
- github.com/grafana/pyroscope/ebpf
69+
exclusions:
70+
generated: lax
71+
paths:
72+
- .*.pb.go
73+
- .*.y.go
74+
- .*.rl.go
75+
- win_eventlog$
76+
- pkg/og
77+
- third_party$
78+
- builtin$
79+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ $(BIN)/buf: Makefile
310310

311311
$(BIN)/golangci-lint: Makefile
312312
@mkdir -p $(@D)
313-
GOBIN=$(abspath $(@D)) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0
313+
GOBIN=$(abspath $(@D)) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.2.2
314314

315315
$(BIN)/protoc-gen-go: Makefile go.mod
316316
@mkdir -p $(@D)

cmd/profilecli/bucket.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"context"
55
"embed"
6-
_ "embed"
76
"fmt"
87
"log"
98
"net/http"

cmd/profilecli/canary_exporter_probes.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func (ce *canaryExporter) testIngestProfile(ctx context.Context, now time.Time)
4848
p.ForStacktraceString("func1").AddSamples(20)
4949

5050
// for testing the span selection
51-
p.Profile.StringTable = append(p.Profile.StringTable, "profile_id", "00000bac2a5ab0c7")
52-
p.Sample[1].Label = []*googlev1.Label{{Key: int64(len(p.Profile.StringTable) - 2), Str: int64(len(p.Profile.StringTable) - 1)}}
51+
p.StringTable = append(p.StringTable, "profile_id", "00000bac2a5ab0c7")
52+
p.Sample[1].Label = []*googlev1.Label{{Key: int64(len(p.StringTable) - 2), Str: int64(len(p.StringTable) - 1)}}
5353

54-
data, err := p.Profile.MarshalVT()
54+
data, err := p.MarshalVT()
5555
if err != nil {
5656
return err
5757
}

cmd/profilecli/query-blocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func blocksQuerySeries(ctx context.Context, params *blocksQuerySeriesParams) err
134134
var from, to int64
135135
from, to = math.MaxInt64, math.MinInt64
136136
var targetBlockQueriers phlaredb.Queriers
137-
for _, blockId := range params.blocksQueryParams.BlockIds {
137+
for _, blockId := range params.BlockIds {
138138
meta, err := blockQuerier.BlockMeta(ctx, blockId)
139139
if err != nil {
140140
return err

cmd/profilecli/query-tracer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func queryTracer(ctx context.Context, params *queryTracerParams) (err error) {
377377

378378
if resp.StatusCode != http.StatusOK {
379379
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
380-
return fmt.Errorf("Tempo returned status code [%d]: %s ", resp.StatusCode, body)
380+
return fmt.Errorf("tempo returned status code [%d]: %s ", resp.StatusCode, body)
381381
}
382382

383383
var respBody struct {
@@ -454,7 +454,7 @@ func queryTracer(ctx context.Context, params *queryTracerParams) (err error) {
454454

455455
if resp.StatusCode != http.StatusOK {
456456
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
457-
return fmt.Errorf("Tempo returned status code [%d]: %s ", resp.StatusCode, body)
457+
return fmt.Errorf("tempo returned status code [%d]: %s ", resp.StatusCode, body)
458458
}
459459

460460
data, err := io.ReadAll(resp.Body)

cmd/profilecli/raft.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func addRaftInfoParams(cmd commander) *raftInfoParams {
4040
}
4141

4242
func raftInfo(ctx context.Context, params *raftInfoParams) error {
43-
client := params.phlareClient.metadataOperatorClient()
43+
client := params.metadataOperatorClient()
4444

4545
res, err := client.NodeInfo(ctx, connect.NewRequest(&raftnodepb.NodeInfoRequest{}))
4646
if err != nil {
@@ -82,9 +82,9 @@ func formatHumanRaftInfo(node *raftnodepb.NodeInfo) string {
8282
keyPadding := maxKeyPadding(keys)
8383
for _, pair := range pairs {
8484
key, value := pair[0], pair[1]
85-
sb.WriteString(fmt.Sprintf("%s:", key))
85+
fmt.Fprintf(sb, "%s:", key)
8686
sb.WriteString(strings.Repeat(" ", keyPadding-len(key)+1))
87-
sb.WriteString(fmt.Sprintf("%s\n", value))
87+
fmt.Fprintf(sb, "%s\n", value)
8888
}
8989
}
9090

cmd/profilecli/upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func addUploadParams(cmd commander) *uploadParams {
4949
}
5050

5151
func upload(ctx context.Context, params *uploadParams) (err error) {
52-
pc := params.phlareClient.pusherClient()
52+
pc := params.pusherClient()
5353

5454
lblStrings := make([]string, 0, len(params.extraLabels)*2)
5555
for key, value := range params.extraLabels {
@@ -85,7 +85,7 @@ func upload(ctx context.Context, params *uploadParams) (err error) {
8585
// detect name if no name has been set
8686
if lbl.Get(model.LabelNameProfileName) == "" {
8787
name := "unknown"
88-
for _, t := range profile.Profile.SampleType {
88+
for _, t := range profile.SampleType {
8989
if sid := int(t.Type); sid < len(profile.StringTable) {
9090
if s := profile.StringTable[sid]; s == "cpu" {
9191
name = "process_cpu"

cmd/pyroscope/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func errorHandler() {
5555
func main() {
5656
var flags mainFlags
5757

58-
flags.Config.V2 = os.Getenv("PYROSCOPE_V2") != "" || os.Getenv("PYROSCOPE_V2_EXPERIMENT") != ""
58+
flags.V2 = os.Getenv("PYROSCOPE_V2") != "" || os.Getenv("PYROSCOPE_V2_EXPERIMENT") != ""
5959
if err := cfg.DynamicUnmarshal(&flags, os.Args[1:], flag.CommandLine); err != nil {
6060
fmt.Fprintf(os.Stderr, "failed parsing config: %v\n", err)
6161
errorHandler()

examples/language-sdk-instrumentation/golang-push/migrating-from-standard-pprof/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ func main() {
7878
if err != nil {
7979
log.Fatalf("Error starting profiler: %v", err)
8080
}
81-
defer profiler.Stop()
81+
defer func() {
82+
err := profiler.Stop()
83+
if err != nil {
84+
log.Printf("Error stopping profiler: %v", err)
85+
}
86+
}()
8287

8388
// pyroscope.Start is non-blocking: the profiler will start shortly.
8489
// To ensure we don't miss the investigation, we wait briefly.

0 commit comments

Comments
 (0)