Skip to content

Commit 13dabcf

Browse files
committed
update modernize to v0.22.0
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
1 parent 29b6167 commit 13dabcf

7 files changed

Lines changed: 28 additions & 24 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ check-protos: clean-protos protos
243243
@git diff --exit-code -- $(PROTO_GOS)
244244

245245
modernize:
246-
GOTOOLCHAIN=auto go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.21.0 -fix ./...
246+
GOTOOLCHAIN=auto go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.22.0 -fix ./...
247247

248248
# Generates the config file documentation.
249249
doc: clean-doc

integration/e2e/scenario.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package e2e
33
import (
44
"fmt"
55
"os"
6+
"slices"
67
"strings"
78
"sync"
89

@@ -151,14 +152,14 @@ func (s *Scenario) shutdown() {
151152
// Kill the services in parallel. We still iterate in reverse order
152153
// to respect service dependencies, but we kill them concurrently.
153154
var wg sync.WaitGroup
154-
for i := len(s.services) - 1; i >= 0; i-- {
155+
for _, v := range slices.Backward(s.services) {
155156
wg.Add(1)
156157
go func(service Service) {
157158
defer wg.Done()
158159
if err := service.Kill(); err != nil {
159160
logger.Log("Unable to kill service", service.Name(), ":", err.Error())
160161
}
161-
}(s.services[i])
162+
}(v)
162163
}
163164
wg.Wait()
164165

pkg/cortex/modules_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func checkSensitiveFields(t reflect.Type, prefix string, pattern *regexp.Regexp,
315315
path := prefix + f.Name
316316

317317
yamlTag := f.Tag.Get("yaml")
318-
yamlName := strings.Split(yamlTag, ",")[0]
318+
yamlName, _, _ := strings.Cut(yamlTag, ",")
319319

320320
if pattern.MatchString(yamlName) && f.Type.Kind() == reflect.String {
321321
*violations = append(*violations, path+" (yaml:\""+yamlName+"\")")

pkg/querier/blocks_finder_bucket_scan.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"maps"
66
"path"
77
"path/filepath"
8+
"slices"
89
"sort"
910
"strings"
1011
"sync"
@@ -133,13 +134,13 @@ func (d *BucketScanBlocksFinder) GetBlocks(_ context.Context, userID string, min
133134
// Given we do expect the large majority of queries to have a time range close
134135
// to "now", we're going to find matching blocks iterating the list in reverse order.
135136
var matchingMetas bucketindex.Blocks
136-
for i := len(userMetas) - 1; i >= 0; i-- {
137-
if userMetas[i].Within(minT, maxT) {
138-
matchingMetas = append(matchingMetas, userMetas[i])
137+
for _, userMeta := range slices.Backward(userMetas) {
138+
if userMeta.Within(minT, maxT) {
139+
matchingMetas = append(matchingMetas, userMeta)
139140
}
140141

141142
// We can safely break the loop because metas are sorted by MaxTime.
142-
if userMetas[i].MaxTime <= minT {
143+
if userMeta.MaxTime <= minT {
143144
break
144145
}
145146
}

pkg/querier/stats/stats.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ type QueryStats struct {
3333

3434
// Phase tracking fields for timeout classification.
3535
// Stored as UnixNano int64 for atomic operations.
36-
queryStart int64 // nanosecond timestamp when query began
37-
queryEnd int64 // nanosecond timestamp when query finished
38-
queueJoinTime int64 // nanosecond timestamp when request entered scheduler queue
39-
queueLeaveTime int64 // nanosecond timestamp when request left scheduler queue
36+
queryStart atomic.Int64 // nanosecond timestamp when query began
37+
queryEnd atomic.Int64 // nanosecond timestamp when query finished
38+
queueJoinTime atomic.Int64 // nanosecond timestamp when request entered scheduler queue
39+
queueLeaveTime atomic.Int64 // nanosecond timestamp when request left scheduler queue
4040
}
4141

4242
// ContextWithEmptyStats returns a context with empty stats.
@@ -326,7 +326,7 @@ func (s *QueryStats) SetQueryStart(t time.Time) {
326326
return
327327
}
328328

329-
atomic.StoreInt64(&s.queryStart, t.UnixNano())
329+
s.queryStart.Store(t.UnixNano())
330330
}
331331

332332
// LoadQueryStart returns the query start time.
@@ -335,7 +335,7 @@ func (s *QueryStats) LoadQueryStart() time.Time {
335335
return time.Time{}
336336
}
337337

338-
ns := atomic.LoadInt64(&s.queryStart)
338+
ns := s.queryStart.Load()
339339
if ns == 0 {
340340
return time.Time{}
341341
}
@@ -348,7 +348,7 @@ func (s *QueryStats) SetQueryEnd(t time.Time) {
348348
return
349349
}
350350

351-
atomic.StoreInt64(&s.queryEnd, t.UnixNano())
351+
s.queryEnd.Store(t.UnixNano())
352352
}
353353

354354
// LoadQueryEnd returns the query end time.
@@ -357,7 +357,7 @@ func (s *QueryStats) LoadQueryEnd() time.Time {
357357
return time.Time{}
358358
}
359359

360-
ns := atomic.LoadInt64(&s.queryEnd)
360+
ns := s.queryEnd.Load()
361361
if ns == 0 {
362362
return time.Time{}
363363
}
@@ -370,7 +370,7 @@ func (s *QueryStats) SetQueueJoinTime(t time.Time) {
370370
return
371371
}
372372

373-
atomic.StoreInt64(&s.queueJoinTime, t.UnixNano())
373+
s.queueJoinTime.Store(t.UnixNano())
374374
}
375375

376376
// LoadQueueJoinTime returns the queue join time.
@@ -379,7 +379,7 @@ func (s *QueryStats) LoadQueueJoinTime() time.Time {
379379
return time.Time{}
380380
}
381381

382-
ns := atomic.LoadInt64(&s.queueJoinTime)
382+
ns := s.queueJoinTime.Load()
383383
if ns == 0 {
384384
return time.Time{}
385385
}
@@ -392,7 +392,7 @@ func (s *QueryStats) SetQueueLeaveTime(t time.Time) {
392392
return
393393
}
394394

395-
atomic.StoreInt64(&s.queueLeaveTime, t.UnixNano())
395+
s.queueLeaveTime.Store(t.UnixNano())
396396
}
397397

398398
// LoadQueueLeaveTime returns the queue leave time.
@@ -401,7 +401,7 @@ func (s *QueryStats) LoadQueueLeaveTime() time.Time {
401401
return time.Time{}
402402
}
403403

404-
ns := atomic.LoadInt64(&s.queueLeaveTime)
404+
ns := s.queueLeaveTime.Load()
405405
if ns == 0 {
406406
return time.Time{}
407407
}

pkg/querier/tripperware/roundtrip.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"context"
2020
"io"
2121
"net/http"
22+
"slices"
2223
"strings"
2324
"time"
2425

@@ -99,8 +100,8 @@ type roundTripper struct {
99100
// ie Merge(f,g,h).Wrap(handler) == f.Wrap(g.Wrap(h.Wrap(handler)))
100101
func MergeMiddlewares(middleware ...Middleware) Middleware {
101102
return MiddlewareFunc(func(next Handler) Handler {
102-
for i := len(middleware) - 1; i >= 0; i-- {
103-
next = middleware[i].Wrap(next)
103+
for _, m := range slices.Backward(middleware) {
104+
next = m.Wrap(next)
104105
}
105106
return next
106107
})

pkg/util/grpcclient/unwrap_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package grpcclient
33
import (
44
"context"
55
"errors"
6+
"slices"
67
"testing"
78

89
otgrpc "github.com/opentracing-contrib/go-grpc"
@@ -66,12 +67,12 @@ func TestUnwrapErrorStreamClientInterceptor(t *testing.T) {
6667

6768
// Chain the interceptors
6869
chainedStreamer := mockStreamer
69-
for i := len(interceptors) - 1; i >= 0; i-- {
70+
for _, interceptor := range slices.Backward(interceptors) {
7071
chainedStreamer = func(interceptor grpc.StreamClientInterceptor, next grpc.Streamer) grpc.Streamer {
7172
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) {
7273
return interceptor(ctx, desc, cc, method, next, opts...)
7374
}
74-
}(interceptors[i], chainedStreamer)
75+
}(interceptor, chainedStreamer)
7576
}
7677

7778
// Call the chained streamer

0 commit comments

Comments
 (0)