forked from thanos-io/thanos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracing_cache.go
46 lines (35 loc) · 1014 Bytes
/
tracing_cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package cache
import (
"context"
"time"
"github.com/opentracing/opentracing-go"
"github.com/thanos-io/thanos/pkg/tracing"
)
// TracingCache includes Fetch operation in the traces.
type TracingCache struct {
c Cache
}
func NewTracingCache(cache Cache) Cache {
return TracingCache{c: cache}
}
func (t TracingCache) Store(ctx context.Context, data map[string][]byte, ttl time.Duration) {
t.c.Store(ctx, data, ttl)
}
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)
bytes := 0
for _, v := range result {
bytes += len(v)
}
span.LogKV("returned keys", len(result), "returned bytes", bytes)
})
return
}
func (t TracingCache) Name() string {
return t.c.Name()
}