NewBackground returns a new Cache that does stores on background goroutines.
(name string, cfg BackgroundConfig, cache Cache, reg prometheus.Registerer)
| 42 | |
| 43 | // NewBackground returns a new Cache that does stores on background goroutines. |
| 44 | func 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. |
| 74 | func (c *backgroundCache) Stop() { |