diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f071c41be..dde5d56aa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Added - [#4680](https://github.com/thanos-io/thanos/pull/4680) Query: add `exemplar.partial-response` flag to control partial response. +- [#4696](https://github.com/thanos-io/thanos/pull/4696) Query: add cache name to tracing spans. ## v0.23.0 - In Progress diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index acaa0e159d..24e52aac00 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -18,4 +18,6 @@ type Cache interface { // Fetch multiple keys from cache. Returns map of input keys to data. // If key isn't in the map, data for given key was not found. Fetch(ctx context.Context, keys []string) map[string][]byte + + Name() string } diff --git a/pkg/cache/inmemory.go b/pkg/cache/inmemory.go index 6a6036a03a..8ddfe9f0b9 100644 --- a/pkg/cache/inmemory.go +++ b/pkg/cache/inmemory.go @@ -41,6 +41,7 @@ type InMemoryCache struct { logger log.Logger maxSizeBytes uint64 maxItemSizeBytes uint64 + name string mtx sync.Mutex curSize uint64 @@ -100,6 +101,7 @@ func NewInMemoryCacheWithConfig(name string, logger log.Logger, reg prometheus.R logger: logger, maxSizeBytes: uint64(config.MaxSize), maxItemSizeBytes: uint64(config.MaxItemSize), + name: name, } c.evicted = promauto.With(reg).NewCounter(prometheus.CounterOpts{ @@ -303,3 +305,7 @@ func (c *InMemoryCache) Fetch(ctx context.Context, keys []string) map[string][]b } return results } + +func (c *InMemoryCache) Name() string { + return c.name +} diff --git a/pkg/cache/memcached.go b/pkg/cache/memcached.go index 04c249576e..695b78e6cd 100644 --- a/pkg/cache/memcached.go +++ b/pkg/cache/memcached.go @@ -19,6 +19,7 @@ import ( type MemcachedCache struct { logger log.Logger memcached cacheutil.MemcachedClient + name string // Metrics. requests prometheus.Counter @@ -30,6 +31,7 @@ func NewMemcachedCache(name string, logger log.Logger, memcached cacheutil.Memca c := &MemcachedCache{ logger: logger, memcached: memcached, + name: name, } c.requests = promauto.With(reg).NewCounter(prometheus.CounterOpts{ @@ -81,3 +83,7 @@ func (c *MemcachedCache) Fetch(ctx context.Context, keys []string) map[string][] c.hits.Add(float64(len(results))) return results } + +func (c *MemcachedCache) Name() string { + return c.name +} diff --git a/pkg/cache/tracing_cache.go b/pkg/cache/tracing_cache.go index ed440c43ad..81fb5bef8e 100644 --- a/pkg/cache/tracing_cache.go +++ b/pkg/cache/tracing_cache.go @@ -27,6 +27,7 @@ func (t TracingCache) Store(ctx context.Context, data map[string][]byte, ttl tim func (t TracingCache) Fetch(ctx context.Context, keys []string) (result map[string][]byte) { tracing.DoWithSpan(ctx, "cache_fetch", func(spanCtx context.Context, span opentracing.Span) { + span.SetTag("name", t.Name()) span.LogKV("requested keys", len(keys)) result = t.c.Fetch(spanCtx, keys) @@ -39,3 +40,7 @@ func (t TracingCache) Fetch(ctx context.Context, keys []string) (result map[stri }) return } + +func (t TracingCache) Name() string { + return t.c.Name() +} diff --git a/pkg/store/cache/caching_bucket_test.go b/pkg/store/cache/caching_bucket_test.go index 9bf0bddcbd..902be08f37 100644 --- a/pkg/store/cache/caching_bucket_test.go +++ b/pkg/store/cache/caching_bucket_test.go @@ -295,6 +295,10 @@ func (m *mockCache) Fetch(_ context.Context, keys []string) map[string][]byte { return found } +func (m *mockCache) Name() string { + return "mockCache" +} + func (m *mockCache) flush() { m.cache = map[string]cacheItem{} }