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
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 2 additions & 2 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: 1.24
- name: Start Cortex
run: |
docker run -d --name cortex \
-p 9009:9009 \
-v ${{ github.workspace }}/integration/cortex-config.yaml:/etc/cortex/config.yaml \
cortexproject/cortex:v1.19.1 \
cortexproject/cortex:v1.20.1 \
-config.file=/etc/cortex/config.yaml \
-target=all,alertmanager
- name: Wait for Cortex
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validate_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: 1.24
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
Expand All @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: 1.24
- name: Unit Tests
run: make test
build:
Expand All @@ -37,6 +37,6 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23
go-version: 1.24
- name: Build All
run: make all
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Order should be `CHANGE`, `FEATURE`, `ENHANCEMENT`, and `BUGFIX`

## v0.20.0
* [CHANGE] Upgrade cortex to v1.20.1
* [CHANGE] Upgrade Go to 1.24

## v0.19.0
* [CHANGE] Upgrade cortex to v1.19.1
* [CHANGE] Upgrade Go to 1.23
Expand Down
34 changes: 34 additions & 0 deletions changelogs/v0.20.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# v0.20.0 Release

## Changes

* [CHANGE] Upgrade cortex to v1.20.1
* [CHANGE] Upgrade Go to 1.24

## Installation

## cortextool

```console
# download the binary (adapt os and arch as needed)
$ curl -fSL -o "cortextool" "https://github.com/cortexproject/cortex-tools/releases/download/v0.20.0/cortextool_0.20.0_linux_x86_64"

# make it executable
$ chmod a+x "cortextool"

# have fun :)
$ ./cortextool --help
```

## benchtool

```console
# download the binary (adapt os and arch as needed)
$ curl -fSL -o "benchtool" "https://github.com/cortexproject/cortex-tools/releases/download/v0.20.0/benchtool_0.20.0_linux_x86_64"

# make it executable
$ chmod a+x "benchtool"

# have fun :)
$ ./benchtool --help
```
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
287 changes: 170 additions & 117 deletions go.mod

Large diffs are not rendered by default.

812 changes: 489 additions & 323 deletions go.sum

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/prometheus/prometheus/promql/parser"
"github.com/prometheus/prometheus/storage/remote"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"

"github.com/cortexproject/cortex-tools/pkg/backfill"
"github.com/cortexproject/cortex-tools/pkg/bench"
Expand All @@ -50,10 +49,10 @@ func newClient(t *testing.T) *client.CortexClient {
return c
}

func ruleNode(record, expr string) rulefmt.RuleNode {
return rulefmt.RuleNode{
Record: yaml.Node{Kind: yaml.ScalarNode, Value: record},
Expr: yaml.Node{Kind: yaml.ScalarNode, Value: expr},
func rule(record, expr string) rulefmt.Rule {
return rulefmt.Rule{
Record: record,
Expr: expr,
}
}

Expand All @@ -64,8 +63,8 @@ func TestRulesLoadListDelete(t *testing.T) {
namespace := "test_namespace"
group := rwrulefmt.RuleGroup{}
group.Name = "test_rule_group"
group.Rules = []rulefmt.RuleNode{
ruleNode("summed_up", "sum(up)"),
group.Rules = []rulefmt.Rule{
rule("summed_up", "sum(up)"),
}

err := c.CreateRuleGroup(ctx, namespace, group)
Expand Down Expand Up @@ -106,9 +105,9 @@ func TestRulesMultipleGroups(t *testing.T) {

namespace := "multi_group_namespace"
groups := []rwrulefmt.RuleGroup{
{RuleGroup: rulefmt.RuleGroup{Name: "group_a", Rules: []rulefmt.RuleNode{ruleNode("metric_a", "sum(up)")}}},
{RuleGroup: rulefmt.RuleGroup{Name: "group_b", Rules: []rulefmt.RuleNode{ruleNode("metric_b", "count(up)")}}},
{RuleGroup: rulefmt.RuleGroup{Name: "group_c", Rules: []rulefmt.RuleNode{ruleNode("metric_c", "avg(up)")}}},
{RuleGroup: rulefmt.RuleGroup{Name: "group_a", Rules: []rulefmt.Rule{rule("metric_a", "sum(up)")}}},
{RuleGroup: rulefmt.RuleGroup{Name: "group_b", Rules: []rulefmt.Rule{rule("metric_b", "count(up)")}}},
{RuleGroup: rulefmt.RuleGroup{Name: "group_c", Rules: []rulefmt.Rule{rule("metric_c", "avg(up)")}}},
}

for _, g := range groups {
Expand Down Expand Up @@ -407,11 +406,11 @@ func (i *timeSeriesIterator) Labels() labels.Labels {
return i.labels
}
series := i.ts[i.posSeries]
i.labels = make(labels.Labels, len(series.Labels))
for idx := range series.Labels {
i.labels[idx].Name = series.Labels[idx].Name
i.labels[idx].Value = series.Labels[idx].Value
b := labels.NewBuilder(labels.EmptyLabels())
for _, l := range series.Labels {
b.Set(l.Name, l.Value)
}
i.labels = b.Labels()
i.labelsSeriesPos = i.posSeries
return i.labels
}
Expand Down
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
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()
}
4 changes: 2 additions & 2 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
8 changes: 4 additions & 4 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
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
8 changes: 4 additions & 4 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 Down
Loading
Loading