Skip to content

Commit 97af51d

Browse files
jorbaumchombium
authored andcommitted
Upgrade to golangci-lint v2 for improved linting
Noteworthy changes in golangci-lint v2: * New config format (migrated with `migrate` command) * Default timeout is now 0 instead of 1 minute. Also fixes issues reported by golangci-lint v2: * Do not use dot imports for sources under `cmd`. * Have nicer logs * Remove redundant type `int` * Use `fmt.Fprintf(x, ...)` instead of `x.Write(fmt.Sprintf(...))`
1 parent dc92af7 commit 97af51d

File tree

13 files changed

+75
-54
lines changed

13 files changed

+75
-54
lines changed

scripts/subtests/lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set +e
99
golangci_lint_executable=$(which golangci-lint)
1010
set -e
1111
if [ -z "${golangci_lint_executable}" ] || [ ! -x "${golangci_lint_executable}" ]; then
12-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
12+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
1313
fi
1414

1515
pushd "${SCRIPT_DIR}/../../src" > /dev/null

src/.golangci.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
version: "2"
2+
13
run:
2-
# Timeout for analysis.
3-
# Default: 1m.
4+
# Timeout full work, e.g. 30s, 5m.
5+
# Default: none
46
timeout: 5m
57

68
linters:
@@ -13,9 +15,28 @@ linters:
1315
- gosec
1416
# Enforces standards of using ginkgo and gomega.
1517
- ginkgolinter
18+
exclusions:
19+
generated: lax
20+
presets:
21+
- comments
22+
- common-false-positives
23+
- legacy
24+
- std-error-handling
25+
paths:
26+
- third_party$
27+
- builtin$
28+
- examples$
1629

1730
issues:
1831
# Disable max issues per linter.
1932
max-issues-per-linter: 0
2033
# Disable max same issues.
2134
max-same-issues: 0
35+
36+
formatters:
37+
exclusions:
38+
generated: lax
39+
paths:
40+
- third_party$
41+
- builtin$
42+
- examples$

src/cmd/cf-auth-proxy/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"code.cloudfoundry.org/go-envstruct"
2323
client "code.cloudfoundry.org/go-log-cache/v3"
2424
"code.cloudfoundry.org/log-cache/internal/auth"
25-
. "code.cloudfoundry.org/log-cache/internal/cfauthproxy"
25+
"code.cloudfoundry.org/log-cache/internal/cfauthproxy"
2626
"code.cloudfoundry.org/log-cache/internal/plumbing"
2727
"code.cloudfoundry.org/log-cache/internal/promql"
2828
)
@@ -109,7 +109,7 @@ func main() {
109109

110110
if cfg.ProxyCAPath != "" {
111111
proxyCACertPool := loadCA(cfg.ProxyCAPath, loggr)
112-
metaHTTPClient.Transport = NewTransportWithRootCA(proxyCACertPool)
112+
metaHTTPClient.Transport = cfauthproxy.NewTransportWithRootCA(proxyCACertPool)
113113
}
114114

115115
metaFetcher := client.NewClient(
@@ -125,26 +125,26 @@ func main() {
125125
capiClient,
126126
)
127127

128-
proxyOptions := []CFAuthProxyOption{
129-
WithAuthMiddleware(middlewareProvider.Middleware),
128+
proxyOptions := []cfauthproxy.CFAuthProxyOption{
129+
cfauthproxy.WithAuthMiddleware(middlewareProvider.Middleware),
130130
}
131131

132132
if cfg.ProxyCAPath != "" {
133133
proxyCACertPool := loadCA(cfg.ProxyCAPath, loggr)
134-
proxyOptions = append(proxyOptions, WithCFAuthProxyCACertPool(proxyCACertPool))
134+
proxyOptions = append(proxyOptions, cfauthproxy.WithCFAuthProxyCACertPool(proxyCACertPool))
135135
}
136136

137137
if cfg.PromQLUnimplemented {
138-
proxyOptions = append(proxyOptions, WithPromMiddleware(promql.UnimplementedMiddleware))
138+
proxyOptions = append(proxyOptions, cfauthproxy.WithPromMiddleware(promql.UnimplementedMiddleware))
139139
}
140140

141141
if cfg.CertPath == "" && cfg.KeyPath == "" {
142-
proxyOptions = append(proxyOptions, WithCFAuthProxyTLSDisabled())
142+
proxyOptions = append(proxyOptions, cfauthproxy.WithCFAuthProxyTLSDisabled())
143143
} else {
144-
proxyOptions = append(proxyOptions, WithCFAuthProxyTLSServer(cfg.CertPath, cfg.KeyPath))
144+
proxyOptions = append(proxyOptions, cfauthproxy.WithCFAuthProxyTLSServer(cfg.CertPath, cfg.KeyPath))
145145
}
146146

147-
proxy := NewCFAuthProxy(
147+
proxy := cfauthproxy.NewCFAuthProxy(
148148
gatewayURL.String(),
149149
cfg.Addr,
150150
proxyOptions...,
@@ -169,7 +169,7 @@ func main() {
169169

170170
accessLogger := auth.NewAccessLogger(accessLog)
171171
accessMiddleware := auth.NewAccessMiddleware(accessLogger, cfg.InternalIP, localPort)
172-
WithAccessMiddleware(accessMiddleware)(proxy)
172+
cfauthproxy.WithAccessMiddleware(accessMiddleware)(proxy)
173173
}
174174

175175
proxy.Start(uaaClient.RefreshTokenKeys)

src/cmd/gateway/main.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
//nolint: gosec
1515
_ "net/http/pprof"
1616

17-
. "code.cloudfoundry.org/log-cache/internal/gateway"
17+
"code.cloudfoundry.org/log-cache/internal/gateway"
1818
"code.cloudfoundry.org/log-cache/internal/plumbing"
1919
"google.golang.org/grpc"
2020
"google.golang.org/grpc/credentials"
@@ -67,14 +67,14 @@ func main() {
6767
go func() { log.Println("PPROF SERVER STOPPED " + pprofServer.ListenAndServe().Error()) }()
6868
}
6969

70-
gatewayOptions := []GatewayOption{
71-
WithGatewayLogger(gatewayLoggr),
72-
WithGatewayVersion(cfg.Version),
73-
WithGatewayBlock(),
70+
gatewayOptions := []gateway.GatewayOption{
71+
gateway.WithGatewayLogger(gatewayLoggr),
72+
gateway.WithGatewayVersion(cfg.Version),
73+
gateway.WithGatewayBlock(),
7474
}
7575

7676
if cfg.ProxyCertPath != "" || cfg.ProxyKeyPath != "" {
77-
gatewayOptions = append(gatewayOptions, WithGatewayTLSServer(cfg.ProxyCertPath, cfg.ProxyKeyPath))
77+
gatewayOptions = append(gatewayOptions, gateway.WithGatewayTLSServer(cfg.ProxyCertPath, cfg.ProxyKeyPath))
7878
}
7979
if cfg.TLS.HasAnyCredential() {
8080
tlsConfig, err := tlsconfig.Build(
@@ -88,21 +88,21 @@ func main() {
8888
panic(err)
8989
}
9090

91-
gatewayOptions = append(gatewayOptions, WithGatewayLogCacheDialOpts(
91+
gatewayOptions = append(gatewayOptions, gateway.WithGatewayLogCacheDialOpts(
9292
grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig)),
9393
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(50*1024*1024)),
9494
),
9595
)
9696
} else {
97-
gatewayOptions = append(gatewayOptions, WithGatewayLogCacheDialOpts(
97+
gatewayOptions = append(gatewayOptions, gateway.WithGatewayLogCacheDialOpts(
9898
grpc.WithTransportCredentials(insecure.NewCredentials()),
9999
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(50*1024*1024)),
100100
),
101101
)
102102

103103
}
104104

105-
gateway := NewGateway(cfg.LogCacheAddr, cfg.Addr, gatewayOptions...)
105+
gw := gateway.NewGateway(cfg.LogCacheAddr, cfg.Addr, gatewayOptions...)
106106

107-
gateway.Start()
107+
gw.Start()
108108
}

src/cmd/log-cache/main.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"code.cloudfoundry.org/tlsconfig"
1818

1919
"code.cloudfoundry.org/go-envstruct"
20-
. "code.cloudfoundry.org/log-cache/internal/cache"
20+
"code.cloudfoundry.org/log-cache/internal/cache"
2121
"code.cloudfoundry.org/log-cache/internal/plumbing"
2222
"google.golang.org/grpc"
2323
"google.golang.org/grpc/credentials"
@@ -89,17 +89,17 @@ func main() {
8989
}
9090
}(time.Now())
9191

92-
logCacheOptions := []LogCacheOption{
93-
WithAddr(cfg.Addr),
94-
WithMemoryLimitPercent(float64(cfg.MemoryLimitPercent)),
95-
WithMemoryLimit(cfg.MemoryLimit),
96-
WithMaxPerSource(cfg.MaxPerSource),
97-
WithQueryTimeout(cfg.QueryTimeout),
98-
WithTruncationInterval(cfg.TruncationInterval),
99-
WithPrunesPerGC(cfg.PrunesPerGC),
100-
WithIngressBufferSize(cfg.IngressBufferSize),
101-
WithIngressBufferReadBatchSize(cfg.IngressBufferReadBatchSize),
102-
WithIngressBufferReadBatchInterval(cfg.IngressBufferReadBatchInterval),
92+
logCacheOptions := []cache.LogCacheOption{
93+
cache.WithAddr(cfg.Addr),
94+
cache.WithMemoryLimitPercent(float64(cfg.MemoryLimitPercent)),
95+
cache.WithMemoryLimit(cfg.MemoryLimit),
96+
cache.WithMaxPerSource(cfg.MaxPerSource),
97+
cache.WithQueryTimeout(cfg.QueryTimeout),
98+
cache.WithTruncationInterval(cfg.TruncationInterval),
99+
cache.WithPrunesPerGC(cfg.PrunesPerGC),
100+
cache.WithIngressBufferSize(cfg.IngressBufferSize),
101+
cache.WithIngressBufferReadBatchSize(cfg.IngressBufferReadBatchSize),
102+
cache.WithIngressBufferReadBatchInterval(cfg.IngressBufferReadBatchInterval),
103103
}
104104
var transport grpc.DialOption
105105
if cfg.TLS.HasAnyCredential() {
@@ -125,24 +125,24 @@ func main() {
125125
if err != nil {
126126
panic(err)
127127
}
128-
logCacheOptions = append(logCacheOptions, WithServerOpts(grpc.Creds(credentials.NewTLS(tlsConfigServer)), grpc.MaxRecvMsgSize(50*1024*1024)))
128+
logCacheOptions = append(logCacheOptions, cache.WithServerOpts(grpc.Creds(credentials.NewTLS(tlsConfigServer)), grpc.MaxRecvMsgSize(50*1024*1024)))
129129
} else {
130130
transport = grpc.WithTransportCredentials(insecure.NewCredentials())
131131
}
132-
logCacheOptions = append(logCacheOptions, WithClustered(
132+
logCacheOptions = append(logCacheOptions, cache.WithClustered(
133133
cfg.NodeIndex,
134134
cfg.NodeAddrs,
135135
transport,
136136
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(50*1024*1024)),
137137
))
138138

139-
cache := New(
139+
lc := cache.New(
140140
m,
141141
logger,
142142
logCacheOptions...,
143143
)
144144

145-
cache.Start()
145+
lc.Start()
146146
waitForTermination()
147147
}
148148

src/cmd/syslog-server/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"code.cloudfoundry.org/go-envstruct"
1515
metrics "code.cloudfoundry.org/go-metric-registry"
16-
. "code.cloudfoundry.org/log-cache/internal/nozzle"
16+
"code.cloudfoundry.org/log-cache/internal/nozzle"
1717
"code.cloudfoundry.org/log-cache/internal/plumbing"
1818
"code.cloudfoundry.org/log-cache/internal/syslog"
1919
"code.cloudfoundry.org/tlsconfig"
@@ -96,7 +96,7 @@ func main() {
9696

9797
go server.Start()
9898

99-
nozzleOptions := []NozzleOption{}
99+
nozzleOptions := []nozzle.NozzleOption{}
100100
if cfg.LogCacheTLS.HasAnyCredential() {
101101
tlsConfig, err := tlsconfig.Build(
102102
tlsconfig.WithInternalServiceDefaults(),
@@ -108,18 +108,18 @@ func main() {
108108
if err != nil {
109109
panic(err)
110110
}
111-
nozzleOptions = append(nozzleOptions, WithDialOpts(grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))))
111+
nozzleOptions = append(nozzleOptions, nozzle.WithDialOpts(grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))))
112112
} else {
113-
nozzleOptions = append(nozzleOptions, WithDialOpts(grpc.WithTransportCredentials(insecure.NewCredentials())))
113+
nozzleOptions = append(nozzleOptions, nozzle.WithDialOpts(grpc.WithTransportCredentials(insecure.NewCredentials())))
114114
}
115115

116-
nozzle := NewNozzle(
116+
noz := nozzle.NewNozzle(
117117
server,
118118
cfg.LogCacheAddr,
119119
m,
120120
loggr,
121121
nozzleOptions...,
122122
)
123123

124-
nozzle.Start()
124+
noz.Start()
125125
}

src/internal/gateway/gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (g *Gateway) listenAndServe() {
179179
}
180180

181181
func (g *Gateway) handleInfoEndpoint(w http.ResponseWriter, r *http.Request) {
182-
_, err := w.Write([]byte(fmt.Sprintf(`{"version":"%s","vm_uptime":"%d"}`+"\n", g.logCacheVersion, g.uptimeFn())))
182+
_, err := fmt.Fprintf(w, `{"version":"%s","vm_uptime":"%d"}`+"\n", g.logCacheVersion, g.uptimeFn())
183183
if err != nil {
184184
g.log.Println("Cannot send result for the info endpoint")
185185
}

src/internal/promql/promql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func (l *LogCacheQuerier) Select(params *storage.SelectParams, ll ...*labels.Mat
340340
}
341341

342342
if len(sourceIDs) == 0 {
343-
err := fmt.Errorf("Metric '%s' does not have a 'source_id' label.", metric)
343+
err := fmt.Errorf("metric '%s' does not have a 'source_id' label", metric)
344344
l.errf(err)
345345
return nil, nil, err
346346
}

src/internal/routing/local_store_reader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ func (r *LocalStoreReader) Read(ctx context.Context, req *logcache_v1.ReadReques
4949
}
5050

5151
if req.Limit > 1000 {
52-
return nil, fmt.Errorf("Limit (%d) must be 1000 or less", req.Limit)
52+
return nil, fmt.Errorf("limit (%d) must be 1000 or less", req.Limit)
5353
}
5454

5555
if req.Limit < 0 {
56-
return nil, fmt.Errorf("Limit (%d) must be greater than zero", req.Limit)
56+
return nil, fmt.Errorf("limit (%d) must be greater than zero", req.Limit)
5757
}
5858

5959
if req.EndTime == 0 {
@@ -69,7 +69,7 @@ func (r *LocalStoreReader) Read(ctx context.Context, req *logcache_v1.ReadReques
6969
if req.NameFilter != "" {
7070
nameFilter, err = regexp.Compile(req.NameFilter)
7171
if err != nil {
72-
return nil, fmt.Errorf("Name filter must be a valid regular expression: %s", err)
72+
return nil, fmt.Errorf("name filter must be a valid regular expression: %s", err)
7373
}
7474
}
7575

src/internal/routing/routing_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (t *RoutingTable) Lookup(item string) []int {
4747
node := t.hasher.Hash(hashValue)
4848

4949
var result []int
50-
var replicationFactor int = int(t.replicationFactor) //#nosec G115
50+
var replicationFactor = int(t.replicationFactor) //#nosec G115
5151
for n := 0; n < replicationFactor; n++ {
5252
result = append(result, (node+n*replicationFactor)%len(t.addresses))
5353
}

0 commit comments

Comments
 (0)