Skip to content

Commit 5f2f54f

Browse files
committed
refactor: bump golangci-lint to 2.6.2
1 parent 4eead6d commit 5f2f54f

Some content is hidden

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

49 files changed

+639
-478
lines changed

.github/workflows/presubmit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: golangci-lint
4444
uses: golangci/golangci-lint-action@v7
4545
with:
46-
version: v2.0.2
46+
version: v2.6.2
4747
skip-cache: true
4848
args: --timeout=5m --verbose
4949
validate:

.golangci.yml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ linters:
4444
- nilnil
4545
- nlreturn
4646
- noctx
47+
- noinlineerr
4748
# TODO(bwplotka): Remove once https://github.com/golangci/golangci-lint/issues/3228 is fixed.
4849
- nolintlint
4950
- nonamedreturns
@@ -61,7 +62,36 @@ linters:
6162
- wastedassign
6263
- wrapcheck
6364
- wsl
65+
- wsl_v5
6466
settings:
67+
errcheck:
68+
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
69+
# Such cases aren't reported by default.
70+
# Default: false
71+
check-type-assertions: false
72+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
73+
# Such cases aren't reported by default.
74+
# Default: false
75+
check-blank: false
76+
# To disable the errcheck built-in exclude list.
77+
# See `-excludeonly` option in https://github.com/kisielk/errcheck#excluding-functions for details.
78+
# Default: false
79+
disable-default-exclusions: false
80+
# List of functions to exclude from checking, where each entry is a single function to exclude.
81+
# See https://github.com/kisielk/errcheck#excluding-functions for details.
82+
exclude-functions:
83+
- fmt.Fprint
84+
- fmt.Fprintf
85+
- fmt.Fprintln
86+
- fmt.Print
87+
- fmt.Printf
88+
- fmt.Println
89+
- io/ioutil.ReadFile
90+
- io.Copy(*bytes.Buffer)
91+
- io.Copy(os.Stdout)
92+
# Display function signature instead of selector.
93+
# Default: false
94+
verbose: true
6595
importas:
6696
alias:
6797
- pkg: k8s.io/api/apps/v1
@@ -167,11 +197,17 @@ linters:
167197
severity: warning
168198
disabled: true
169199
- name: unhandled-error
170-
arguments:
171-
- fmt.Printf
172-
- myFunction
173200
severity: warning
174-
disabled: true
201+
disabled: false
202+
exclude: [""]
203+
arguments:
204+
- "fmt.Fprint"
205+
- "fmt.Fprintf"
206+
- "fmt.Fprintln"
207+
- "fmt.Print"
208+
- "fmt.Printf"
209+
- "fmt.Println"
210+
- "strings.Builder.WriteByte"
175211
- name: unused-receiver
176212
arguments:
177213
- allowRegex: ^_

cmd/datasource-syncer/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ func main() {
135135

136136
dsSuccessfullyUpdated := []string{}
137137
dsErrors := []string{}
138-
datasourceUIDs := strings.Split(*datasourceUIDList, ",")
139-
for _, datasourceUID := range datasourceUIDs {
138+
for datasourceUID := range strings.SplitSeq(*datasourceUIDList, ",") {
140139
datasourceUID = strings.TrimSpace(datasourceUID)
141140
if datasourceUID == "" {
142141
continue
@@ -290,7 +289,7 @@ func buildUpdateDataSourceRequest(dataSource grafana.DataSource, token string) (
290289
}
291290
authHeaderValue := fmt.Sprintf("%s%d", httpHeaderValue, x)
292291
if dataSource.SecureJSONData == nil {
293-
dataSource.SecureJSONData = map[string]interface{}{}
292+
dataSource.SecureJSONData = map[string]any{}
294293
}
295294
// Add token to SecureJSONData e.g. httpHeaderValue1: Bearer 123.
296295
dataSource.SecureJSONData[authHeaderValue] = fmt.Sprintf("Bearer %s", token)

cmd/datasource-syncer/main_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
3636
name: "OK",
3737
input: grafana.DataSource{
3838
Type: "prometheus",
39-
JSONData: map[string]interface{}{},
39+
JSONData: map[string]any{},
4040
},
4141
want: grafana.DataSource{
4242
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
4343
Type: "prometheus",
44-
JSONData: map[string]interface{}{
44+
JSONData: map[string]any{
4545
"httpHeaderName1": "Authorization",
4646
"httpMethod": "GET",
4747
"prometheusType": "Prometheus",
4848
"prometheusVersion": "2.40.0",
4949
"queryTimeout": "2m",
5050
"timeout": "120",
5151
},
52-
SecureJSONData: map[string]interface{}{
52+
SecureJSONData: map[string]any{
5353
"httpHeaderValue1": "Bearer 12345",
5454
},
5555
},
@@ -59,15 +59,15 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
5959
input: grafana.DataSource{
6060
URL: "http://localhost:9090",
6161
Type: "prometheus",
62-
JSONData: map[string]interface{}{
62+
JSONData: map[string]any{
6363
"httpHeaderName1": "X-Custom-Header",
6464
"httpHeaderName2": "X-Custom-Header2",
6565
},
6666
},
6767
want: grafana.DataSource{
6868
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
6969
Type: "prometheus",
70-
JSONData: map[string]interface{}{
70+
JSONData: map[string]any{
7171
"httpHeaderName1": "X-Custom-Header",
7272
"httpHeaderName2": "X-Custom-Header2",
7373
"httpHeaderName3": "Authorization",
@@ -77,7 +77,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
7777
"queryTimeout": "2m",
7878
"timeout": "120",
7979
},
80-
SecureJSONData: map[string]interface{}{
80+
SecureJSONData: map[string]any{
8181
"httpHeaderValue3": "Bearer 12345",
8282
},
8383
},
@@ -87,7 +87,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
8787
input: grafana.DataSource{
8888
URL: "http://localhost:9090",
8989
Type: "prometheus",
90-
JSONData: map[string]interface{}{
90+
JSONData: map[string]any{
9191
"httpHeaderName1": "X-Custom-Header",
9292
"httpHeaderName2": "Authorization",
9393
"httpHeaderName3": "X-Custom-Header3",
@@ -99,7 +99,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
9999
want: grafana.DataSource{
100100
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
101101
Type: "prometheus",
102-
JSONData: map[string]interface{}{
102+
JSONData: map[string]any{
103103
"httpHeaderName1": "X-Custom-Header",
104104
"httpHeaderName2": "Authorization",
105105
"httpHeaderName3": "X-Custom-Header3",
@@ -109,7 +109,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
109109
"queryTimeout": "2m",
110110
"timeout": "120",
111111
},
112-
SecureJSONData: map[string]interface{}{
112+
SecureJSONData: map[string]any{
113113
"httpHeaderValue2": "Bearer 12345",
114114
},
115115
},
@@ -119,7 +119,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
119119
input: grafana.DataSource{
120120
Type: "prometheus",
121121
URL: "http://localhost:9090",
122-
JSONData: map[string]interface{}{
122+
JSONData: map[string]any{
123123
"httpHeaderName1": "X-Custom-Header",
124124
"httpHeaderName2": "X-Custom-Header2",
125125
"httpHeaderName3": "Authorization",
@@ -131,7 +131,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
131131
want: grafana.DataSource{
132132
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
133133
Type: "prometheus",
134-
JSONData: map[string]interface{}{
134+
JSONData: map[string]any{
135135
"httpHeaderName1": "X-Custom-Header",
136136
"httpHeaderName2": "X-Custom-Header2",
137137
"httpHeaderName3": "Authorization",
@@ -141,7 +141,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
141141
"queryTimeout": "2m",
142142
"timeout": "120",
143143
},
144-
SecureJSONData: map[string]interface{}{
144+
SecureJSONData: map[string]any{
145145
"httpHeaderValue3": "Bearer 12345",
146146
},
147147
},
@@ -151,7 +151,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
151151
input: grafana.DataSource{
152152
Type: "prometheus",
153153
URL: "http://localhost:9090",
154-
JSONData: map[string]interface{}{
154+
JSONData: map[string]any{
155155
"prometheusType": "Prometheus",
156156
"prometheusVersion": "2.42.0",
157157
"queryTimeout": "3m",
@@ -161,15 +161,15 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
161161
want: grafana.DataSource{
162162
URL: "https://monitoring.googleapis.com/v1/projects/test/location/global/prometheus/",
163163
Type: "prometheus",
164-
JSONData: map[string]interface{}{
164+
JSONData: map[string]any{
165165
"httpHeaderName1": "Authorization",
166166
"httpMethod": "GET",
167167
"prometheusType": "Prometheus",
168168
"prometheusVersion": "2.42.0",
169169
"queryTimeout": "3m",
170170
"timeout": "160",
171171
},
172-
SecureJSONData: map[string]interface{}{
172+
SecureJSONData: map[string]any{
173173
"httpHeaderValue1": "Bearer 12345",
174174
},
175175
},
@@ -188,7 +188,7 @@ func TestBuildUpdateDataSourceRequest(t *testing.T) {
188188
got, err := buildUpdateDataSourceRequest(tt.input, accessToken)
189189
if tt.fail {
190190
if err == nil {
191-
t.Fatalf("unexpectedly succeeded")
191+
t.Fatal("unexpectedly succeeded")
192192
}
193193
return
194194
}

cmd/frontend/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ var (
6969
targetURLStr = flag.String("query.target-url", fmt.Sprintf("https://monitoring.googleapis.com/v1/projects/%s/location/global/prometheus", projectIDVar),
7070
fmt.Sprintf("The URL to forward authenticated requests to. (%s is replaced with the --query.project-id flag.)", projectIDVar))
7171

72+
//nolint:revive // Allow insecure http connection
7273
ruleEndpointURLStrings = flag.String("rules.target-urls", "http://rule-evaluator.gmp-system.svc.cluster.local:19092", "Comma separated lists of URLs that support HTTP Prometheus Alert and Rules APIs (/api/v1/alerts, /api/v1/rules), e.g. GMP rule-evaluator. NOTE: Results are merged as-is, no sorting and deduplication is done.")
7374

7475
logLevel = flag.String("log.level", "info",
@@ -126,7 +127,7 @@ func main() {
126127
}
127128

128129
var ruleEndpointURLs []url.URL
129-
for _, ruleEndpointURLStr := range strings.Split(*ruleEndpointURLStrings, ",") {
130+
for ruleEndpointURLStr := range strings.SplitSeq(*ruleEndpointURLStrings, ",") {
130131
ruleEndpointURL, err := url.Parse(strings.TrimSpace(ruleEndpointURLStr))
131132
if err != nil || ruleEndpointURL == nil {
132133
_ = level.Error(logger).Log("msg", "parsing rule endpoint URL failed", "err", err, "url", strings.TrimSpace(ruleEndpointURLStr))
@@ -187,11 +188,11 @@ func main() {
187188

188189
http.HandleFunc("/-/healthy", func(w http.ResponseWriter, _ *http.Request) {
189190
w.WriteHeader(http.StatusOK)
190-
fmt.Fprintf(w, "Prometheus frontend is Healthy.\n")
191+
fmt.Fprint(w, "Prometheus frontend is Healthy.\n")
191192
})
192193
http.HandleFunc("/-/ready", func(w http.ResponseWriter, _ *http.Request) {
193194
w.WriteHeader(http.StatusOK)
194-
fmt.Fprintf(w, "Prometheus frontend is Ready.\n")
195+
fmt.Fprint(w, "Prometheus frontend is Ready.\n")
195196
})
196197

197198
http.Handle("/", authenticate(ui.Handler(externalURL)))

cmd/rule-evaluator/internal/api.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ const (
5454
// https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview
5555
// response is the prometheus-compatible response format.
5656
type response struct {
57-
Status status `json:"status"`
58-
Data interface{} `json:"data,omitempty"`
59-
ErrorType errorType `json:"errorType,omitempty"`
60-
Error string `json:"error,omitempty"`
61-
Warnings []string `json:"warnings,omitempty"`
62-
Infos []string `json:"infos,omitempty"`
57+
Status status `json:"status"`
58+
Data any `json:"data,omitempty"`
59+
ErrorType errorType `json:"errorType,omitempty"`
60+
Error string `json:"error,omitempty"`
61+
Warnings []string `json:"warnings,omitempty"`
62+
Infos []string `json:"infos,omitempty"`
6363
}
6464

6565
// RuleRetriever provides a list of active rules.
@@ -102,7 +102,7 @@ func (api *API) writeResponse(w http.ResponseWriter, httpResponseCode int, endpo
102102
}
103103
}
104104

105-
func (api *API) writeSuccessResponse(w http.ResponseWriter, httpResponseCode int, endpointURI string, data interface{}) {
105+
func (api *API) writeSuccessResponse(w http.ResponseWriter, httpResponseCode int, endpointURI string, data any) {
106106
api.writeResponse(w, httpResponseCode, endpointURI, response{
107107
Status: statusSuccess,
108108
Data: data,

cmd/rule-evaluator/internal/rules_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func TestAPI_HandleRulesEndpoint(t *testing.T) {
8787
},
8888
}
8989
for _, tt := range tests {
90-
tt := tt //nolint:copyloopvar // parallel test
9190
t.Run(tt.name, func(t *testing.T) {
9291
t.Parallel()
9392

@@ -480,7 +479,6 @@ func TestAPI_groupToAPIGroup(t *testing.T) {
480479
},
481480
}
482481
for _, tt := range tests {
483-
tt := tt //nolint:copyloopvar // parallel test
484482
t.Run(tt.name, func(t *testing.T) {
485483
t.Parallel()
486484
api := &API{logger: log.NewNopLogger()}

cmd/rule-evaluator/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func main() {
342342
})
343343
http.HandleFunc("/-/ready", func(w http.ResponseWriter, _ *http.Request) {
344344
w.WriteHeader(http.StatusOK)
345-
fmt.Fprintf(w, "rule-evaluator is Ready.\n")
345+
fmt.Fprintln(w, "rule-evaluator is Ready.")
346346
})
347347
// https://prometheus.io/docs/prometheus/latest/querying/api/#runtime-information
348348
// Useful for knowing whether a config reload was successful.
@@ -685,7 +685,7 @@ func (m *configMetrics) setFailure() {
685685
// reloadConfig applies the configuration files.
686686
func reloadConfig(filename string, logger log.Logger, metrics *configMetrics, rls ...reloader) (err error) {
687687
start := time.Now()
688-
timings := []interface{}{}
688+
timings := []any{}
689689
_ = level.Info(logger).Log("msg", "Loading configuration file", "filename", filename)
690690

691691
content, err := os.ReadFile(filename)
@@ -713,7 +713,7 @@ func reloadConfig(filename string, logger log.Logger, metrics *configMetrics, rl
713713
}
714714

715715
metrics.setSuccess()
716-
l := []interface{}{"msg", "Completed loading of configuration file", "filename", filename, "totalDuration", time.Since(start)}
716+
l := []any{"msg", "Completed loading of configuration file", "filename", filename, "totalDuration", time.Since(start)}
717717
_ = level.Info(logger).Log(append(l, timings...)...)
718718
return nil
719719
}
@@ -853,6 +853,7 @@ func (s *queryStorage) Querier(mint, maxt int64) (storage.Querier, error) {
853853
type queryAccess struct {
854854
// storage.LabelQuerier satisfies the interface. Calling related methods will result in panic.
855855
storage.LabelQuerier
856+
856857
api v1.API
857858
mint int64
858859
maxt int64

0 commit comments

Comments
 (0)