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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
10 changes: 5 additions & 5 deletions .github/workflows/validate_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
go-version: 1.23
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: v1.54
version: v1.64
unit_tests:
name: Unit-Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
go-version: 1.23
- name: Unit Tests
run: make test
build:
Expand All @@ -35,6 +35,6 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
go-version: 1.23
- name: Build All
run: make all
6 changes: 4 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ run:
- require_docker

output:
format: line-number
formats:
- format: line-number

linters:
enable:
Expand All @@ -17,6 +18,7 @@ linters:

linters-settings:
errcheck:
exclude: .errcheck-exclude
exclude-functions:
- (github.com/go-kit/log.Logger).Log
goimports:
local-prefixes: "github.com/cortexproject/cortex-tools"
2 changes: 1 addition & 1 deletion cmd/blockscopy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/concurrency"
"github.com/oklog/ulid"
"github.com/oklog/ulid/v2"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand Down
8 changes: 4 additions & 4 deletions cmd/sim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func run(k int, sizer func(float64) int) {

fmt.Printf("%d, %d, %d, %d, %f, %f\n",
k,
int(min(nodeSeries)),
int(max(nodeSeries)),
int(minFloat(nodeSeries)),
int(maxFloat(nodeSeries)),
int(stat.Mean(nodeSeries, nil)),
stat.StdDev(nodeSeries, nil),
float64(maxAffectedTenants)/float64(numTenants))
Expand Down Expand Up @@ -168,7 +168,7 @@ func shuffleShard(entropy *rand.Rand, shardSize, numReplicas int) []int {
return ids
}

func min(fs []float64) float64 {
func minFloat(fs []float64) float64 {
result := math.MaxFloat64
for _, f := range fs {
if f < result {
Expand All @@ -178,7 +178,7 @@ func min(fs []float64) float64 {
return result
}

func max(fs []float64) float64 {
func maxFloat(fs []float64) float64 {
result := 0.0
for _, f := range fs {
if f > result {
Expand Down
313 changes: 186 additions & 127 deletions go.mod

Large diffs are not rendered by default.

1,505 changes: 924 additions & 581 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pkg/analyse/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func ParseMetricsInRuleGroup(mir *MetricsInRuler, group rwrulefmt.RuleGroup, ns
)

for _, rule := range group.Rules {
if rule.Record.Value != "" {
ruleMetrics[rule.Record.Value] = struct{}{}
if rule.Record != "" {
ruleMetrics[rule.Record] = struct{}{}
}

query := rule.Expr.Value
query := rule.Expr
expr, err := parser.ParseExpr(query)
if err != nil {
parseErrors = append(parseErrors, errors.Wrapf(err, "query=%v", query))
Expand Down
4 changes: 2 additions & 2 deletions pkg/backfill/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"fmt"
"io"
"log/slog"
"strconv"
"strings"
"text/tabwriter"
"time"

"github.com/alecthomas/units"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
Expand Down Expand Up @@ -87,7 +87,7 @@ func CreateBlocks(input IteratorCreator, mint, maxt int64, maxSamplesInAppender

for t := mint; t <= maxt; t = t + blockDuration {
err := func() error {
w, err := tsdb.NewBlockWriter(log.NewNopLogger(), outputDir, blockDuration)
w, err := tsdb.NewBlockWriter(slog.Default(), outputDir, blockDuration)
if err != nil {
return errors.Wrap(err, "block writer")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/bench/query_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (q *queryRunner) resolveAddrs() error {
defer cancel()

// If some of the dns resolution fails, log the error.
if err := q.dnsProvider.Resolve(ctx, []string{q.cfg.Endpoint}); err != nil {
if err := q.dnsProvider.Resolve(ctx, []string{q.cfg.Endpoint}, true); err != nil {
level.Error(q.logger).Log("msg", "failed to resolve addresses", "err", err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/bench/write_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (w *WriteBenchmarkRunner) resolveAddrs() error {
defer cancel()

// If some of the dns resolution fails, log the error.
if err := w.dnsProvider.Resolve(ctx, []string{w.cfg.Endpoint}); err != nil {
if err := w.dnsProvider.Resolve(ctx, []string{w.cfg.Endpoint}, true); err != nil {
level.Error(w.logger).Log("msg", "failed to resolve addresses", "err", err)
}

Expand Down
20 changes: 8 additions & 12 deletions pkg/commands/block_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package commands

import (
"context"
"log/slog"
"os"
"sort"
"time"

"github.com/go-kit/log"
Expand Down Expand Up @@ -96,7 +96,7 @@ func (f *BlockGenCommand) run(_ *kingpin.ParseContext) error {

currentBlockID = blockID(currentTs, blockSize)
level.Info(logger).Log("msg", "starting new block", "block_id", currentBlockID, "blocks_left", lastBlockID-currentBlockID+1)
w, err = tsdb.NewBlockWriter(log.NewNopLogger(), f.Cfg.BlockDir, blockSize)
w, err = tsdb.NewBlockWriter(slog.Default(), f.Cfg.BlockDir, blockSize)
if err != nil {
return err
}
Expand All @@ -108,13 +108,10 @@ func (f *BlockGenCommand) run(_ *kingpin.ParseContext) error {
for _, s := range timeSeries {
var ref storage.SeriesRef

labels := prompbLabelsToLabelsLabels(s.Labels)
sort.Slice(labels, func(i, j int) bool {
return labels[i].Name < labels[j].Name
})
lbls := prompbLabelsToLabelsLabels(s.Labels)

for _, sample := range s.Samples {
ref, err = app.Append(ref, labels, sample.Timestamp, sample.Value)
ref, err = app.Append(ref, lbls, sample.Timestamp, sample.Value)
if err != nil {
return err
}
Expand All @@ -139,10 +136,9 @@ func blockID(ts, blockSize int64) int64 {
}

func prompbLabelsToLabelsLabels(in []prompb.Label) labels.Labels {
out := make(labels.Labels, len(in))
for idx := range in {
out[idx].Name = in[idx].Name
out[idx].Value = in[idx].Value
b := labels.NewBuilder(labels.EmptyLabels())
for _, l := range in {
b.Set(l.Name, l.Value)
}
return out
return b.Labels()
}
6 changes: 3 additions & 3 deletions pkg/commands/bucket_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (c *retryingBucketClient) withRetries(f func() error) error {
}
}

func (c *retryingBucketClient) Upload(ctx context.Context, name string, r io.Reader) error {
return c.withRetries(func() error { return c.Bucket.Upload(ctx, name, r) })
func (c *retryingBucketClient) Upload(ctx context.Context, name string, r io.Reader, opts ...objstore.ObjectUploadOption) error {
return c.withRetries(func() error { return c.Bucket.Upload(ctx, name, r, opts...) })
}

func (c *retryingBucketClient) Exists(ctx context.Context, name string) (bool, error) {
Expand Down Expand Up @@ -115,7 +115,7 @@ func (b *BucketValidationCommand) validate(_ *kingpin.ParseContext) error {
b.logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
ctx := context.Background()

bucketClient, err := bucket.NewClient(ctx, b.cfg, "testClient", b.logger, prometheus.DefaultRegisterer)
bucketClient, err := bucket.NewClient(ctx, b.cfg, nil, "testClient", b.logger, prometheus.DefaultRegisterer)
if err != nil {
return errors.Wrap(err, "failed to create the bucket client")
}
Expand Down
17 changes: 11 additions & 6 deletions pkg/commands/remote_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ func (i *timeSeriesIterator) Labels() (l labels.Labels) {
}

series := i.ts[i.posSeries]
i.labels = make(labels.Labels, len(series.Labels))
for posLabel := range series.Labels {
i.labels[posLabel].Name = series.Labels[posLabel].Name
i.labels[posLabel].Value = series.Labels[posLabel].Value
b := labels.NewBuilder(labels.EmptyLabels())
for _, lbl := range series.Labels {
b.Set(lbl.Name, lbl.Value)
}
i.labels = b.Labels()
i.labelsSeriesPos = i.posSeries
return i.labels
}
Expand Down Expand Up @@ -252,12 +252,17 @@ func (c *RemoteReadCommand) prepare() (query func(context.Context) ([]*prompb.Ti

return func(ctx context.Context) ([]*prompb.TimeSeries, error) {
log.Infof("Querying time from=%s to=%s with selector=%s", from.Format(time.RFC3339), to.Format(time.RFC3339), c.selector)
resp, err := readClient.Read(ctx, pbQuery)
ss, err := readClient.Read(ctx, pbQuery, false)
if err != nil {
return nil, err
}

return resp.Timeseries, nil
result, _, err := remote.ToQueryResult(ss, 0)
if err != nil {
return nil, err
}

return result.Timeseries, nil

}, from, to, nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/commands/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func (r *RuleCommand) prepare(_ *kingpin.ParseContext) error {
}

// Do not apply the aggregation label to excluded rule groups.
applyTo := func(group rwrulefmt.RuleGroup, _ rulefmt.RuleNode) bool {
applyTo := func(group rwrulefmt.RuleGroup, _ rulefmt.Rule) bool {
_, excluded := r.aggregationLabelExcludedRuleGroupsList[group.Name]
return !excluded
}
Expand Down Expand Up @@ -774,11 +774,11 @@ func checkDuplicates(groups []rwrulefmt.RuleGroup) []compareRuleType {
return duplicates
}

func ruleMetric(rule rulefmt.RuleNode) string {
if rule.Alert.Value != "" {
return rule.Alert.Value
func ruleMetric(rule rulefmt.Rule) string {
if rule.Alert != "" {
return rule.Alert
}
return rule.Record.Value
return rule.Record
}

// End taken from https://github.com/prometheus/prometheus/blob/8c8de46003d1800c9d40121b4a5e5de8582ef6e1/cmd/promtool/main.go#L403
Expand Down
21 changes: 10 additions & 11 deletions pkg/commands/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/prometheus/prometheus/model/rulefmt"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"

"github.com/cortexproject/cortex-tools/pkg/rules/rwrulefmt"
)
Expand All @@ -21,14 +20,14 @@ func TestCheckDuplicates(t *testing.T) {
in: []rwrulefmt.RuleGroup{{
RuleGroup: rulefmt.RuleGroup{
Name: "rulegroup",
Rules: []rulefmt.RuleNode{
Rules: []rulefmt.Rule{
{
Record: yaml.Node{Value: "up"},
Expr: yaml.Node{Value: "up==1"},
Record: "up",
Expr: "up==1",
},
{
Record: yaml.Node{Value: "down"},
Expr: yaml.Node{Value: "up==0"},
Record: "down",
Expr: "up==0",
},
},
},
Expand All @@ -41,14 +40,14 @@ func TestCheckDuplicates(t *testing.T) {
in: []rwrulefmt.RuleGroup{{
RuleGroup: rulefmt.RuleGroup{
Name: "rulegroup",
Rules: []rulefmt.RuleNode{
Rules: []rulefmt.Rule{
{
Record: yaml.Node{Value: "up"},
Expr: yaml.Node{Value: "up==1"},
Record: "up",
Expr: "up==1",
},
{
Record: yaml.Node{Value: "up"},
Expr: yaml.Node{Value: "up==0"},
Record: "up",
Expr: "up==0",
},
},
},
Expand Down
14 changes: 7 additions & 7 deletions pkg/rules/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ func CompareGroups(groupOne, groupTwo rwrulefmt.RuleGroup) error {
return nil
}

func rulesEqual(a, b *rulefmt.RuleNode) bool {
if a.Alert.Value != b.Alert.Value ||
a.Record.Value != b.Record.Value ||
a.Expr.Value != b.Expr.Value ||
func rulesEqual(a, b *rulefmt.Rule) bool {
if a.Alert != b.Alert ||
a.Record != b.Record ||
a.Expr != b.Expr ||
a.For != b.For {
return false
}
Expand All @@ -131,9 +131,9 @@ func rulesEqual(a, b *rulefmt.RuleNode) bool {

// CompareNamespaces returns the differences between the two provided
// namespaces
func CompareNamespaces(original, new RuleNamespace) NamespaceChange {
func CompareNamespaces(original, updated RuleNamespace) NamespaceChange {
result := NamespaceChange{
Namespace: new.Namespace,
Namespace: updated.Namespace,
State: Unchanged,
GroupsUpdated: []UpdatedRuleGroup{},
GroupsCreated: []rwrulefmt.RuleGroup{},
Expand All @@ -145,7 +145,7 @@ func CompareNamespaces(original, new RuleNamespace) NamespaceChange {
origMap[g.Name] = g
}

for _, newGroup := range new.Groups {
for _, newGroup := range updated.Groups {
origGroup, found := origMap[newGroup.Name]
if !found {
result.State = Updated
Expand Down
Loading
Loading