MCPcopy
hub / github.com/grafana/tempo / NewBackground

Function NewBackground

pkg/cache/background.go:44–71  ·  view source on GitHub ↗

NewBackground returns a new Cache that does stores on background goroutines.

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

Source from the content-addressed store, hash-verified

42
43// NewBackground returns a new Cache that does stores on background goroutines.
44func NewBackground(name string, cfg BackgroundConfig, cache Cache, reg prometheus.Registerer) Cache {
45 c := &backgroundCache{
46 Cache: cache,
47 quit: make(chan struct{}),
48 bgWrites: make(chan backgroundWrite, cfg.WriteBackBuffer),
49 name: name,
50 droppedWriteBack: promauto.With(reg).NewCounter(prometheus.CounterOpts{
51 Namespace: "tempo",
52 Name: "cache_dropped_background_writes_total",
53 Help: "Total count of dropped write backs to cache.",
54 ConstLabels: prometheus.Labels{"name": name},
55 }),
56
57 queueLength: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
58 Namespace: "tempo",
59 Name: "cache_background_queue_length",
60 Help: "Length of the cache background write queue.",
61 ConstLabels: prometheus.Labels{"name": name},
62 }),
63 }
64
65 c.wg.Add(cfg.WriteBackGoroutines)
66 for i := 0; i < cfg.WriteBackGoroutines; i++ {
67 go c.writeBackLoop()
68 }
69
70 return c
71}
72
73// Stop the background flushing goroutines.
74func (c *backgroundCache) Stop() {

Callers 3

NewClientFunction · 0.92
NewClientFunction · 0.92
TestBackgroundFunction · 0.92

Calls 4

writeBackLoopMethod · 0.95
NewCounterMethod · 0.65
NewGaugeMethod · 0.65
AddMethod · 0.65

Tested by 1

TestBackgroundFunction · 0.74