Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/test-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ jobs:
run: make BUILD_IN_CONTAINER=false mod-check
- name: Check Protos
run: make BUILD_IN_CONTAINER=false check-protos
- name: Check Modernize
run: make BUILD_IN_CONTAINER=false check-modernize

test:
strategy:
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ linters:
enable:
- depguard
- misspell
- modernize
- revive
- sloglint
settings:
Expand Down
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ GOVOLUMES= -v $(shell pwd)/.cache:/go/cache:delegated,z \
-v $(shell pwd)/.pkg:/go/pkg:delegated,z \
-v $(shell pwd):/go/src/github.com/cortexproject/cortex:delegated,z

exes $(EXES) protos $(PROTO_GOS) lint test cover shell mod-check check-protos doc modernize: build-image/$(UPTODATE)
exes $(EXES) protos $(PROTO_GOS) lint test cover shell mod-check check-protos doc: build-image/$(UPTODATE)
@mkdir -p $(shell pwd)/.pkg
@mkdir -p $(shell pwd)/.cache
@echo
Expand Down Expand Up @@ -222,9 +222,6 @@ mod-check:
check-protos: clean-protos protos
@git diff --exit-code -- $(PROTO_GOS)

modernize:
GOTOOLCHAIN=auto go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.23.0 -fix ./...

# Generates the config file documentation.
doc: clean-doc
go run -tags slicelabels ./tools/doc-generator ./docs/configuration/config-file-reference.template > ./docs/configuration/config-file-reference.md
Expand Down Expand Up @@ -283,9 +280,6 @@ clean-white-noise:
check-white-noise: clean-white-noise
@git diff --exit-code --quiet -- '*.md' || (echo "Please remove trailing whitespaces running 'make clean-white-noise'" && false)

check-modernize: modernize
@git diff --exit-code -- . || (echo "Please modernize running 'make modernize'" && false)

web-serve:
cd website && hugo --config config.toml --minify -v server

Expand Down
12 changes: 6 additions & 6 deletions integration/active_series_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func TestActiveSeriesTrackerPerTenant(t *testing.T) {
defer s.Close()

// Write runtime config with per-tenant active series trackers.
runtimeConfig := map[string]interface{}{
"overrides": map[string]interface{}{
"user-1": map[string]interface{}{
runtimeConfig := map[string]any{
"overrides": map[string]any{
"user-1": map[string]any{
"active_series_trackers": []map[string]string{
{"name": "api_metrics", "matchers": `{__name__=~"api_.*"}`},
{"name": "node_metrics", "matchers": `{__name__=~"node_.*"}`},
Expand Down Expand Up @@ -123,9 +123,9 @@ func TestActiveSeriesTrackerPerTenant(t *testing.T) {
require.Equal(t, 0.0, sum[0])

// Now update runtime config: remove node_metrics tracker for user-1.
runtimeConfig2 := map[string]interface{}{
"overrides": map[string]interface{}{
"user-1": map[string]interface{}{
runtimeConfig2 := map[string]any{
"overrides": map[string]any{
"user-1": map[string]any{
"active_series_trackers": []map[string]string{
{"name": "api_metrics", "matchers": `{__name__=~"api_.*"}`},
},
Expand Down
7 changes: 1 addition & 6 deletions integration/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,7 @@ func TestAlertmanagerShardingScaling(t *testing.T) {

// If the number of instances has not yet reached the replication
// factor, then effective replication will be reduced.
var expectedReplication int
if len(instances) <= testCfg.replicationFactor {
expectedReplication = len(instances)
} else {
expectedReplication = testCfg.replicationFactor
}
expectedReplication := min(len(instances), testCfg.replicationFactor)

require.NoError(t, ams.WaitSumMetrics(
e2e.Equals(float64(numUsers*expectedReplication)),
Expand Down
2 changes: 1 addition & 1 deletion integration/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func assertServiceMetricsPrefixes(t *testing.T, serviceType ServiceType, service
blacklist := getBlacklistedMetricsPrefixesByService(serviceType)

// Ensure no metric name matches the blacklisted prefixes.
for _, metricLine := range strings.Split(metrics, "\n") {
for metricLine := range strings.SplitSeq(metrics, "\n") {
metricLine = strings.TrimSpace(metricLine)
if metricLine == "" || strings.HasPrefix(metricLine, "#") {
continue
Expand Down
6 changes: 3 additions & 3 deletions integration/backward_compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func TestMetadataAPIWhenDeployment(t *testing.T) {
metadataMetricNum := 5
metadataPerMetrics := 2
metadata := make([]prompb.MetricMetadata, 0, metadataMetricNum)
for i := 0; i < metadataMetricNum; i++ {
for j := 0; j < metadataPerMetrics; j++ {
for i := range metadataMetricNum {
for j := range metadataPerMetrics {
metadata = append(metadata, prompb.MetricMetadata{
MetricFamilyName: fmt.Sprintf("metadata_name_%d", i),
Help: fmt.Sprintf("metadata_help_%d_%d", i, j),
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestCanSupportHoltWintersFunc(t *testing.T) {
numSamples := 240
serieses := make([]prompb.TimeSeries, numSeries)
lbls := make([]labels.Labels, numSeries)
for i := 0; i < numSeries; i++ {
for i := range numSeries {
series := e2e.GenerateSeriesWithSamples("test_series", start, scrapeInterval, i*numSamples, numSamples, prompb.Label{Name: "job", Value: "test"}, prompb.Label{Name: "series", Value: strconv.Itoa(i)})
serieses[i] = series

Expand Down
2 changes: 1 addition & 1 deletion integration/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ blocks_storage:
})
)

func buildConfigFromTemplate(tmpl string, data interface{}) string {
func buildConfigFromTemplate(tmpl string, data any) string {
t, err := template.New("config").Parse(tmpl)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion integration/e2e/scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestStartStop(t *testing.T) {

m1 := e2edb.NewMinio(9000, bktName)

for i := 0; i < 10; i++ {
for range 10 {
require.NoError(t, s.Start(m1))
require.NoError(t, s.Stop(m1))
}
Expand Down
8 changes: 4 additions & 4 deletions integration/grpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestConcurrentGrpcCalls(t *testing.T) {
wg := sync.WaitGroup{}
n := 10000
wg.Add(n)
for i := 0; i < n; i++ {
for i := range n {
go func(i int) {
defer wg.Done()
ctx := context.Background()
Expand All @@ -185,7 +185,7 @@ func TestConcurrentGrpcCalls(t *testing.T) {
wg := sync.WaitGroup{}
n := 10000
wg.Add(n)
for i := 0; i < n; i++ {
for i := range n {
go func(i int) {
defer wg.Done()
stream, err := client.PushStream(ctx)
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestConcurrentGrpcCalls(t *testing.T) {
wg := sync.WaitGroup{}
n := 10000
wg.Add(n)
for i := 0; i < n; i++ {
for i := range n {
go func(i int) {
defer wg.Done()
ctx := context.Background()
Expand Down Expand Up @@ -284,7 +284,7 @@ func createRequest(i int) *cortexpb.WriteRequest {

func createLabels(i int) []cortexpb.LabelAdapter {
labels := make([]cortexpb.LabelAdapter, 0, 100)
for j := 0; j < 100; j++ {
for j := range 100 {
labels = append(labels, cortexpb.LabelAdapter{
Name: fmt.Sprintf("test%d_%d", i, j),
Value: fmt.Sprintf("test%d_%d", i, j),
Expand Down
10 changes: 5 additions & 5 deletions integration/ingester_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func TestIngesterMetadata(t *testing.T) {
metadataMetricNum := 5
metadataPerMetrics := 2
metadata := make([]prompb.MetricMetadata, 0, metadataMetricNum)
for i := 0; i < metadataMetricNum; i++ {
for j := 0; j < metadataPerMetrics; j++ {
for i := range metadataMetricNum {
for j := range metadataPerMetrics {
metadata = append(metadata, prompb.MetricMetadata{
MetricFamilyName: fmt.Sprintf("metadata_name_%d", i),
Help: fmt.Sprintf("metadata_help_%d_%d", i, j),
Expand Down Expand Up @@ -127,8 +127,8 @@ func TestIngesterMetadataWithTenantFederation(t *testing.T) {
metadataMetricNum := 5
metadataPerMetrics := 2
metadata := make([]prompb.MetricMetadata, 0, metadataMetricNum)
for i := 0; i < metadataMetricNum; i++ {
for j := 0; j < metadataPerMetrics; j++ {
for i := range metadataMetricNum {
for j := range metadataPerMetrics {
metadata = append(metadata, prompb.MetricMetadata{
MetricFamilyName: fmt.Sprintf("metadata_name_%d", i),
Help: fmt.Sprintf("metadata_help_%d_%d", i, j),
Expand All @@ -139,7 +139,7 @@ func TestIngesterMetadataWithTenantFederation(t *testing.T) {

numUsers := 2
tenantIDs := make([]string, numUsers)
for u := 0; u < numUsers; u++ {
for u := range numUsers {
tenantIDs[u] = fmt.Sprintf("user-%d", u)
c, err := e2ecortex.NewClient(distributor.HTTPEndpoint(), querier.HTTPEndpoint(), "", "", tenantIDs[u])
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions integration/ingester_stream_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestIngesterStreamPushConnectionWithMatchingSigningKey(t *testing.T) {
require.NoError(t, err)

// Push a few series; all should succeed because the signing key matches.
for i := 0; i < 5; i++ {
for i := range 5 {
series, _ := generateSeries(fmt.Sprintf("test_signing_ok_%d", i), now)
res, err := client.Push(series)
require.NoError(t, err)
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestIngesterStreamPushConnectionWithMismatchedSigningKey(t *testing.T) {
client, err := e2ecortex.NewClient(distributor.HTTPEndpoint(), "", "", "", userID)
require.NoError(t, err)

for i := 0; i < 3; i++ {
for i := range 3 {
series, _ := generateSeries(fmt.Sprintf("test_signing_mismatch_%d", i), now)
res, err := client.Push(series)
if err == nil {
Expand Down Expand Up @@ -259,7 +259,7 @@ func TestIngesterStreamPushConnectionWithError(t *testing.T) {
client, err := e2ecortex.NewClient(distributor.HTTPEndpoint(), "", "", "", userID)
require.NoError(t, err)

for i := 0; i < 5; i++ {
for range 5 {
series, _ := generateSeries("test_limit_per_metric", now,
prompb.Label{
Name: "cardinality",
Expand Down
2 changes: 1 addition & 1 deletion integration/integration_memberlist_single_binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func TestSingleBinaryWithMemberlistScaling(t *testing.T) {
minCortex := 3
instances := make([]*e2ecortex.CortexService, 0)

for i := 0; i < maxCortex; i++ {
for i := range maxCortex {
name := fmt.Sprintf("cortex-%d", i+1)
join := ""
if i > 0 {
Expand Down
52 changes: 23 additions & 29 deletions integration/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestKVList(t *testing.T) {
// Create keys to list back
keysToCreate := []string{"key-a", "key-b", "key-c"}
for _, key := range keysToCreate {
err := client.CAS(context.Background(), key, func(in interface{}) (out interface{}, retry bool, err error) {
err := client.CAS(context.Background(), key, func(in any) (out any, retry bool, err error) {
return key, false, nil
})
require.NoError(t, err, "could not create key")
Expand All @@ -50,7 +50,7 @@ func TestKVList(t *testing.T) {
func TestKVDelete(t *testing.T) {
testKVs(t, func(t *testing.T, client kv.Client, reg *prometheus.Registry) {
// Create a key
err := client.CAS(context.Background(), "key-to-delete", func(in interface{}) (out interface{}, retry bool, err error) {
err := client.CAS(context.Background(), "key-to-delete", func(in any) (out any, retry bool, err error) {
return "key-to-delete", false, nil
})
require.NoError(t, err, "object could not be created")
Expand All @@ -77,20 +77,18 @@ func TestKVWatchAndDelete(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

err := client.CAS(context.Background(), "key-before-watch", func(in interface{}) (out interface{}, retry bool, err error) {
err := client.CAS(context.Background(), "key-before-watch", func(in any) (out any, retry bool, err error) {
return "value-before-watch", false, nil
})
require.NoError(t, err)

w := &watcher{}
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
w.watch(ctx, client)
}()
})

err = client.CAS(context.Background(), "key-to-delete", func(in interface{}) (out interface{}, retry bool, err error) {
err = client.CAS(context.Background(), "key-to-delete", func(in any) (out any, retry bool, err error) {
return "value-to-delete", false, nil
})
require.NoError(t, err, "object could not be created")
Expand Down Expand Up @@ -127,12 +125,10 @@ func setupEtcd(t *testing.T, scenario *e2e.Scenario, reg prometheus.Registerer,
etcdKv, err := kv.NewClient(kv.Config{
Store: "etcd",
Prefix: "keys/",
StoreConfig: kv.StoreConfig{
Etcd: etcd.Config{
Endpoints: []string{etcdSvc.HTTPEndpoint()},
DialTimeout: time.Minute,
MaxRetries: 5,
},
Etcd: etcd.Config{
Endpoints: []string{etcdSvc.HTTPEndpoint()},
DialTimeout: time.Minute,
MaxRetries: 5,
},
}, stringCodec{}, reg, logger)
require.NoError(t, err)
Expand All @@ -149,13 +145,11 @@ func setupConsul(t *testing.T, scenario *e2e.Scenario, reg prometheus.Registerer
consulKv, err := kv.NewClient(kv.Config{
Store: "consul",
Prefix: "keys/",
StoreConfig: kv.StoreConfig{
Consul: consul.Config{
Host: consulSvc.HTTPEndpoint(),
HTTPClientTimeout: time.Minute,
WatchKeyBurstSize: 5,
WatchKeyRateLimit: 1,
},
Consul: consul.Config{
Host: consulSvc.HTTPEndpoint(),
HTTPClientTimeout: time.Minute,
WatchKeyBurstSize: 5,
WatchKeyRateLimit: 1,
},
}, stringCodec{}, reg, logger)
require.NoError(t, err)
Expand Down Expand Up @@ -219,30 +213,30 @@ func verifyClientMetricsHistogram(t *testing.T, reg *prometheus.Registry, metric

type stringCodec struct{}

func (c stringCodec) Decode(bb []byte) (interface{}, error) {
func (c stringCodec) Decode(bb []byte) (any, error) {
if bb == nil {
return "<nil>", nil
}
return string(bb), nil
}
func (c stringCodec) Encode(v interface{}) ([]byte, error) { return []byte(v.(string)), nil }
func (c stringCodec) CodecID() string { return "stringCodec" }
func (c stringCodec) Encode(v any) ([]byte, error) { return []byte(v.(string)), nil }
func (c stringCodec) CodecID() string { return "stringCodec" }

func (stringCodec) EncodeMultiKey(msg interface{}) (map[string][]byte, error) {
func (stringCodec) EncodeMultiKey(msg any) (map[string][]byte, error) {
return nil, errors.New("String codec does not support EncodeMultiKey")
}

func (stringCodec) DecodeMultiKey(map[string][]byte) (interface{}, error) {
func (stringCodec) DecodeMultiKey(map[string][]byte) (any, error) {
return nil, errors.New("String codec does not support DecodeMultiKey")
}

type watcher struct {
values map[string][]interface{}
values map[string][]any
}

func (w *watcher) watch(ctx context.Context, client kv.Client) {
w.values = map[string][]interface{}{}
client.WatchPrefix(ctx, "", func(key string, value interface{}) bool {
w.values = map[string][]any{}
client.WatchPrefix(ctx, "", func(key string, value any) bool {
w.values[key] = append(w.values[key], value)
return true
})
Expand Down
Loading