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

Store: Adds the name of the instantiated memcached client to log info #3929

Merged
merged 4 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ We use _breaking :warning:_ to mark changes that are not backward compatible (re
- [#3922](https://github.com/thanos-io/thanos/pull/3922) Fix panic in http logging middleware.

### Changed
- [#3929](https://github.com/thanos-io/thanos/pull/3929) Store: Adds the name of the instantiated memcached client to log info

### Removed

Expand Down
22 changes: 14 additions & 8 deletions pkg/cacheutil/memcached_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cacheutil

import (
"context"
"fmt"
"net"
"strconv"
"strings"
Expand Down Expand Up @@ -149,6 +150,9 @@ type memcachedClient struct {
client memcachedClientBackend
selector *MemcachedJumpHashSelector

// Name provides an identifier for the instantiated Client
name string

// DNS provider used to keep the memcached servers list updated.
dnsProvider *dns.Provider

Expand Down Expand Up @@ -205,7 +209,7 @@ func NewMemcachedClientWithConfig(logger log.Logger, name string, config Memcach
if reg != nil {
reg = prometheus.WrapRegistererWith(prometheus.Labels{"name": name}, reg)
}
return newMemcachedClient(logger, client, selector, config, reg)
return newMemcachedClient(logger, client, selector, config, reg, name)
}

func newMemcachedClient(
Expand All @@ -214,6 +218,7 @@ func newMemcachedClient(
selector *MemcachedJumpHashSelector,
config MemcachedClientConfig,
reg prometheus.Registerer,
name string,
) (*memcachedClient, error) {
dnsProvider := dns.NewProvider(
logger,
Expand All @@ -222,6 +227,7 @@ func newMemcachedClient(
)

c := &memcachedClient{
name: name,
logger: logger,
wiardvanrij marked this conversation as resolved.
Show resolved Hide resolved
config: config,
client: client,
Expand Down Expand Up @@ -366,7 +372,7 @@ func (c *memcachedClient) SetAsync(_ context.Context, key string, value []byte,

if err == errMemcachedAsyncBufferFull {
c.skipped.WithLabelValues(opSet, reasonAsyncBufferFull).Inc()
level.Debug(c.logger).Log("msg", "failed to store item to memcached because the async buffer is full", "err", err, "size", len(c.asyncQueue))
level.Debug(c.logger).Log("msg", "failed to store item to memcached because the async buffer is full", "err", err, "size", len(c.asyncQueue), "name", c.name)
return nil
}
return err
Expand All @@ -379,7 +385,7 @@ func (c *memcachedClient) GetMulti(ctx context.Context, keys []string) map[strin

batches, err := c.getMultiBatched(ctx, keys)
if err != nil {
level.Warn(c.logger).Log("msg", "failed to fetch items from memcached", "numKeys", len(keys), "firstKey", keys[0], "err", err)
level.Warn(c.logger).Log("msg", "failed to fetch items from memcached", "numKeys", len(keys), "firstKey", keys[0], "err", err, "name", c.name)

// In case we have both results and an error, it means some batch requests
// failed and other succeeded. In this case we prefer to log it and move on,
Expand Down Expand Up @@ -465,7 +471,7 @@ func (c *memcachedClient) getMultiSingle(ctx context.Context, keys []string) (it
// concurrency should be enforced.
if c.config.MaxGetMultiConcurrency > 0 {
if err := c.getMultiGate.Start(ctx); err != nil {
return nil, errors.Wrapf(err, "failed to wait for turn")
return nil, errors.Wrapf(err, "failed to wait for turn. Instance: %s", c.name)
}
defer c.getMultiGate.Done()
}
Expand All @@ -474,7 +480,7 @@ func (c *memcachedClient) getMultiSingle(ctx context.Context, keys []string) (it
c.operations.WithLabelValues(opGetMulti).Inc()
items, err = c.client.GetMulti(keys)
if err != nil {
level.Debug(c.logger).Log("msg", "failed to get multiple items from memcached", "err", err)
level.Debug(c.logger).Log("msg", "failed to get multiple items from memcached", "err", err, "name", c.name)
c.trackError(opGetMulti, err)
} else {
var total int
Expand Down Expand Up @@ -542,7 +548,7 @@ func (c *memcachedClient) resolveAddrsLoop() {
case <-ticker.C:
err := c.resolveAddrs()
if err != nil {
level.Warn(c.logger).Log("msg", "failed update memcached servers list", "err", err)
level.Warn(c.logger).Log("msg", "failed update memcached servers list", "err", err, "name", c.name)
}
case <-c.stop:
return
Expand All @@ -557,12 +563,12 @@ func (c *memcachedClient) resolveAddrs() error {

// If some of the dns resolution fails, log the error.
if err := c.dnsProvider.Resolve(ctx, c.config.Addresses); err != nil {
level.Error(c.logger).Log("msg", "failed to resolve addresses for memcached", "addresses", strings.Join(c.config.Addresses, ","), "err", err)
level.Error(c.logger).Log("msg", "failed to resolve addresses for memcached", "addresses", strings.Join(c.config.Addresses, ","), "err", err, "name", c.name)
}
// Fail in case no server address is resolved.
servers := c.dnsProvider.Addresses()
if len(servers) == 0 {
return errors.New("no server address resolved")
return fmt.Errorf("no server address resolved for %s", c.name)
}

return c.selector.SetServers(servers...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cacheutil/memcached_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func TestMemcachedClient_GetMulti(t *testing.T) {
func prepare(config MemcachedClientConfig, backendMock *memcachedClientBackendMock) (*memcachedClient, error) {
logger := log.NewNopLogger()
selector := &MemcachedJumpHashSelector{}
client, err := newMemcachedClient(logger, backendMock, selector, config, nil)
client, err := newMemcachedClient(logger, backendMock, selector, config, nil, "test")

return client, err
}
Expand Down