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

Query: Put cache name on tracing spans #4696

Merged
merged 2 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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

Expand Down
2 changes: 2 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions pkg/cache/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type InMemoryCache struct {
logger log.Logger
maxSizeBytes uint64
maxItemSizeBytes uint64
name string

mtx sync.Mutex
curSize uint64
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions pkg/cache/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type MemcachedCache struct {
logger log.Logger
memcached cacheutil.MemcachedClient
name string

// Metrics.
requests prometheus.Counter
Expand All @@ -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{
Expand Down Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/cache/tracing_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
4 changes: 4 additions & 0 deletions pkg/store/cache/caching_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down