From 7176ba7b84c8938ba2283391706bfb6e799f24b5 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Mon, 30 Sep 2024 09:28:33 +0200 Subject: [PATCH 1/3] chore: Improve logging of jumphash server selector This commit adds the name of the server to the jumphash server selector logging by adding the name of the server to make the log lines distinguishable. Signed-off-by: Christian Haudum --- pkg/bloomgateway/client_pool.go | 2 +- pkg/storage/chunk/cache/memcached_client.go | 2 +- pkg/util/jumphash/memcached_client_selector.go | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/bloomgateway/client_pool.go b/pkg/bloomgateway/client_pool.go index 4b45292bef889..b784511e201bf 100644 --- a/pkg/bloomgateway/client_pool.go +++ b/pkg/bloomgateway/client_pool.go @@ -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) diff --git a/pkg/storage/chunk/cache/memcached_client.go b/pkg/storage/chunk/cache/memcached_client.go index 995e896fbcfee..ffdc817b68b42 100644 --- a/pkg/storage/chunk/cache/memcached_client.go +++ b/pkg/storage/chunk/cache/memcached_client.go @@ -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{} } diff --git a/pkg/util/jumphash/memcached_client_selector.go b/pkg/util/jumphash/memcached_client_selector.go index ccec90fa0dda2..8011730162c71 100644 --- a/pkg/util/jumphash/memcached_client_selector.go +++ b/pkg/util/jumphash/memcached_client_selector.go @@ -23,6 +23,7 @@ import ( // with consistent DNS names where the naturally sorted order // is predictable. type Selector struct { + name string mu sync.RWMutex addrs []net.Addr resolveUnixAddr UnixResolver @@ -33,15 +34,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{ + name: name, resolveUnixAddr: resolveUnixAddr, resolveTCPAddr: resolveTCPAddr, } } -func DefaultSelector() *Selector { +func DefaultSelector(name string) *Selector { return &Selector{ + name: name, resolveUnixAddr: net.ResolveUnixAddr, resolveTCPAddr: net.ResolveTCPAddr, } @@ -102,7 +105,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", "name", s.name, "servers", strings.Join(addresses(naddrs), ","), "count", len(naddrs)) s.mu.Lock() defer s.mu.Unlock() From eeb547ddaf48e7fd5d08bb991b453efa1a99f021 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Mon, 30 Sep 2024 09:44:56 +0200 Subject: [PATCH 2/3] fixup! chore: Improve logging of jumphash server selector Signed-off-by: Christian Haudum --- pkg/util/jumphash/memcached_client_selector.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/util/jumphash/memcached_client_selector.go b/pkg/util/jumphash/memcached_client_selector.go index 8011730162c71..7eec90a3de706 100644 --- a/pkg/util/jumphash/memcached_client_selector.go +++ b/pkg/util/jumphash/memcached_client_selector.go @@ -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" @@ -23,7 +24,7 @@ import ( // with consistent DNS names where the naturally sorted order // is predictable. type Selector struct { - name string + logger log.Logger mu sync.RWMutex addrs []net.Addr resolveUnixAddr UnixResolver @@ -36,7 +37,7 @@ type TCPResolver func(network, address string) (*net.TCPAddr, error) func NewSelector(name string, resolveUnixAddr UnixResolver, resolveTCPAddr TCPResolver) *Selector { return &Selector{ - name: name, + logger: log.With(util_log.Logger, "name", name), resolveUnixAddr: resolveUnixAddr, resolveTCPAddr: resolveTCPAddr, } @@ -44,7 +45,7 @@ func NewSelector(name string, resolveUnixAddr UnixResolver, resolveTCPAddr TCPRe func DefaultSelector(name string) *Selector { return &Selector{ - name: name, + logger: log.With(util_log.Logger, "name", name), resolveUnixAddr: net.ResolveUnixAddr, resolveTCPAddr: net.ResolveTCPAddr, } @@ -105,7 +106,7 @@ func (s *Selector) SetServers(servers ...string) error { } } - level.Debug(util_log.Logger).Log("msg", "updating servers", "name", s.name, "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() From 4b823bbe5803d07504a083d5c21d13f45455820b Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Mon, 30 Sep 2024 10:41:31 +0200 Subject: [PATCH 3/3] Update tests Signed-off-by: Christian Haudum --- pkg/util/jumphash/memcached_client_selector_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/util/jumphash/memcached_client_selector_test.go b/pkg/util/jumphash/memcached_client_selector_test.go index 939106ad5aac8..06beca0f8800c 100644 --- a/pkg/util/jumphash/memcached_client_selector_test.go +++ b/pkg/util/jumphash/memcached_client_selector_test.go @@ -57,6 +57,7 @@ var mockTCPResolver = func(_, address string) (*net.TCPAddr, error) { func TestMemcachedJumpHashSelector_PickSever(t *testing.T) { s := NewSelector( + "test", mockUnixResolver, mockTCPResolver, ) @@ -84,6 +85,7 @@ func TestMemcachedJumpHashSelector_PickSever(t *testing.T) { func TestMemcachedJumpHashSelector_PickSever_ErrNoServers(t *testing.T) { s := NewSelector( + "test", mockUnixResolver, mockTCPResolver, )