MCPcopy Create free account
hub / github.com/cortexproject/cortex / Instrument

Function Instrument

pkg/chunk/cache/instrumented.go:14–56  ·  view source on GitHub ↗

Instrument returns an instrumented cache.

(name string, cache Cache, reg prometheus.Registerer)

Source from the content-addressed store, hash-verified

12
13// Instrument returns an instrumented cache.
14func Instrument(name string, cache Cache, reg prometheus.Registerer) Cache {
15 valueSize := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
16 Namespace: "cortex",
17 Name: "cache_value_size_bytes",
18 Help: "Size of values in the cache.",
19 // Cached chunks are generally in the KBs, but cached index can
20 // get big. Histogram goes from 1KB to 4MB.
21 // 1024 * 4^(7-1) = 4MB
22 Buckets: prometheus.ExponentialBuckets(1024, 4, 7),
23 ConstLabels: prometheus.Labels{"name": name},
24 }, []string{"method"})
25
26 return &instrumentedCache{
27 name: name,
28 Cache: cache,
29
30 requestDuration: instr.NewHistogramCollector(promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
31 Namespace: "cortex",
32 Name: "cache_request_duration_seconds",
33 Help: "Total time spent in seconds doing cache requests.",
34 // Cache requests are very quick: smallest bucket is 16us, biggest is 1s.
35 Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8),
36 ConstLabels: prometheus.Labels{"name": name},
37 }, []string{"method", "status_code"})),
38
39 fetchedKeys: promauto.With(reg).NewCounter(prometheus.CounterOpts{
40 Namespace: "cortex",
41 Name: "cache_fetched_keys_total",
42 Help: "Total count of keys requested from cache.",
43 ConstLabels: prometheus.Labels{"name": name},
44 }),
45
46 hits: promauto.With(reg).NewCounter(prometheus.CounterOpts{
47 Namespace: "cortex",
48 Name: "cache_hits_total",
49 Help: "Total count of keys found in cache.",
50 ConstLabels: prometheus.Labels{"name": name},
51 }),
52
53 storedValueSize: valueSize.WithLabelValues("store"),
54 fetchedValueSize: valueSize.WithLabelValues("fetch"),
55 }
56}
57
58type instrumentedCache struct {
59 name string

Callers 1

NewFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected