Skip to content

Commit

Permalink
chore: Improve logging of jumphash server selector (#14306)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Haudum <[email protected]>
  • Loading branch information
chaudum authored Oct 21, 2024
1 parent 11c4fa2 commit f568dda
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/bloomgateway/client_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type AddressProvider interface {
}

func NewJumpHashClientPool(clientFactory ClientFactory, dnsProvider AddressProvider, updateInterval time.Duration, logger log.Logger) (*JumpHashClientPool, error) {
selector := jumphash.DefaultSelector()
selector := jumphash.DefaultSelector("bloomgateway")
err := selector.SetServers(dnsProvider.Addresses()...)
if err != nil {
level.Warn(logger).Log("msg", "error updating servers", "err", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/chunk/cache/memcached_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (cfg *MemcachedClientConfig) RegisterFlagsWithPrefix(prefix, description st
func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Registerer, logger log.Logger, metricsNamespace string) MemcachedClient {
var selector serverSelector
if cfg.ConsistentHash {
selector = jumphash.DefaultSelector()
selector = jumphash.DefaultSelector("memcached")
} else {
selector = &memcache.ServerList{}
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/util/jumphash/memcached_client_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cespare/xxhash"
"github.com/facette/natsort"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/grafana/gomemcache/memcache"

Expand All @@ -23,6 +24,7 @@ import (
// with consistent DNS names where the naturally sorted order
// is predictable.
type Selector struct {
logger log.Logger
mu sync.RWMutex
addrs []net.Addr
resolveUnixAddr UnixResolver
Expand All @@ -33,15 +35,17 @@ type UnixResolver func(network, address string) (*net.UnixAddr, error)

type TCPResolver func(network, address string) (*net.TCPAddr, error)

func NewSelector(resolveUnixAddr UnixResolver, resolveTCPAddr TCPResolver) *Selector {
func NewSelector(name string, resolveUnixAddr UnixResolver, resolveTCPAddr TCPResolver) *Selector {
return &Selector{
logger: log.With(util_log.Logger, "name", name),
resolveUnixAddr: resolveUnixAddr,
resolveTCPAddr: resolveTCPAddr,
}
}

func DefaultSelector() *Selector {
func DefaultSelector(name string) *Selector {
return &Selector{
logger: log.With(util_log.Logger, "name", name),
resolveUnixAddr: net.ResolveUnixAddr,
resolveTCPAddr: net.ResolveTCPAddr,
}
Expand Down Expand Up @@ -102,7 +106,7 @@ func (s *Selector) SetServers(servers ...string) error {
}
}

level.Debug(util_log.Logger).Log("msg", "updating memcached servers", "servers", strings.Join(addresses(naddrs), ","), "count", len(naddrs))
level.Debug(util_log.Logger).Log("msg", "updating servers", "servers", strings.Join(addresses(naddrs), ","), "count", len(naddrs))

s.mu.Lock()
defer s.mu.Unlock()
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/jumphash/memcached_client_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var mockTCPResolver = func(_, address string) (*net.TCPAddr, error) {

func TestMemcachedJumpHashSelector_PickSever(t *testing.T) {
s := NewSelector(
"test",
mockUnixResolver,
mockTCPResolver,
)
Expand Down Expand Up @@ -84,6 +85,7 @@ func TestMemcachedJumpHashSelector_PickSever(t *testing.T) {

func TestMemcachedJumpHashSelector_PickSever_ErrNoServers(t *testing.T) {
s := NewSelector(
"test",
mockUnixResolver,
mockTCPResolver,
)
Expand Down

0 comments on commit f568dda

Please sign in to comment.