Skip to content

Commit 73088a9

Browse files
Modernize the entire codebase (#7005)
* modernize the entire codebase Signed-off-by: SungJin1212 <[email protected]> * add CI to modernize check Signed-off-by: SungJin1212 <[email protected]> * fix modernize Signed-off-by: SungJin1212 <[email protected]> * Delete unnecessary b.ResetTimer() Signed-off-by: SungJin1212 <[email protected]> * Remove StringsContain Signed-off-by: SungJin1212 <[email protected]> * delete unnecessary map copy in ingester test Signed-off-by: SungJin1212 <[email protected]> --------- Signed-off-by: SungJin1212 <[email protected]> Signed-off-by: Friedrich Gonzalez <[email protected]> Co-authored-by: Friedrich Gonzalez <[email protected]>
1 parent eab2099 commit 73088a9

File tree

307 files changed

+1423
-1737
lines changed

Some content is hidden

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

307 files changed

+1423
-1737
lines changed

.github/workflows/test-build-deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
run: make BUILD_IN_CONTAINER=false check-doc
4343
- name: Check White Noise.
4444
run: make BUILD_IN_CONTAINER=false check-white-noise
45+
- name: Check Modernize
46+
run: make BUILD_IN_CONTAINER=false check-modernize
4547

4648
test:
4749
runs-on: ubuntu-24.04

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* [FEATURE] Querier: Support for configuring query optimizers and enabling XFunctions in the Thanos engine. #6873
2525
* [FEATURE] Query Frontend: Add support /api/v1/format_query API for formatting queries. #6893
2626
* [FEATURE] Query Frontend: Add support for /api/v1/parse_query API (experimental) to parse a PromQL expression and return it as a JSON-formatted AST (abstract syntax tree). #6978
27+
* [ENHANCEMENT] Modernizes the entire codebase by using go modernize tool. #7005
2728
* [ENHANCEMENT] Overrides Exporter: Expose all fields that can be converted to float64. Also, the label value `max_local_series_per_metric` got renamed to `max_series_per_metric`, and `max_local_series_per_user` got renamed to `max_series_per_user`. #6979
2829
* [ENHANCEMENT] Ingester: Add `cortex_ingester_tsdb_wal_replay_unknown_refs_total` and `cortex_ingester_tsdb_wbl_replay_unknown_refs_total` metrics to track unknown series references during wal/wbl replaying. #6945
2930
* [ENHANCEMENT] Ruler: Emit an error message when the rule synchronization fails. #6902

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ GOVOLUMES= -v $(shell pwd)/.cache:/go/cache:delegated,z \
126126
-v $(shell pwd)/.pkg:/go/pkg:delegated,z \
127127
-v $(shell pwd):/go/src/github.com/cortexproject/cortex:delegated,z
128128

129-
exes $(EXES) protos $(PROTO_GOS) lint test cover shell mod-check check-protos web-build web-pre web-deploy doc: build-image/$(UPTODATE)
129+
exes $(EXES) protos $(PROTO_GOS) lint test cover shell mod-check check-protos web-build web-pre web-deploy doc check-modernize: build-image/$(UPTODATE)
130130
@mkdir -p $(shell pwd)/.pkg
131131
@mkdir -p $(shell pwd)/.cache
132132
@echo
@@ -308,6 +308,12 @@ clean-white-noise:
308308
check-white-noise: clean-white-noise
309309
@git diff --exit-code --quiet -- '*.md' || (echo "Please remove trailing whitespaces running 'make clean-white-noise'" && false)
310310

311+
modernize:
312+
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/[email protected] -fix ./...
313+
314+
check-modernize: modernize
315+
@git diff --exit-code -- . || (echo "Please modernize running 'make modernize'" && false)
316+
311317
web-serve:
312318
cd website && hugo --config config.toml --minify -v server
313319

cmd/cortex/main_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ func TestExpandEnv(t *testing.T) {
225225
}
226226

227227
for _, test := range tests {
228-
test := test
229228
t.Run(test.in, func(t *testing.T) {
230229
_ = os.Setenv("y", "y")
231230
output := expandEnv([]byte(test.in))
@@ -263,7 +262,6 @@ func TestParseConfigFileParameter(t *testing.T) {
263262
{"--config.expand-env --opt1 --config.file=foo", "foo", true},
264263
}
265264
for _, test := range tests {
266-
test := test
267265
t.Run(test.args, func(t *testing.T) {
268266
args := strings.Split(test.args, " ")
269267
configFile, expandENV := parseConfigFileParameter(args)

cmd/thanosconvert/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func main() {
7979

8080
}
8181

82-
func fatal(msg string, args ...interface{}) {
82+
func fatal(msg string, args ...any) {
8383
fmt.Fprintf(os.Stderr, msg+"\n", args...)
8484
os.Exit(1)
8585
}

integration/e2e/composite_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (s *CompositeHTTPService) SumMetrics(metricNames []string, opts ...MetricsO
8484
return nil, fmt.Errorf("unexpected mismatching sum metrics results (got %d, expected %d)", len(partials), len(sums))
8585
}
8686

87-
for i := 0; i < len(sums); i++ {
87+
for i := range sums {
8888
sums[i] += partials[i]
8989
}
9090
}

integration/e2e/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewLogger(w io.Writer) *Logger {
2929
}
3030
}
3131

32-
func (l *Logger) Log(keyvals ...interface{}) error {
32+
func (l *Logger) Log(keyvals ...any) error {
3333
log := strings.Builder{}
3434
log.WriteString(time.Now().Format("15:04:05"))
3535

integration/e2e/metrics.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package e2e
22

33
import (
44
"math"
5+
"slices"
56

67
io_prometheus_client "github.com/prometheus/client_model/go"
78
)
@@ -143,12 +144,7 @@ func EqualsAmong(values ...float64) func(sums ...float64) bool {
143144
if len(sums) != 1 {
144145
panic("equals among: expected one value")
145146
}
146-
for _, value := range values {
147-
if sums[0] == value {
148-
return true
149-
}
150-
}
151-
return false
147+
return slices.Contains(values, sums[0])
152148
}
153149
}
154150

integration/e2e/scenario.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (s *Scenario) shutdown() {
163163
"--filter",
164164
fmt.Sprintf("network=%s", s.networkName),
165165
); err == nil {
166-
for _, containerID := range strings.Split(string(out), "\n") {
166+
for containerID := range strings.SplitSeq(string(out), "\n") {
167167
containerID = strings.TrimSpace(containerID)
168168
if containerID == "" {
169169
continue

integration/e2e/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ type LinePrefixLogger struct {
503503
}
504504

505505
func (w *LinePrefixLogger) Write(p []byte) (n int, err error) {
506-
for _, line := range strings.Split(string(p), "\n") {
506+
for line := range strings.SplitSeq(string(p), "\n") {
507507
// Skip empty lines
508508
line = strings.TrimSpace(line)
509509
if line == "" {
@@ -698,7 +698,7 @@ func (s *HTTPService) WaitRemovedMetric(metricName string, opts ...MetricsOption
698698
func parseDockerIPv4Port(out string) (int, error) {
699699
// The "docker port" output may be multiple lines if both IPv4 and IPv6 are supported,
700700
// so we need to parse each line.
701-
for _, line := range strings.Split(out, "\n") {
701+
for line := range strings.SplitSeq(out, "\n") {
702702
matches := dockerIPv4PortPattern.FindStringSubmatch(strings.TrimSpace(line))
703703
if len(matches) != 2 {
704704
continue

0 commit comments

Comments
 (0)