Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .github/workflows/test-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
run: make BUILD_IN_CONTAINER=false check-doc
- name: Check White Noise.
run: make BUILD_IN_CONTAINER=false check-white-noise
- name: Check Modernize
run: make BUILD_IN_CONTAINER=false check-modernize

test:
runs-on: ubuntu-24.04
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [FEATURE] Querier: Support for configuring query optimizers and enabling XFunctions in the Thanos engine. #6873
* [FEATURE] Query Frontend: Add support /api/v1/format_query API for formatting queries. #6893
* [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
* [ENHANCEMENT] Modernizes the entire codebase by using go modernize tool. #7005
* [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
* [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
* [ENHANCEMENT] Ruler: Emit an error message when the rule synchronization fails. #6902
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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 web-build web-pre web-deploy doc: build-image/$(UPTODATE)
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)
@mkdir -p $(shell pwd)/.pkg
@mkdir -p $(shell pwd)/.cache
@echo
Expand Down Expand Up @@ -308,6 +308,12 @@ 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)

modernize:
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/[email protected] -fix ./...

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
2 changes: 0 additions & 2 deletions cmd/cortex/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func TestExpandEnv(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.in, func(t *testing.T) {
_ = os.Setenv("y", "y")
output := expandEnv([]byte(test.in))
Expand Down Expand Up @@ -263,7 +262,6 @@ func TestParseConfigFileParameter(t *testing.T) {
{"--config.expand-env --opt1 --config.file=foo", "foo", true},
}
for _, test := range tests {
test := test
t.Run(test.args, func(t *testing.T) {
args := strings.Split(test.args, " ")
configFile, expandENV := parseConfigFileParameter(args)
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanosconvert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {

}

func fatal(msg string, args ...interface{}) {
func fatal(msg string, args ...any) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(1)
}
2 changes: 1 addition & 1 deletion integration/e2e/composite_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *CompositeHTTPService) SumMetrics(metricNames []string, opts ...MetricsO
return nil, fmt.Errorf("unexpected mismatching sum metrics results (got %d, expected %d)", len(partials), len(sums))
}

for i := 0; i < len(sums); i++ {
for i := range sums {
sums[i] += partials[i]
}
}
Expand Down
2 changes: 1 addition & 1 deletion integration/e2e/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewLogger(w io.Writer) *Logger {
}
}

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

Expand Down
8 changes: 2 additions & 6 deletions integration/e2e/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"math"
"slices"

io_prometheus_client "github.com/prometheus/client_model/go"
)
Expand Down Expand Up @@ -143,12 +144,7 @@ func EqualsAmong(values ...float64) func(sums ...float64) bool {
if len(sums) != 1 {
panic("equals among: expected one value")
}
for _, value := range values {
if sums[0] == value {
return true
}
}
return false
return slices.Contains(values, sums[0])
}
}

Expand Down
2 changes: 1 addition & 1 deletion integration/e2e/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (s *Scenario) shutdown() {
"--filter",
fmt.Sprintf("network=%s", s.networkName),
); err == nil {
for _, containerID := range strings.Split(string(out), "\n") {
for containerID := range strings.SplitSeq(string(out), "\n") {
containerID = strings.TrimSpace(containerID)
if containerID == "" {
continue
Expand Down
4 changes: 2 additions & 2 deletions integration/e2e/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ type LinePrefixLogger struct {
}

func (w *LinePrefixLogger) Write(p []byte) (n int, err error) {
for _, line := range strings.Split(string(p), "\n") {
for line := range strings.SplitSeq(string(p), "\n") {
// Skip empty lines
line = strings.TrimSpace(line)
if line == "" {
Expand Down Expand Up @@ -698,7 +698,7 @@ func (s *HTTPService) WaitRemovedMetric(metricName string, opts ...MetricsOption
func parseDockerIPv4Port(out string) (int, error) {
// The "docker port" output may be multiple lines if both IPv4 and IPv6 are supported,
// so we need to parse each line.
for _, line := range strings.Split(out, "\n") {
for line := range strings.SplitSeq(out, "\n") {
matches := dockerIPv4PortPattern.FindStringSubmatch(strings.TrimSpace(line))
if len(matches) != 2 {
continue
Expand Down
17 changes: 8 additions & 9 deletions integration/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"maps"
"math"
"math/rand"
"net/http"
Expand Down Expand Up @@ -63,9 +64,7 @@ func MergeFlagsWithoutRemovingEmpty(inputs ...map[string]string) map[string]stri
output := map[string]string{}

for _, input := range inputs {
for name, value := range input {
output[name] = value
}
maps.Copy(output, input)
}

return output
Expand Down Expand Up @@ -211,7 +210,7 @@ func GenerateSeriesWithSamples(

startTMillis := tsMillis
samples := make([]prompb.Sample, numSamples)
for i := 0; i < numSamples; i++ {
for i := range numSamples {
scrapeJitter := rand.Int63n(10) + 1 // add a jitter to simulate real-world scenarios, refer to: https://github.com/prometheus/prometheus/issues/13213
samples[i] = prompb.Sample{
Timestamp: startTMillis + scrapeJitter,
Expand Down Expand Up @@ -288,11 +287,11 @@ func CreateNHBlock(
}()

app := h.Appender(ctx)
for i := 0; i < len(series); i++ {
for i := range series {
num := random.Intn(i + 1)
var ref storage.SeriesRef
start := RandRange(rnd, mint, maxt)
for j := 0; j < numNHSamples; j++ {
for j := range numNHSamples {
if num%2 == 0 {
// append float histogram
ref, err = app.AppendHistogram(ref, series[i], start, nil, tsdbutil.GenerateTestFloatHistogram(int64(i+j)))
Expand Down Expand Up @@ -372,11 +371,11 @@ func CreateBlock(
}()

app := h.Appender(ctx)
for i := 0; i < len(series); i++ {
for i := range series {

var ref storage.SeriesRef
start := RandRange(rnd, mint, maxt)
for j := 0; j < numSamples; j++ {
for j := range numSamples {
ref, err = app.Append(ref, series[i], start, float64(i+j))
if err != nil {
if rerr := app.Rollback(); rerr != nil {
Expand Down Expand Up @@ -519,7 +518,7 @@ func GenerateV2SeriesWithSamples(

startTMillis := tsMillis
samples := make([]writev2.Sample, numSamples)
for i := 0; i < numSamples; i++ {
for i := range numSamples {
scrapeJitter := rand.Int63n(10) + 1 // add a jitter to simulate real-world scenarios, refer to: https://github.com/prometheus/prometheus/issues/13213
samples[i] = writev2.Sample{
Timestamp: startTMillis + scrapeJitter,
Expand Down
4 changes: 2 additions & 2 deletions pkg/alertmanager/alertmanager_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ type StatusHandler struct {

// ServeHTTP serves the status of the alertmanager.
func (s StatusHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
var clusterInfo map[string]interface{}
var clusterInfo map[string]any
if s.am.peer != nil {
clusterInfo = s.am.peer.Info()
}
err := statusTemplate.Execute(w, struct {
ClusterInfo map[string]interface{}
ClusterInfo map[string]any
}{
ClusterInfo: clusterInfo,
})
Expand Down
4 changes: 1 addition & 3 deletions pkg/alertmanager/alertmanager_http_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package alertmanager

import (
"context"
"io"
"net/http/httptest"
"testing"
Expand All @@ -14,8 +13,7 @@ import (
)

func TestMultitenantAlertmanager_GetStatusHandler(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
var peer *cluster.Peer
{
logger := promslog.NewNopLogger()
Expand Down
1 change: 0 additions & 1 deletion pkg/alertmanager/alertmanager_ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestIsHealthyForAlertmanagerOperations(t *testing.T) {
}

for testName, testData := range tests {
testData := testData

t.Run(testName, func(t *testing.T) {
actual := testData.instance.IsHealthy(RingOp, testData.timeout, time.Now())
Expand Down
6 changes: 3 additions & 3 deletions pkg/alertmanager/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestSilencesLimits(t *testing.T) {
}

// create silences up to maxSilencesCount
for i := 0; i < maxSilencesCount; i++ {
for range maxSilencesCount {
err := am.silences.Set(createSilences())
require.NoError(t, err)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ route:

now := time.Now()

for i := 0; i < alertGroups; i++ {
for i := range alertGroups {
alertName := model.LabelValue(fmt.Sprintf("Alert-%d", i))

inputAlerts := []*types.Alert{
Expand Down Expand Up @@ -174,7 +174,7 @@ route:
}

// Give it some time, as alerts are sent to dispatcher asynchronously.
test.Poll(t, 3*time.Second, nil, func() interface{} {
test.Poll(t, 3*time.Second, nil, func() any {
return testutil.GatherAndCompare(reg, strings.NewReader(fmt.Sprintf(`
# HELP alertmanager_dispatcher_aggregation_group_limit_reached_total Number of times when dispatcher failed to create new aggregation group due to limit.
# TYPE alertmanager_dispatcher_aggregation_group_limit_reached_total counter
Expand Down
2 changes: 1 addition & 1 deletion pkg/alertmanager/alertstore/bucketclient/bucket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *BucketAlertStore) GetAlertConfigs(ctx context.Context, userIDs []string
cfgs = make(map[string]alertspb.AlertConfigDesc, len(userIDs))
)

err := concurrency.ForEach(ctx, concurrency.CreateJobsFromStrings(userIDs), fetchConcurrency, func(ctx context.Context, job interface{}) error {
err := concurrency.ForEach(ctx, concurrency.CreateJobsFromStrings(userIDs), fetchConcurrency, func(ctx context.Context, job any) error {
userID := job.(string)

cfg, uBucket, err := s.getAlertConfig(ctx, userID)
Expand Down
8 changes: 2 additions & 6 deletions pkg/alertmanager/alertstore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package alertstore

import (
"flag"
"slices"

"github.com/cortexproject/cortex/pkg/alertmanager/alertstore/configdb"
"github.com/cortexproject/cortex/pkg/alertmanager/alertstore/local"
Expand All @@ -28,10 +29,5 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {

// IsFullStateSupported returns if the given configuration supports access to FullState objects.
func (cfg *Config) IsFullStateSupported() bool {
for _, backend := range bucket.SupportedBackends {
if cfg.Backend == backend {
return true
}
}
return false
return slices.Contains(bucket.SupportedBackends, cfg.Backend)
}
14 changes: 7 additions & 7 deletions pkg/alertmanager/alertstore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
)

func TestAlertStore_ListAllUsers(t *testing.T) {
runForEachAlertStore(t, func(t *testing.T, store AlertStore, m *mockBucket, client interface{}) {
runForEachAlertStore(t, func(t *testing.T, store AlertStore, m *mockBucket, client any) {
ctx := context.Background()
user1Cfg := alertspb.AlertConfigDesc{User: "user-1", RawConfig: "content-1"}
user2Cfg := alertspb.AlertConfigDesc{User: "user-2", RawConfig: "content-2"}
Expand All @@ -46,7 +46,7 @@ func TestAlertStore_ListAllUsers(t *testing.T) {
}

func TestAlertStore_SetAndGetAlertConfig(t *testing.T) {
runForEachAlertStore(t, func(t *testing.T, store AlertStore, m *mockBucket, client interface{}) {
runForEachAlertStore(t, func(t *testing.T, store AlertStore, m *mockBucket, client any) {
ctx := context.Background()
user1Cfg := alertspb.AlertConfigDesc{User: "user-1", RawConfig: "content-1"}
user2Cfg := alertspb.AlertConfigDesc{User: "user-2", RawConfig: "content-2"}
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestAlertStore_SetAndGetAlertConfig(t *testing.T) {
}

func TestStore_GetAlertConfigs(t *testing.T) {
runForEachAlertStore(t, func(t *testing.T, store AlertStore, m *mockBucket, client interface{}) {
runForEachAlertStore(t, func(t *testing.T, store AlertStore, m *mockBucket, client any) {
ctx := context.Background()
user1Cfg := alertspb.AlertConfigDesc{User: "user-1", RawConfig: "content-1"}
user2Cfg := alertspb.AlertConfigDesc{User: "user-2", RawConfig: "content-2"}
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestStore_GetAlertConfigs(t *testing.T) {
}

func TestAlertStore_DeleteAlertConfig(t *testing.T) {
runForEachAlertStore(t, func(t *testing.T, store AlertStore, m *mockBucket, client interface{}) {
runForEachAlertStore(t, func(t *testing.T, store AlertStore, m *mockBucket, client any) {
ctx := context.Background()
user1Cfg := alertspb.AlertConfigDesc{User: "user-1", RawConfig: "content-1"}
user2Cfg := alertspb.AlertConfigDesc{User: "user-2", RawConfig: "content-2"}
Expand Down Expand Up @@ -169,14 +169,14 @@ func TestAlertStore_DeleteAlertConfig(t *testing.T) {
})
}

func runForEachAlertStore(t *testing.T, testFn func(t *testing.T, store AlertStore, b *mockBucket, client interface{})) {
func runForEachAlertStore(t *testing.T, testFn func(t *testing.T, store AlertStore, b *mockBucket, client any)) {
bucketClient := objstore.NewInMemBucket()
mBucketClient := &mockBucket{Bucket: bucketClient}
bucketStore := bucketclient.NewBucketAlertStore(mBucketClient, nil, log.NewNopLogger())

stores := map[string]struct {
store AlertStore
client interface{}
client any
}{
"bucket": {store: bucketStore, client: mBucketClient},
}
Expand All @@ -188,7 +188,7 @@ func runForEachAlertStore(t *testing.T, testFn func(t *testing.T, store AlertSto
}
}

func objectExists(bucketClient interface{}, key string) (bool, error) {
func objectExists(bucketClient any, key string) (bool, error) {
if typed, ok := bucketClient.(objstore.Bucket); ok {
return typed.Exists(context.Background(), key)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/alertmanager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (am *MultitenantAlertmanager) ListAllConfigs(w http.ResponseWriter, r *http
}

done := make(chan struct{})
iter := make(chan interface{})
iter := make(chan any)

go func() {
util.StreamWriteYAMLResponse(w, iter, logger)
Expand Down Expand Up @@ -321,7 +321,7 @@ func (am *MultitenantAlertmanager) ListAllConfigs(w http.ResponseWriter, r *http
// validateAlertmanagerConfig recursively scans the input config looking for data types for which
// we have a specific validation and, whenever encountered, it runs their validation. Returns the
// first error or nil if validation succeeds.
func validateAlertmanagerConfig(cfg interface{}) error {
func validateAlertmanagerConfig(cfg any) error {
v := reflect.ValueOf(cfg)
t := v.Type()

Expand Down
2 changes: 1 addition & 1 deletion pkg/alertmanager/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ receivers:

func TestValidateAlertmanagerConfig(t *testing.T) {
tests := map[string]struct {
input interface{}
input any
expected error
}{
"*HTTPClientConfig": {
Expand Down
Loading
Loading