From 4e7c3e5cf6378943b694b360adfe47b923660ef0 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Mon, 30 Sep 2024 09:28:33 +0200 Subject: [PATCH] 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 989ced34c6730..212b47f88f333 100644 --- a/pkg/bloomgateway/client_pool.go +++ b/pkg/bloomgateway/client_pool.go @@ -47,7 +47,7 @@ type AddressProvider interface { } func NewJumpHashClientPool(pool *client.Pool, dnsProvider AddressProvider, updateInterval time.Duration, logger log.Logger) *JumpHashClientPool { - 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()