Skip to content

Commit

Permalink
Replace exp/slices with slices from standard library (#10255)
Browse files Browse the repository at this point in the history
* Replace `exp/slices` with `slices` from standard library

The experimental functions in `golang.org/x/exp/slices` are now
available in the standard library in Go 1.21 [1].

[1]: https://go.dev/doc/go1.21#slices

Signed-off-by: Eng Zer Jun <[email protected]>

---------

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee authored Dec 16, 2024
1 parent cc7e34a commit a979e2b
Show file tree
Hide file tree
Showing 48 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ lint: check-makefiles
# Note that we don't automatically suggest replacing sort.Float64s() with slices.Sort() as the documentation for slices.Sort()
# at the time of writing warns that slices.Sort() may not correctly handle NaN values.
faillint -paths \
"sort.{Strings,Ints}=golang.org/x/exp/slices.Sort" \
"sort.{Strings,Ints}=slices.Sort" \
./pkg/... ./cmd/... ./tools/... ./integration/...

# Don't use generic ring.Read operation.
Expand Down
2 changes: 1 addition & 1 deletion cmd/metaconvert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"os/signal"
"path"
"slices"
"syscall"

gklog "github.com/go-kit/log"
Expand All @@ -22,7 +23,6 @@ import (
dslog "github.com/grafana/dskit/log"
"github.com/pkg/errors"
"github.com/thanos-io/objstore"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/storage/bucket"
mimir_tsdb "github.com/grafana/mimir/pkg/storage/tsdb"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ require (
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/trace v1.32.0
go.uber.org/multierr v1.11.0
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e
golang.org/x/term v0.27.0
google.golang.org/api v0.209.0
google.golang.org/protobuf v1.35.2
Expand Down Expand Up @@ -271,6 +270,7 @@ require (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/exp v0.0.0-20241215155358-4a5509556b9e // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sys v0.28.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/cardinality/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"fmt"
"net/http"
"net/url"
"slices"
"strconv"
"strings"

"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql/parser"
"golang.org/x/exp/slices"
)

type CountMethod string
Expand Down
2 changes: 1 addition & 1 deletion pkg/compactor/split_merge_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ package compactor

import (
"fmt"
"slices"
"strings"
"time"

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

"github.com/grafana/mimir/pkg/storage/tsdb"
"github.com/grafana/mimir/pkg/storage/tsdb/block"
Expand Down
2 changes: 1 addition & 1 deletion pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"math"
"math/rand"
"net/http"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -44,7 +45,6 @@ import (
"github.com/prometheus/prometheus/model/relabel"
"github.com/prometheus/prometheus/scrape"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"

"github.com/grafana/mimir/pkg/cardinality"
Expand Down
2 changes: 1 addition & 1 deletion pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io"
"math"
"math/rand"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -46,7 +47,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/twmb/franz-go/pkg/kfake"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
"golang.org/x/time/rate"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down
2 changes: 1 addition & 1 deletion pkg/distributor/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"slices"
"strings"
"testing"
"time"
Expand All @@ -31,7 +32,6 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"
"golang.org/x/exp/slices"
"google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/proto"
Expand Down
2 changes: 1 addition & 1 deletion pkg/distributor/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package distributor
import (
"context"
"io"
"slices"
"time"

"github.com/go-kit/log/level"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"golang.org/x/exp/slices"

ingester_client "github.com/grafana/mimir/pkg/ingester/client"
"github.com/grafana/mimir/pkg/mimirpb"
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/querymiddleware/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io"
"net/http"
"net/url"
"slices"
"sort"
"strconv"
"strings"
Expand All @@ -30,7 +31,6 @@ import (
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/promql/parser"
v1 "github.com/prometheus/prometheus/web/api/v1"
"golang.org/x/exp/slices"

apierror "github.com/grafana/mimir/pkg/api/error"
"github.com/grafana/mimir/pkg/cardinality"
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/querymiddleware/experimental_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package querymiddleware
import (
"context"
"fmt"
"slices"

"github.com/go-kit/log"
"github.com/grafana/dskit/tenant"
"github.com/prometheus/prometheus/promql/parser"
"golang.org/x/exp/slices"

apierror "github.com/grafana/mimir/pkg/api/error"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/querymiddleware/labels_query_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"net/url"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql/parser"
v1 "github.com/prometheus/prometheus/web/api/v1"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/util"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/querymiddleware/model_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/url"
"slices"
"strconv"
"strings"
"testing"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/prometheus/prometheus/promql/parser"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func TestEncodeAndDecodeCachedHTTPResponse(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend/querymiddleware/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"flag"
"fmt"
"net/http"
"slices"
"strings"
"time"

Expand All @@ -22,7 +23,6 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/promql/parser"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/storage/ingest"
"github.com/grafana/mimir/pkg/util"
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/activeseries/model/custom_trackers_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"fmt"
"math"
"reflect"
"slices"
"strings"

amlabels "github.com/prometheus/alertmanager/pkg/labels"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v3"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -49,7 +50,6 @@ import (
"github.com/prometheus/prometheus/util/zeropool"
"github.com/thanos-io/objstore"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"

"github.com/grafana/mimir/pkg/ingester/activeseries"
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/ingester_early_compaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math"
"os"
"path/filepath"
"slices"
"sync"
"testing"
"time"
Expand All @@ -25,7 +26,6 @@ import (
"github.com/prometheus/prometheus/tsdb/chunks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/ingester/client"
util_test "github.com/grafana/mimir/pkg/util/test"
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"path/filepath"
"reflect"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -55,7 +56,6 @@ import (
"github.com/thanos-io/objstore"
"github.com/thanos-io/objstore/providers/filesystem"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/label_names_and_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
"strconv"
"strings"
"testing"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/prometheus/prometheus/tsdb/index"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/ingester/client"
"github.com/grafana/mimir/pkg/mimirpb"
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/tenants_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"html/template"
"math"
"net/http"
"slices"
"time"

"github.com/gorilla/mux"
"github.com/prometheus/prometheus/tsdb"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/util"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/mimirpb/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ package mimirpb
import (
"fmt"
"io"
"slices"
"sort"
"strings"
"sync"
"unsafe"

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

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/mimirpb/timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"crypto/rand"
"fmt"
"reflect"
"slices"
"sort"
"testing"
"time"
"unsafe"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func TestLabelAdapter_Marshal(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mimirtool/analyze/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package analyze
import (
"encoding/json"
"fmt"
"slices"
"strings"

"github.com/grafana/regexp"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql/parser"
log "github.com/sirupsen/logrus"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/mimirtool/minisdk"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/mimirtool/analyze/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
package analyze

import (
"slices"

"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/promql/parser"
log "github.com/sirupsen/logrus"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/mimirtool/rules/rwrulefmt"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/mimirtool/commands/analyse_grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
"encoding/json"
"fmt"
"os"
"slices"
"sort"
"strings"
"time"

"github.com/alecthomas/kingpin/v2"
"github.com/grafana-tools/sdk"
"github.com/prometheus/common/model"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/mimirtool/analyze"
"github.com/grafana/mimir/pkg/mimirtool/minisdk"
Expand Down
2 changes: 1 addition & 1 deletion pkg/mimirtool/commands/analyse_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
package commands

import (
"slices"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/grafana/mimir/pkg/mimirtool/analyze"
"github.com/grafana/mimir/pkg/mimirtool/rules"
Expand Down
Loading

0 comments on commit a979e2b

Please sign in to comment.