Skip to content

Commit

Permalink
Merge pull request #8021 from Juneezee/refactor/exp
Browse files Browse the repository at this point in the history
*: replace `golang.org/x/exp` with standard library
  • Loading branch information
fpetkovski authored Dec 24, 2024
2 parents c5025b7 + 90bfef6 commit ab13e10
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 118 deletions.
163 changes: 75 additions & 88 deletions go.mod

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package validation
import (
"encoding/json"
"fmt"
"slices"

"github.com/pkg/errors"
"golang.org/x/exp/slices"
)

var allowedIntegrationNames = []string{
Expand Down
5 changes: 2 additions & 3 deletions pkg/receive/expandedpostingscache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ package expandedpostingscache
import (
"bytes"
"fmt"
"math/rand/v2"
"strings"
"sync"
"testing"
"time"

"go.uber.org/atomic"
"golang.org/x/exp/rand"

"github.com/prometheus/client_golang/prometheus"
promtest "github.com/prometheus/client_golang/prometheus/testutil"
Expand Down Expand Up @@ -202,9 +202,8 @@ var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randSeq(n int) string {
b := make([]rune, n)
rand.Seed(uint64(time.Now().UnixNano()))
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
b[i] = letters[rand.IntN(len(letters))]
}
return string(b)
}
2 changes: 1 addition & 1 deletion pkg/receive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math"
"net"
"net/http"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -36,7 +37,6 @@ import (
"github.com/prometheus/prometheus/tsdb"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"golang.org/x/exp/slices"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down
2 changes: 1 addition & 1 deletion pkg/receive/hashring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"fmt"
"math"
"path/filepath"
"slices"
"sort"
"strconv"
"strings"
"sync"

"github.com/cespare/xxhash"
"golang.org/x/exp/slices"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down
2 changes: 1 addition & 1 deletion pkg/receive/multitsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path"
"path/filepath"
"slices"
"sort"
"sync"
"time"
Expand All @@ -18,7 +19,6 @@ import (
"github.com/oklog/ulid"
"github.com/pkg/errors"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"

Expand Down
3 changes: 1 addition & 2 deletions pkg/rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"context"
"path"
"path/filepath"
"slices"
"testing"
"time"

"golang.org/x/exp/slices"

"github.com/efficientgo/core/testutil"
"github.com/gogo/protobuf/proto"
"github.com/prometheus/prometheus/model/labels"
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"net/url"
"os"
"path/filepath"
"slices"
"testing"
"time"

"github.com/efficientgo/core/testutil"
"github.com/go-kit/log"
"github.com/pkg/errors"
"golang.org/x/exp/slices"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"math"
"os"
"path"
"slices"
"sort"
"strings"
"sync"
Expand All @@ -35,7 +36,6 @@ import (
"github.com/prometheus/prometheus/tsdb/encoding"
"github.com/prometheus/prometheus/tsdb/index"
"github.com/weaveworks/common/httpgrpc"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down
23 changes: 11 additions & 12 deletions pkg/store/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"sort"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -44,7 +44,6 @@ import (
"github.com/prometheus/prometheus/tsdb/encoding"
"github.com/prometheus/prometheus/tsdb/index"
"go.uber.org/atomic"
"golang.org/x/exp/slices"

"github.com/thanos-io/objstore"
"github.com/thanos-io/objstore/providers/filesystem"
Expand Down Expand Up @@ -996,16 +995,16 @@ func testSharding(t *testing.T, reuseDisk string, bkt objstore.Bucket, all ...ul
for id := range bucketStore.blocks {
ids = append(ids, id)
}
sort.Slice(ids, func(i, j int) bool {
return ids[i].Compare(ids[j]) < 0
slices.SortFunc(ids, func(i, j ulid.ULID) int {
return i.Compare(j)
})
testutil.Equals(t, sc.expectedIDs, ids)

// Make sure we don't download files we did not expect to.
// Regression test: https://github.com/thanos-io/thanos/issues/1664

// Sort records. We load blocks concurrently so operations might be not ordered.
sort.Strings(rec.getRangeTouched)
slices.Sort(rec.getRangeTouched)

// With binary header nothing should be downloaded fully.
testutil.Equals(t, []string(nil), rec.getTouched)
Expand Down Expand Up @@ -1052,7 +1051,7 @@ func expectedTouchedBlockOps(all, expected, cached []ulid.ULID) []string {
)
}
}
sort.Strings(ops)
slices.Sort(ops)
return ops
}

Expand Down Expand Up @@ -2581,8 +2580,8 @@ func TestLabelNamesAndValuesHints(t *testing.T) {
var namesHints hintspb.LabelNamesResponseHints
testutil.Ok(t, types.UnmarshalAny(namesResp.Hints, &namesHints))
// The order is not determinate, so we are sorting them.
sort.Slice(namesHints.QueriedBlocks, func(i, j int) bool {
return namesHints.QueriedBlocks[i].Id < namesHints.QueriedBlocks[j].Id
slices.SortFunc(namesHints.QueriedBlocks, func(i, j hintspb.Block) int {
return strings.Compare(i.Id, j.Id)
})
testutil.Equals(t, tc.expectedNamesHints, namesHints)

Expand All @@ -2593,8 +2592,8 @@ func TestLabelNamesAndValuesHints(t *testing.T) {
var valuesHints hintspb.LabelValuesResponseHints
testutil.Ok(t, types.UnmarshalAny(valuesResp.Hints, &valuesHints))
// The order is not determinate, so we are sorting them.
sort.Slice(valuesHints.QueriedBlocks, func(i, j int) bool {
return valuesHints.QueriedBlocks[i].Id < valuesHints.QueriedBlocks[j].Id
slices.SortFunc(valuesHints.QueriedBlocks, func(i, j hintspb.Block) int {
return strings.Compare(i.Id, j.Id)
})
testutil.Equals(t, tc.expectedValuesHints, valuesHints)
})
Expand Down Expand Up @@ -2730,7 +2729,7 @@ func labelNamesFromSeriesSet(series []*storepb.Series) []string {
labels = append(labels, k)
}

sort.Strings(labels)
slices.Sort(labels)
return labels
}

Expand Down Expand Up @@ -3345,7 +3344,7 @@ func TestMatchersToPostingGroup(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
actual, err := matchersToPostingGroups(ctx, func(name string) ([]string, error) {
sort.Strings(tc.labelValues[name])
slices.Sort(tc.labelValues[name])
return tc.labelValues[name], nil
}, tc.matchers)
testutil.Ok(t, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/cache/filter_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package storecache
import (
"context"
"fmt"
"slices"

"github.com/oklog/ulid"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"
"golang.org/x/exp/slices"
)

type FilteredIndexCache struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/store/flushable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
package store

import (
"slices"

"github.com/prometheus/prometheus/model/labels"
"golang.org/x/exp/slices"

"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/store/storepb"
Expand Down
2 changes: 1 addition & 1 deletion pkg/store/lazy_postings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package store
import (
"context"
"math"
"slices"
"strings"

"github.com/go-kit/log/level"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb/index"
"golang.org/x/exp/slices"

"github.com/thanos-io/thanos/pkg/block/indexheader"
)
Expand Down
7 changes: 3 additions & 4 deletions pkg/store/tsdb_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
package store

import (
"sort"
"maps"
"slices"
"strings"

"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel"
"golang.org/x/exp/maps"

"github.com/thanos-io/thanos/pkg/store/storepb"
)
Expand Down Expand Up @@ -88,8 +88,7 @@ func MatchersForLabelSets(labelSets []labels.Labels) []storepb.LabelMatcher {

matchers := make([]storepb.LabelMatcher, 0, len(labelNameValues))
for lblName, lblVals := range labelNameValues {
values := maps.Keys(lblVals)
sort.Strings(values)
values := slices.Sorted(maps.Keys(lblVals))
matcher := storepb.LabelMatcher{
Name: lblName,
Value: strings.Join(values, "|"),
Expand Down

0 comments on commit ab13e10

Please sign in to comment.