Skip to content

Commit

Permalink
refactor: replace experimental maps and slices with stdlib (grafa…
Browse files Browse the repository at this point in the history
…na#15051)

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee authored Nov 27, 2024
1 parent 215f994 commit 062d1e9
Show file tree
Hide file tree
Showing 26 changed files with 38 additions and 142 deletions.
3 changes: 1 addition & 2 deletions clients/pkg/promtail/client/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package client

import (
"fmt"
"slices"
"strconv"

"strings"
"time"

"github.com/gogo/protobuf/proto"
"github.com/golang/snappy"
"github.com/prometheus/common/model"
"golang.org/x/exp/slices"

"github.com/grafana/loki/v3/clients/pkg/promtail/api"

Expand Down
3 changes: 1 addition & 2 deletions clients/pkg/promtail/targets/cloudflare/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package cloudflare

import (
"fmt"

"golang.org/x/exp/slices"
"slices"
)

type FieldsType string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ require (
github.com/willf/bloom v2.0.3+incompatible
go.opentelemetry.io/collector/pdata v1.20.0
go4.org/netipx v0.0.0-20230125063823-8449b0a6169f
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
golang.org/x/oauth2 v0.24.0
golang.org/x/text v0.20.0
google.golang.org/protobuf v1.35.2
Expand Down Expand Up @@ -189,6 +188,7 @@ require (
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
google.golang.org/grpc/stats/opentelemetry v0.0.0-20240907200651-3ffb98b2c93a // indirect
)

Expand Down
2 changes: 1 addition & 1 deletion integration/loki_micro_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package integration
import (
"context"
"encoding/json"
"slices"
"strings"
"sync"
"testing"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/prometheus/prometheus/model/labels"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
"google.golang.org/protobuf/proto"

"github.com/grafana/loki/v3/integration/client"
Expand Down
2 changes: 1 addition & 1 deletion pkg/bloombuild/builder/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"io"
"math"
"slices"
"time"

"github.com/grafana/dskit/multierror"
"golang.org/x/exp/slices"

"github.com/grafana/loki/v3/pkg/chunkenc"
iter "github.com/grafana/loki/v3/pkg/iter/v2"
Expand Down
2 changes: 1 addition & 1 deletion pkg/bloomgateway/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"io"
"slices"
"sort"

"github.com/go-kit/log"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"

Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/recalculate_owned_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package ingester
import (
"context"
"fmt"
"slices"
"sync"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/ring"
"github.com/grafana/dskit/services"
"golang.org/x/exp/slices"

lokiring "github.com/grafana/loki/v3/pkg/util/ring"
)
Expand Down
15 changes: 5 additions & 10 deletions pkg/logql/accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"container/heap"
"context"
"fmt"
"maps"
"slices"
"sort"
"time"

"golang.org/x/exp/maps"

"github.com/grafana/loki/v3/pkg/logproto"
"github.com/grafana/loki/v3/pkg/logqlmodel"
"github.com/grafana/loki/v3/pkg/logqlmodel/metadata"
Expand Down Expand Up @@ -102,8 +102,7 @@ func (a *QuantileSketchAccumulator) Result() []logqlmodel.Result {
)
}

warnings := maps.Keys(a.warnings)
sort.Strings(warnings)
warnings := slices.Sorted(maps.Keys(a.warnings))

return []logqlmodel.Result{
{
Expand Down Expand Up @@ -178,8 +177,7 @@ func (a *CountMinSketchAccumulator) Result() []logqlmodel.Result {
)
}

warnings := maps.Keys(a.warnings)
sort.Strings(warnings)
warnings := slices.Sorted(maps.Keys(a.warnings))

return []logqlmodel.Result{
{
Expand Down Expand Up @@ -476,10 +474,7 @@ func (acc *AccumulatedStreams) Result() []logqlmodel.Result {
)
}

warnings := maps.Keys(acc.warnings)
sort.Strings(warnings)

res.Warnings = warnings
res.Warnings = slices.Sorted(maps.Keys(acc.warnings))

return []logqlmodel.Result{res}
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/logqlmodel/metadata/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ package metadata
import (
"context"
"errors"
"maps"
"slices"
"sort"
"sync"

"golang.org/x/exp/maps"

"github.com/grafana/loki/v3/pkg/querier/queryrange/queryrangebase/definitions"
)

Expand Down Expand Up @@ -87,8 +87,7 @@ func (c *Context) Warnings() []string {
c.mtx.Lock()
defer c.mtx.Unlock()

warnings := maps.Keys(c.warnings)
sort.Strings(warnings)
warnings := slices.Sorted(maps.Keys(c.warnings))

return warnings
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pattern/drain/drain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"bufio"
"fmt"
"os"
"slices"
"strings"
"testing"
"time"

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

"github.com/grafana/loki/v3/pkg/logql/log/pattern"
)
Expand Down
3 changes: 1 addition & 2 deletions pkg/push/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"encoding/json"
"fmt"
"io"
"slices"
"strings"
"time"
"unsafe"

"golang.org/x/exp/slices"
)

// Stream contains a unique labels set as a string and a set of entries for it.
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/ingester_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package querier
import (
"context"
"net/http"
"slices"
"strings"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/concurrency"
"github.com/grafana/dskit/user"
"golang.org/x/exp/slices"

"github.com/grafana/loki/v3/pkg/storage/stores/index/seriesvolume"

Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"net/http"
"slices"
"sort"
"strconv"
"time"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc/health/grpc_health_v1"

Expand Down
6 changes: 3 additions & 3 deletions pkg/querier/queryrange/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"encoding/json"
"fmt"
"io"
"maps"
"net/http"
"net/url"
"regexp"
"slices"
"sort"
"strings"
"time"
Expand All @@ -21,7 +23,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/timestamp"
"golang.org/x/exp/maps"

"github.com/grafana/loki/v3/pkg/loghttp"
"github.com/grafana/loki/v3/pkg/logproto"
Expand Down Expand Up @@ -2194,8 +2195,7 @@ func mergeLokiResponse(responses ...queryrangebase.Response) *LokiResponse {
}
}

warnings := maps.Keys(uniqueWarnings)
sort.Strings(warnings)
warnings := slices.Sorted(maps.Keys(uniqueWarnings))

if len(warnings) == 0 {
// When there are no warnings, keep it nil so it can be compared against
Expand Down
7 changes: 3 additions & 4 deletions pkg/querier/queryrange/queryrangebase/query_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"context"
"fmt"
"io"
"maps"
"math"
"net/http"
"slices"
"sort"
"strconv"
"time"

"golang.org/x/exp/maps"

"github.com/gogo/status"
"github.com/grafana/dskit/httpgrpc"
jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -173,8 +173,7 @@ func (p prometheusCodec) MergeResponse(responses ...Response) (Response, error)
}
}

warnings := maps.Keys(uniqueWarnings)
sort.Strings(warnings)
warnings := slices.Sorted(maps.Keys(uniqueWarnings))

if len(warnings) == 0 {
// When there are no warnings, keep it nil so it can be compared against
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/chunk/cache/resultscache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resultscache

import (
"context"
"slices"
"strconv"
"testing"
"time"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/grafana/dskit/user"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"

"github.com/grafana/loki/v3/pkg/logqlmodel/stats"
"github.com/grafana/loki/v3/pkg/storage/chunk/cache"
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/chunk/fetcher/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package fetcher
import (
"context"
"fmt"
"slices"
"strconv"
"testing"
"time"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/slices"

"github.com/grafana/loki/v3/pkg/chunkenc"
"github.com/grafana/loki/v3/pkg/compression"
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/stores/shipper/bloomshipper/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"path"
"slices"
"sort"
"time"

Expand All @@ -12,7 +13,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"golang.org/x/exp/slices"

"github.com/grafana/loki/v3/pkg/storage"
v1 "github.com/grafana/loki/v3/pkg/storage/bloom/v1"
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/stores/shipper/indexshipper/downloads/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package downloads
import (
"context"
"fmt"
"maps"
"os"
"path/filepath"
"runtime"
"slices"
"sync"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/concurrency"
"github.com/pkg/errors"
"golang.org/x/exp/maps"
"golang.org/x/sync/errgroup"

"github.com/grafana/loki/v3/pkg/storage/chunk/client/util"
Expand Down Expand Up @@ -272,7 +273,7 @@ func (t *table) Sync(ctx context.Context) error {
level.Debug(t.logger).Log("msg", fmt.Sprintf("syncing files for table %s", t.name))

t.indexSetsMtx.RLock()
users := maps.Keys(t.indexSets)
users := slices.Collect(maps.Keys(t.indexSets))
t.indexSetsMtx.RUnlock()

for _, userID := range users {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package downloads
import (
"context"
"fmt"
"maps"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"time"
Expand All @@ -14,7 +16,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"golang.org/x/exp/maps"

"github.com/grafana/loki/v3/pkg/compactor/deletion"
"github.com/grafana/loki/v3/pkg/storage/chunk/client/util"
Expand Down Expand Up @@ -219,7 +220,7 @@ func (tm *tableManager) getOrCreateTable(tableName string) (Table, error) {

func (tm *tableManager) syncTables(ctx context.Context) error {
tm.tablesMtx.RLock()
tables := maps.Keys(tm.tables)
tables := slices.Collect(maps.Keys(tm.tables))
tm.tablesMtx.RUnlock()

start := time.Now()
Expand Down
Loading

0 comments on commit 062d1e9

Please sign in to comment.