Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trivial "util" exported package #247

Merged
merged 2 commits into from
Jan 4, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cache/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/go-kit/log/level"
"github.com/golang/snappy"

"github.com/grafana/dskit/util/stringsutil"
"github.com/grafana/dskit/internal/slices"
)

const (
Expand All @@ -35,9 +35,10 @@ func (cfg *CompressionConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix st
}

func (cfg *CompressionConfig) Validate() error {
if cfg.Compression != "" && !stringsutil.SliceContains(supportedCompressions, cfg.Compression) {
if cfg.Compression != "" && !slices.Contains(supportedCompressions, cfg.Compression) {
return errUnsupportedCompression
}

return nil
}

Expand Down
11 changes: 11 additions & 0 deletions internal/slices/slices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package slices

func Contains[T comparable](haystack []T, needle T) bool {
charleskorn marked this conversation as resolved.
Show resolved Hide resolved
for _, e := range haystack {
if e == needle {
return true
}
}

return false
}
4 changes: 2 additions & 2 deletions ring/client/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"google.golang.org/grpc/health/grpc_health_v1"

"github.com/grafana/dskit/concurrency"
"github.com/grafana/dskit/internal/slices"
"github.com/grafana/dskit/services"
"github.com/grafana/dskit/util/stringsutil"
)

// PoolClient is the interface that should be implemented by a
Expand Down Expand Up @@ -171,7 +171,7 @@ func (p *Pool) removeStaleClients() {
}

for _, addr := range p.RegisteredAddresses() {
if stringsutil.SliceContains(serviceAddrs, addr) {
if slices.Contains(serviceAddrs, addr) {
continue
}
level.Info(p.logger).Log("msg", "removing stale client", "addr", addr)
Expand Down
14 changes: 7 additions & 7 deletions ring/ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"flag"
"fmt"

"math"
"math/rand"
"net/http"
Expand All @@ -19,13 +20,12 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/grafana/dskit/flagext"
dsmath "github.com/grafana/dskit/internal/math"
"github.com/grafana/dskit/internal/slices"
"github.com/grafana/dskit/kv"
shardUtil "github.com/grafana/dskit/ring/shard"
"github.com/grafana/dskit/services"

"github.com/grafana/dskit/flagext"
dsmath "github.com/grafana/dskit/internal/math"
"github.com/grafana/dskit/util/stringsutil"
)

const (
Expand Down Expand Up @@ -291,7 +291,7 @@ func (r *Ring) updateRingState(ringDesc *Desc) {
// Filter out all instances belonging to excluded zones.
if len(r.cfg.ExcludedZones) > 0 {
for instanceID, instance := range ringDesc.Ingesters {
if stringsutil.SliceContains(r.cfg.ExcludedZones, instance.Zone) {
if slices.Contains(r.cfg.ExcludedZones, instance.Zone) {
delete(ringDesc.Ingesters, instanceID)
}
}
Expand Down Expand Up @@ -364,13 +364,13 @@ func (r *Ring) Get(key uint32, op Operation, bufDescs []InstanceDesc, bufHosts,
}

// We want n *distinct* instances && distinct zones.
if stringsutil.SliceContains(distinctHosts, info.InstanceID) {
if slices.Contains(distinctHosts, info.InstanceID) {
continue
}

// Ignore if the instances don't have a zone set.
if r.cfg.ZoneAwarenessEnabled && info.Zone != "" {
if stringsutil.SliceContains(distinctZones, info.Zone) {
if slices.Contains(distinctZones, info.Zone) {
continue
}
}
Expand Down
6 changes: 3 additions & 3 deletions ring/ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"google.golang.org/grpc/status"

"github.com/grafana/dskit/flagext"
"github.com/grafana/dskit/internal/slices"
"github.com/grafana/dskit/kv"
"github.com/grafana/dskit/kv/consul"
"github.com/grafana/dskit/ring/shard"
"github.com/grafana/dskit/services"
"github.com/grafana/dskit/test"
"github.com/grafana/dskit/util/stringsutil"
)

const (
Expand Down Expand Up @@ -1280,7 +1280,7 @@ func TestRing_ShuffleShard_Shuffling(t *testing.T) {

numMatching := 0
for _, c := range currShard {
if stringsutil.SliceContains(otherShard, c) {
if slices.Contains(otherShard, c) {
numMatching++
}
}
Expand Down Expand Up @@ -2218,7 +2218,7 @@ func TestRingUpdates(t *testing.T) {

// Ensure there's no instance in an excluded zone.
if len(testData.excludedZones) > 0 {
assert.False(t, stringsutil.SliceContains(testData.excludedZones, ing.Zone))
assert.False(t, slices.Contains(testData.excludedZones, ing.Zone))
}
}

Expand Down
11 changes: 0 additions & 11 deletions util/stringsutil/stringsutil.go

This file was deleted.