Skip to content

Commit dd672bc

Browse files
committed
chore: enable hugeParam rule from go-critic
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent c8a612b commit dd672bc

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ linters:
2828
- builtinShadow
2929
- deferInLoop
3030
- exitAfterDefer
31-
- hugeParam
3231
- importShadow
3332
- unnamedResult
3433
enable-all: true

interceptors/realip/realip_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type testCase struct {
8787
expectedIP netip.Addr
8888
}
8989

90-
func (c testCase) optsFromTesCase() []Option {
90+
func (c *testCase) optsFromTestCase() []Option {
9191
return []Option{
9292
WithTrustedPeers(c.trustedPeers),
9393
WithTrustedProxies(c.trustedProxies),
@@ -96,8 +96,8 @@ func (c testCase) optsFromTesCase() []Option {
9696
}
9797
}
9898

99-
func testUnaryServerInterceptor(t *testing.T, c testCase) {
100-
interceptor := UnaryServerInterceptorOpts(c.optsFromTesCase()...)
99+
func testUnaryServerInterceptor(t *testing.T, c *testCase) {
100+
interceptor := UnaryServerInterceptorOpts(c.optsFromTestCase()...)
101101
handler := func(ctx context.Context, req any) (any, error) {
102102
ip, _ := FromContext(ctx)
103103

@@ -121,8 +121,8 @@ func testUnaryServerInterceptor(t *testing.T, c testCase) {
121121
assert.NoError(t, err)
122122
}
123123

124-
func testStreamServerInterceptor(t *testing.T, c testCase) {
125-
interceptor := StreamServerInterceptorOpts(c.optsFromTesCase()...)
124+
func testStreamServerInterceptor(t *testing.T, c *testCase) {
125+
interceptor := StreamServerInterceptorOpts(c.optsFromTestCase()...)
126126
handler := func(srv any, stream grpc.ServerStream) error {
127127
ip, _ := FromContext(stream.Context())
128128

@@ -147,7 +147,7 @@ func testStreamServerInterceptor(t *testing.T, c testCase) {
147147

148148
func TestInterceptor(t *testing.T) {
149149
t.Run("no peer", func(t *testing.T) {
150-
tc := testCase{
150+
tc := &testCase{
151151
// Test that if there is no peer, we don't get an IP.
152152
trustedPeers: localnet,
153153
headerKeys: []string{XForwardedFor},
@@ -165,7 +165,7 @@ func TestInterceptor(t *testing.T) {
165165
})
166166
})
167167
t.Run("trusted peer header csv", func(t *testing.T) {
168-
tc := testCase{
168+
tc := &testCase{
169169
// Test that if the remote peer is trusted and the header contains
170170
// a comma separated list of valid IPs, we get right most one.
171171
trustedPeers: localnet,
@@ -184,7 +184,7 @@ func TestInterceptor(t *testing.T) {
184184
})
185185
})
186186
t.Run("trusted proxy list with XForwardedFor", func(t *testing.T) {
187-
tc := testCase{
187+
tc := &testCase{
188188
// Test that if the remote peer is trusted and the header contains
189189
// a comma separated list of valid IPs,
190190
// we get the first going from right to left that is not in local net
@@ -205,7 +205,7 @@ func TestInterceptor(t *testing.T) {
205205
})
206206
})
207207
t.Run("trusted proxy list private net with XForwardedFor", func(t *testing.T) {
208-
tc := testCase{
208+
tc := &testCase{
209209
// Test that if the remote peer is trusted and the header contains
210210
// a comma separated list of valid IPs,
211211
// we get the first going from right to left that is not in private net
@@ -226,7 +226,7 @@ func TestInterceptor(t *testing.T) {
226226
})
227227
})
228228
t.Run("trusted proxy count with XForwardedFor", func(t *testing.T) {
229-
tc := testCase{
229+
tc := &testCase{
230230
// Test that if the remote peer is trusted and the header contains
231231
// a comma separated list of valid IPs, we get right most one -1 proxiesCount.
232232
trustedPeers: localnet,
@@ -246,7 +246,7 @@ func TestInterceptor(t *testing.T) {
246246
})
247247
})
248248
t.Run("wrong trusted proxy count with XForwardedFor", func(t *testing.T) {
249-
tc := testCase{
249+
tc := &testCase{
250250
// Test that if the remote peer is trusted and the header contains
251251
// a comma separated list of valid IPs,
252252
// we get peer ip as the proxiesCount is wrongly configured
@@ -267,7 +267,7 @@ func TestInterceptor(t *testing.T) {
267267
})
268268
})
269269
t.Run("trusted peer single", func(t *testing.T) {
270-
tc := testCase{
270+
tc := &testCase{
271271
// Test that if the remote peer is trusted and the header contains
272272
// a single valid IP, we get that IP.
273273
trustedPeers: localnet,
@@ -286,7 +286,7 @@ func TestInterceptor(t *testing.T) {
286286
})
287287
})
288288
t.Run("trusted peer multiple", func(t *testing.T) {
289-
tc := testCase{
289+
tc := &testCase{
290290
// Test that if the trusted peers list is larger than 1 network and
291291
// the remote peer is in the third network, we get the right IP.
292292
trustedPeers: privatenet,
@@ -305,7 +305,7 @@ func TestInterceptor(t *testing.T) {
305305
})
306306
})
307307
t.Run("untrusted peer single", func(t *testing.T) {
308-
tc := testCase{
308+
tc := &testCase{
309309
// Test that if the remote peer is not trusted and the header
310310
// contains a single valid IP, we get that the peer IP.
311311
trustedPeers: localnet,
@@ -324,7 +324,7 @@ func TestInterceptor(t *testing.T) {
324324
})
325325
})
326326
t.Run("trusted peer multiple headers", func(t *testing.T) {
327-
tc := testCase{
327+
tc := &testCase{
328328
// Test that if the peer is trusted and several headers are
329329
// provided, the interceptor reads the IP from the first header in
330330
// the list.
@@ -345,7 +345,7 @@ func TestInterceptor(t *testing.T) {
345345
})
346346
})
347347
t.Run("trusted peer multiple header configured single provided", func(t *testing.T) {
348-
tc := testCase{
348+
tc := &testCase{
349349
// Test that if the peer is trusted and several headers are
350350
// configured, but only one is provided, the interceptor reads the
351351
// IP from the provided header.
@@ -365,7 +365,7 @@ func TestInterceptor(t *testing.T) {
365365
})
366366
})
367367
t.Run("trusted peer multiple header configured none provided", func(t *testing.T) {
368-
tc := testCase{
368+
tc := &testCase{
369369
// Test that if the peer is trusted and several headers are, but no
370370
// header is provided, the interceptor reads the IP from the peer.
371371
//
@@ -384,7 +384,7 @@ func TestInterceptor(t *testing.T) {
384384
})
385385
})
386386
t.Run("untrusted peer multiple headers", func(t *testing.T) {
387-
tc := testCase{
387+
tc := &testCase{
388388
// Test that if the peer is not trusted, but several headers are
389389
// provided, the interceptor reads the IP from peer.
390390
trustedPeers: nil,
@@ -403,7 +403,7 @@ func TestInterceptor(t *testing.T) {
403403
})
404404
})
405405
t.Run("untrusted peer multiple header configured single provided", func(t *testing.T) {
406-
tc := testCase{
406+
tc := &testCase{
407407
// Test that if the peer is not trusted and several headers are
408408
// configured, but only one is provided, the interceptor reads the
409409
// IP from the peer.
@@ -426,7 +426,7 @@ func TestInterceptor(t *testing.T) {
426426
})
427427
})
428428
t.Run("trusted peer malformed header", func(t *testing.T) {
429-
tc := testCase{
429+
tc := &testCase{
430430
// Test that if the peer is trusted, but the provided headers
431431
// contain malformed IP addresses, the interceptor reads the IP
432432
// from the peer.
@@ -446,7 +446,7 @@ func TestInterceptor(t *testing.T) {
446446
})
447447
})
448448
t.Run("ipv6 from grpc peer", func(t *testing.T) {
449-
tc := testCase{
449+
tc := &testCase{
450450
trustedPeers: localnet,
451451
headerKeys: []string{},
452452
peer: localhost6Peer(),
@@ -460,7 +460,7 @@ func TestInterceptor(t *testing.T) {
460460
})
461461
})
462462
t.Run("ipv6 from header", func(t *testing.T) {
463-
tc := testCase{
463+
tc := &testCase{
464464
trustedPeers: privatenet,
465465
headerKeys: []string{XForwardedFor},
466466
inputHeaders: map[string]string{
@@ -477,7 +477,7 @@ func TestInterceptor(t *testing.T) {
477477
})
478478
})
479479
t.Run("unix", func(t *testing.T) {
480-
tc := testCase{
480+
tc := &testCase{
481481
trustedPeers: localnet,
482482
headerKeys: []string{XRealIp},
483483
peer: &peer.Peer{
@@ -493,7 +493,7 @@ func TestInterceptor(t *testing.T) {
493493
})
494494
})
495495
t.Run("header casing", func(t *testing.T) {
496-
tc := testCase{
496+
tc := &testCase{
497497
// Test that header casing is ignored.
498498
trustedPeers: localnet,
499499
headerKeys: []string{XRealIp},

providers/prometheus/client_options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func WithClientCounterOptions(opts ...CounterOption) ClientMetricsOption {
3636
func WithClientHandlingTimeHistogram(opts ...HistogramOption) ClientMetricsOption {
3737
return func(o *clientMetricsConfig) {
3838
o.clientHandledHistogram = prometheus.NewHistogramVec(
39-
histogramOptions(opts).apply(prometheus.HistogramOpts{
39+
histogramOptions(opts).apply(&prometheus.HistogramOpts{
4040
Name: "grpc_client_handling_seconds",
4141
Help: "Histogram of response latency (seconds) of the gRPC until it is finished by the application.",
4242
Buckets: prometheus.DefBuckets,
@@ -51,7 +51,7 @@ func WithClientHandlingTimeHistogram(opts ...HistogramOption) ClientMetricsOptio
5151
func WithClientStreamRecvHistogram(opts ...HistogramOption) ClientMetricsOption {
5252
return func(o *clientMetricsConfig) {
5353
o.clientStreamRecvHistogram = prometheus.NewHistogramVec(
54-
histogramOptions(opts).apply(prometheus.HistogramOpts{
54+
histogramOptions(opts).apply(&prometheus.HistogramOpts{
5555
Name: "grpc_client_msg_recv_handling_seconds",
5656
Help: "Histogram of response latency (seconds) of the gRPC single message receive.",
5757
Buckets: prometheus.DefBuckets,
@@ -66,7 +66,7 @@ func WithClientStreamRecvHistogram(opts ...HistogramOption) ClientMetricsOption
6666
func WithClientStreamSendHistogram(opts ...HistogramOption) ClientMetricsOption {
6767
return func(o *clientMetricsConfig) {
6868
o.clientStreamSendHistogram = prometheus.NewHistogramVec(
69-
histogramOptions(opts).apply(prometheus.HistogramOpts{
69+
histogramOptions(opts).apply(&prometheus.HistogramOpts{
7070
Name: "grpc_client_msg_send_handling_seconds",
7171
Help: "Histogram of response latency (seconds) of the gRPC single message send.",
7272
Buckets: prometheus.DefBuckets,

providers/prometheus/options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ type HistogramOption func(*prometheus.HistogramOpts)
5959

6060
type histogramOptions []HistogramOption
6161

62-
func (ho histogramOptions) apply(o prometheus.HistogramOpts) prometheus.HistogramOpts {
62+
func (ho histogramOptions) apply(o *prometheus.HistogramOpts) prometheus.HistogramOpts {
6363
for _, f := range ho {
64-
f(&o)
64+
f(o)
6565
}
66-
return o
66+
return *o
6767
}
6868

6969
// WithHistogramBuckets allows you to specify custom bucket ranges for histograms if EnableHandlingTimeHistogram is on.

providers/prometheus/server_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewServerMetrics(opts ...ServerMetricsOption) *ServerMetrics {
4343
if config.enableHistogram {
4444
histogramLabels := append(defaultLabels, config.contextLabels...)
4545
serverHandledHistogram = prometheus.NewHistogramVec(
46-
histogramOptions(config.histogramOpts).apply(prometheus.HistogramOpts{
46+
histogramOptions(config.histogramOpts).apply(&prometheus.HistogramOpts{
4747
Name: "grpc_server_handling_seconds",
4848
Help: "Histogram of response latency (seconds) of gRPC that had been application-level handled by the server.",
4949
Buckets: prometheus.DefBuckets,

0 commit comments

Comments
 (0)