diff --git a/CHANGELOG.md b/CHANGELOG.md index c0a02526c72..984bb80b92d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ * [CHANGE] Experimental TSDB: compact head when opening TSDB. This should only affect ingester startup after it was unable to compact head in previous run. #2870 * [CHANGE] Metric `cortex_overrides_last_reload_successful` has been renamed to `cortex_runtime_config_last_reload_successful`. #2874 * [CHANGE] HipChat support has been removed from the alertmanager (because removed from the Prometheus upstream too). #2902 +* [CHANGE] Add constant label `name` to metric `cortex_cache_request_duration_seconds`. #2903 * [FEATURE] Introduced `ruler.for-outage-tolerance`, Max time to tolerate outage for restoring "for" state of alert. #2783 * [FEATURE] Introduced `ruler.for-grace-period`, Minimum duration between alert and restored "for" state. This is maintained only for alerts with configured "for" time greater than grace period. #2783 * [FEATURE] Introduced `ruler.resend-delay`, Minimum amount of time to wait before resending an alert to Alertmanager. #2783 diff --git a/integration/chunks_storage_backends_test.go b/integration/chunks_storage_backends_test.go index 55138a8928d..a5f9331185a 100644 --- a/integration/chunks_storage_backends_test.go +++ b/integration/chunks_storage_backends_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "github.com/go-kit/kit/log" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "github.com/stretchr/testify/assert" @@ -184,7 +185,7 @@ func TestSwiftChunkStorage(t *testing.T) { limits, err := validation.NewOverrides(defaults, nil) require.NoError(t, err) - store, err := storage.NewStore(cfg, storeConfig, schemaConfig, limits, nil, nil) + store, err := storage.NewStore(cfg, storeConfig, schemaConfig, limits, nil, nil, log.NewNopLogger()) require.NoError(t, err) defer store.Stop() diff --git a/pkg/chunk/cache/background.go b/pkg/chunk/cache/background.go index 994c49b7452..bfdfb748d89 100644 --- a/pkg/chunk/cache/background.go +++ b/pkg/chunk/cache/background.go @@ -11,19 +11,6 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" ) -var ( - droppedWriteBack = promauto.NewCounterVec(prometheus.CounterOpts{ - Namespace: "cortex", - Name: "cache_dropped_background_writes_total", - Help: "Total count of dropped write backs to cache.", - }, []string{"name"}) - queueLength = promauto.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "cortex", - Name: "cache_background_queue_length", - Help: "Length of the cache background write queue.", - }, []string{"name"}) -) - // BackgroundConfig is config for a Background Cache. type BackgroundConfig struct { WriteBackGoroutines int `yaml:"writeback_goroutines"` @@ -54,14 +41,25 @@ type backgroundWrite struct { } // NewBackground returns a new Cache that does stores on background goroutines. -func NewBackground(name string, cfg BackgroundConfig, cache Cache) Cache { +func NewBackground(name string, cfg BackgroundConfig, cache Cache, reg prometheus.Registerer) Cache { c := &backgroundCache{ - Cache: cache, - quit: make(chan struct{}), - bgWrites: make(chan backgroundWrite, cfg.WriteBackBuffer), - name: name, - droppedWriteBack: droppedWriteBack.WithLabelValues(name), - queueLength: queueLength.WithLabelValues(name), + Cache: cache, + quit: make(chan struct{}), + bgWrites: make(chan backgroundWrite, cfg.WriteBackBuffer), + name: name, + droppedWriteBack: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "cortex", + Name: "cache_dropped_background_writes_total", + Help: "Total count of dropped write backs to cache.", + ConstLabels: prometheus.Labels{"name": name}, + }), + + queueLength: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Namespace: "cortex", + Name: "cache_background_queue_length", + Help: "Length of the cache background write queue.", + ConstLabels: prometheus.Labels{"name": name}, + }), } c.wg.Add(cfg.WriteBackGoroutines) diff --git a/pkg/chunk/cache/background_test.go b/pkg/chunk/cache/background_test.go index e8acaa50ea3..06e69bf28be 100644 --- a/pkg/chunk/cache/background_test.go +++ b/pkg/chunk/cache/background_test.go @@ -10,7 +10,7 @@ func TestBackground(t *testing.T) { c := cache.NewBackground("mock", cache.BackgroundConfig{ WriteBackGoroutines: 1, WriteBackBuffer: 100, - }, cache.NewMockCache()) + }, cache.NewMockCache(), nil) keys, chunks := fillCache(t, c) cache.Flush(c) diff --git a/pkg/chunk/cache/cache.go b/pkg/chunk/cache/cache.go index e400e88a32b..dbbc6b2e8c4 100644 --- a/pkg/chunk/cache/cache.go +++ b/pkg/chunk/cache/cache.go @@ -6,6 +6,7 @@ import ( "flag" "time" + "github.com/go-kit/kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -60,7 +61,7 @@ func (cfg *Config) Validate() error { } // New creates a new Cache using Config. -func New(cfg Config) (Cache, error) { +func New(cfg Config, reg prometheus.Registerer, logger log.Logger) (Cache, error) { if cfg.Cache != nil { return cfg.Cache, nil } @@ -72,8 +73,8 @@ func New(cfg Config) (Cache, error) { cfg.Fifocache.Validity = cfg.DefaultValidity } - if cache := NewFifoCache(cfg.Prefix+"fifocache", cfg.Fifocache); cache != nil { - caches = append(caches, Instrument(cfg.Prefix+"fifocache", cache)) + if cache := NewFifoCache(cfg.Prefix+"fifocache", cfg.Fifocache, reg, logger); cache != nil { + caches = append(caches, Instrument(cfg.Prefix+"fifocache", cache, reg)) } } @@ -86,11 +87,11 @@ func New(cfg Config) (Cache, error) { cfg.Memcache.Expiration = cfg.DefaultValidity } - client := NewMemcachedClient(cfg.MemcacheClient, cfg.Prefix, prometheus.DefaultRegisterer) - cache := NewMemcached(cfg.Memcache, client, cfg.Prefix) + client := NewMemcachedClient(cfg.MemcacheClient, cfg.Prefix, reg, logger) + cache := NewMemcached(cfg.Memcache, client, cfg.Prefix, reg, logger) cacheName := cfg.Prefix + "memcache" - caches = append(caches, NewBackground(cacheName, cfg.Background, Instrument(cacheName, cache))) + caches = append(caches, NewBackground(cacheName, cfg.Background, Instrument(cacheName, cache, reg), reg)) } if cfg.Redis.Endpoint != "" { @@ -98,13 +99,13 @@ func New(cfg Config) (Cache, error) { cfg.Redis.Expiration = cfg.DefaultValidity } cacheName := cfg.Prefix + "redis" - cache := NewRedisCache(cfg.Redis, cacheName, nil) - caches = append(caches, NewBackground(cacheName, cfg.Background, Instrument(cacheName, cache))) + cache := NewRedisCache(cfg.Redis, cacheName, nil, logger) + caches = append(caches, NewBackground(cacheName, cfg.Background, Instrument(cacheName, cache, reg), reg)) } cache := NewTiered(caches) if len(caches) > 1 { - cache = Instrument(cfg.Prefix+"tiered", cache) + cache = Instrument(cfg.Prefix+"tiered", cache, reg) } return cache, nil } diff --git a/pkg/chunk/cache/cache_test.go b/pkg/chunk/cache/cache_test.go index 36faa5fd4fb..3500a6cbd0f 100644 --- a/pkg/chunk/cache/cache_test.go +++ b/pkg/chunk/cache/cache_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/go-kit/kit/log" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "github.com/stretchr/testify/require" @@ -158,7 +159,8 @@ func testCache(t *testing.T, cache cache.Cache) { func TestMemcache(t *testing.T) { t.Run("Unbatched", func(t *testing.T) { - cache := cache.NewMemcached(cache.MemcachedConfig{}, newMockMemcache(), "test") + cache := cache.NewMemcached(cache.MemcachedConfig{}, newMockMemcache(), + "test", nil, log.NewNopLogger()) testCache(t, cache) }) @@ -166,17 +168,18 @@ func TestMemcache(t *testing.T) { cache := cache.NewMemcached(cache.MemcachedConfig{ BatchSize: 10, Parallelism: 3, - }, newMockMemcache(), "test") + }, newMockMemcache(), "test", nil, log.NewNopLogger()) testCache(t, cache) }) } func TestFifoCache(t *testing.T) { - cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 1e3, Validity: 1 * time.Hour}) + cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 1e3, Validity: 1 * time.Hour}, + nil, log.NewNopLogger()) testCache(t, cache) } func TestSnappyCache(t *testing.T) { - cache := cache.NewSnappy(cache.NewMockCache()) + cache := cache.NewSnappy(cache.NewMockCache(), log.NewNopLogger()) testCache(t, cache) } diff --git a/pkg/chunk/cache/fifo_cache.go b/pkg/chunk/cache/fifo_cache.go index ca331de77e6..81432d1a1e5 100644 --- a/pkg/chunk/cache/fifo_cache.go +++ b/pkg/chunk/cache/fifo_cache.go @@ -9,6 +9,7 @@ import ( "unsafe" "github.com/dustin/go-humanize" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -18,64 +19,6 @@ import ( "github.com/cortexproject/cortex/pkg/util/flagext" ) -var ( - cacheEntriesAdded = promauto.NewCounterVec(prometheus.CounterOpts{ - Namespace: "querier", - Subsystem: "cache", - Name: "added_total", - Help: "The total number of Put calls on the cache", - }, []string{"cache"}) - - cacheEntriesAddedNew = promauto.NewCounterVec(prometheus.CounterOpts{ - Namespace: "querier", - Subsystem: "cache", - Name: "added_new_total", - Help: "The total number of new entries added to the cache", - }, []string{"cache"}) - - cacheEntriesEvicted = promauto.NewCounterVec(prometheus.CounterOpts{ - Namespace: "querier", - Subsystem: "cache", - Name: "evicted_total", - Help: "The total number of evicted entries", - }, []string{"cache"}) - - cacheEntriesCurrent = promauto.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "querier", - Subsystem: "cache", - Name: "entries", - Help: "The total number of entries", - }, []string{"cache"}) - - cacheTotalGets = promauto.NewCounterVec(prometheus.CounterOpts{ - Namespace: "querier", - Subsystem: "cache", - Name: "gets_total", - Help: "The total number of Get calls", - }, []string{"cache"}) - - cacheTotalMisses = promauto.NewCounterVec(prometheus.CounterOpts{ - Namespace: "querier", - Subsystem: "cache", - Name: "misses_total", - Help: "The total number of Get calls that had no valid entry", - }, []string{"cache"}) - - cacheStaleGets = promauto.NewCounterVec(prometheus.CounterOpts{ - Namespace: "querier", - Subsystem: "cache", - Name: "stale_gets_total", - Help: "The total number of Get calls that had an entry which expired", - }, []string{"cache"}) - - cacheMemoryBytes = promauto.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "querier", - Subsystem: "cache", - Name: "memory_bytes", - Help: "The current cache size in bytes", - }, []string{"cache"}) -) - const ( elementSize = int(unsafe.Sizeof(list.Element{})) elementPrtSize = int(unsafe.Sizeof(&list.Element{})) @@ -149,20 +92,19 @@ type cacheEntry struct { } // NewFifoCache returns a new initialised FifoCache of size. -// TODO(bwplotka): Fix metrics, get them out of globals, separate or allow prefixing. -func NewFifoCache(name string, cfg FifoCacheConfig) *FifoCache { +func NewFifoCache(name string, cfg FifoCacheConfig, reg prometheus.Registerer, logger log.Logger) *FifoCache { util.WarnExperimentalUse("In-memory (FIFO) cache") if cfg.DeprecatedSize > 0 { flagext.DeprecatedFlagsUsed.Inc() - level.Warn(util.Logger).Log("msg", "running with DEPRECATED flag fifocache.size, use fifocache.max-size-items or fifocache.max-size-bytes instead", "cache", name) + level.Warn(logger).Log("msg", "running with DEPRECATED flag fifocache.size, use fifocache.max-size-items or fifocache.max-size-bytes instead", "cache", name) cfg.MaxSizeItems = cfg.DeprecatedSize } maxSizeBytes, _ := parsebytes(cfg.MaxSizeBytes) if maxSizeBytes == 0 && cfg.MaxSizeItems == 0 { // zero cache capacity - no need to create cache - level.Warn(util.Logger).Log("msg", "neither fifocache.max-size-bytes nor fifocache.max-size-items is set", "cache", name) + level.Warn(logger).Log("msg", "neither fifocache.max-size-bytes nor fifocache.max-size-items is set", "cache", name) return nil } return &FifoCache{ @@ -172,15 +114,69 @@ func NewFifoCache(name string, cfg FifoCacheConfig) *FifoCache { entries: make(map[string]*list.Element), lru: list.New(), - // TODO(bwplotka): There might be simple cache.Cache wrapper for those. - entriesAdded: cacheEntriesAdded.WithLabelValues(name), - entriesAddedNew: cacheEntriesAddedNew.WithLabelValues(name), - entriesEvicted: cacheEntriesEvicted.WithLabelValues(name), - entriesCurrent: cacheEntriesCurrent.WithLabelValues(name), - totalGets: cacheTotalGets.WithLabelValues(name), - totalMisses: cacheTotalMisses.WithLabelValues(name), - staleGets: cacheStaleGets.WithLabelValues(name), - memoryBytes: cacheMemoryBytes.WithLabelValues(name), + entriesAdded: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "querier", + Subsystem: "cache", + Name: "added_total", + Help: "The total number of Put calls on the cache", + ConstLabels: prometheus.Labels{"cache": name}, + }), + + entriesAddedNew: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "querier", + Subsystem: "cache", + Name: "added_new_total", + Help: "The total number of new entries added to the cache", + ConstLabels: prometheus.Labels{"cache": name}, + }), + + entriesEvicted: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "querier", + Subsystem: "cache", + Name: "evicted_total", + Help: "The total number of evicted entries", + ConstLabels: prometheus.Labels{"cache": name}, + }), + + entriesCurrent: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Namespace: "querier", + Subsystem: "cache", + Name: "entries", + Help: "The total number of entries", + ConstLabels: prometheus.Labels{"cache": name}, + }), + + totalGets: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "querier", + Subsystem: "cache", + Name: "gets_total", + Help: "The total number of Get calls", + ConstLabels: prometheus.Labels{"cache": name}, + }), + + totalMisses: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "querier", + Subsystem: "cache", + Name: "misses_total", + Help: "The total number of Get calls that had no valid entry", + ConstLabels: prometheus.Labels{"cache": name}, + }), + + staleGets: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "querier", + Subsystem: "cache", + Name: "stale_gets_total", + Help: "The total number of Get calls that had an entry which expired", + ConstLabels: prometheus.Labels{"cache": name}, + }), + + memoryBytes: promauto.With(reg).NewGauge(prometheus.GaugeOpts{ + Namespace: "querier", + Subsystem: "cache", + Name: "memory_bytes", + Help: "The current cache size in bytes", + ConstLabels: prometheus.Labels{"cache": name}, + }), } } diff --git a/pkg/chunk/cache/fifo_cache_test.go b/pkg/chunk/cache/fifo_cache_test.go index f41d5813a6c..d8988e72c48 100644 --- a/pkg/chunk/cache/fifo_cache_test.go +++ b/pkg/chunk/cache/fifo_cache_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/go-kit/kit/log" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -37,7 +38,7 @@ func TestFifoCacheEviction(t *testing.T) { } for _, test := range tests { - c := NewFifoCache(test.name, test.cfg) + c := NewFifoCache(test.name, test.cfg, nil, log.NewNopLogger()) ctx := context.Background() // Check put / get works @@ -185,7 +186,7 @@ func TestFifoCacheExpiry(t *testing.T) { } for _, test := range tests { - c := NewFifoCache(test.name, test.cfg) + c := NewFifoCache(test.name, test.cfg, nil, log.NewNopLogger()) ctx := context.Background() c.Store(ctx, diff --git a/pkg/chunk/cache/instrumented.go b/pkg/chunk/cache/instrumented.go index c5c43b21cec..ca27d4a3b4e 100644 --- a/pkg/chunk/cache/instrumented.go +++ b/pkg/chunk/cache/instrumented.go @@ -6,58 +6,52 @@ import ( ot "github.com/opentracing/opentracing-go" otlog "github.com/opentracing/opentracing-go/log" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" instr "github.com/weaveworks/common/instrument" ) -var ( - requestDuration = instr.NewHistogramCollector(prometheus.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "cortex", - Name: "cache_request_duration_seconds", - Help: "Total time spent in seconds doing cache requests.", - // Cache requests are very quick: smallest bucket is 16us, biggest is 1s. - Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8), - }, []string{"method", "status_code"})) - - fetchedKeys = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "cortex", - Name: "cache_fetched_keys", - Help: "Total count of keys requested from cache.", - }, []string{"name"}) - - hits = prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: "cortex", - Name: "cache_hits", - Help: "Total count of keys found in cache.", - }, []string{"name"}) - - valueSize = prometheus.NewHistogramVec(prometheus.HistogramOpts{ +// Instrument returns an instrumented cache. +func Instrument(name string, cache Cache, reg prometheus.Registerer) Cache { + valueSize := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ Namespace: "cortex", Name: "cache_value_size_bytes", Help: "Size of values in the cache.", // Cached chunks are generally in the KBs, but cached index can // get big. Histogram goes from 1KB to 4MB. // 1024 * 4^(7-1) = 4MB - Buckets: prometheus.ExponentialBuckets(1024, 4, 7), - }, []string{"name", "method"}) -) + Buckets: prometheus.ExponentialBuckets(1024, 4, 7), + ConstLabels: prometheus.Labels{"name": name}, + }, []string{"method"}) -func init() { - requestDuration.Register() - prometheus.MustRegister(fetchedKeys) - prometheus.MustRegister(hits) - prometheus.MustRegister(valueSize) -} - -// Instrument returns an instrumented cache. -func Instrument(name string, cache Cache) Cache { return &instrumentedCache{ name: name, Cache: cache, - fetchedKeys: fetchedKeys.WithLabelValues(name), - hits: hits.WithLabelValues(name), - storedValueSize: valueSize.WithLabelValues(name, "store"), - fetchedValueSize: valueSize.WithLabelValues(name, "fetch"), + requestDuration: instr.NewHistogramCollector(promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ + Namespace: "cortex", + Name: "cache_request_duration_seconds", + Help: "Total time spent in seconds doing cache requests.", + // Cache requests are very quick: smallest bucket is 16us, biggest is 1s. + Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8), + ConstLabels: prometheus.Labels{"name": name}, + }, []string{"method", "status_code"})), + + fetchedKeys: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "cortex", + Name: "cache_fetched_keys", + Help: "Total count of keys requested from cache.", + ConstLabels: prometheus.Labels{"name": name}, + }), + + hits: promauto.With(reg).NewCounter(prometheus.CounterOpts{ + Namespace: "cortex", + Name: "cache_hits", + Help: "Total count of keys found in cache.", + ConstLabels: prometheus.Labels{"name": name}, + }), + + storedValueSize: valueSize.WithLabelValues("store"), + fetchedValueSize: valueSize.WithLabelValues("fetch"), } } @@ -67,6 +61,7 @@ type instrumentedCache struct { fetchedKeys, hits prometheus.Counter storedValueSize, fetchedValueSize prometheus.Observer + requestDuration *instr.HistogramCollector } func (i *instrumentedCache) Store(ctx context.Context, keys []string, bufs [][]byte) { @@ -75,7 +70,7 @@ func (i *instrumentedCache) Store(ctx context.Context, keys []string, bufs [][]b } method := i.name + ".store" - _ = instr.CollectedRequest(ctx, method, requestDuration, instr.ErrorCode, func(ctx context.Context) error { + _ = instr.CollectedRequest(ctx, method, i.requestDuration, instr.ErrorCode, func(ctx context.Context) error { sp := ot.SpanFromContext(ctx) sp.LogFields(otlog.Int("keys", len(keys))) i.Cache.Store(ctx, keys, bufs) @@ -91,7 +86,7 @@ func (i *instrumentedCache) Fetch(ctx context.Context, keys []string) ([]string, method = i.name + ".fetch" ) - _ = instr.CollectedRequest(ctx, method, requestDuration, instr.ErrorCode, func(ctx context.Context) error { + _ = instr.CollectedRequest(ctx, method, i.requestDuration, instr.ErrorCode, func(ctx context.Context) error { sp := ot.SpanFromContext(ctx) sp.LogFields(otlog.Int("keys requested", len(keys))) diff --git a/pkg/chunk/cache/memcached.go b/pkg/chunk/cache/memcached.go index 0b14180e11f..c2101e69168 100644 --- a/pkg/chunk/cache/memcached.go +++ b/pkg/chunk/cache/memcached.go @@ -9,6 +9,7 @@ import ( "time" "github.com/bradfitz/gomemcache/memcache" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" opentracing "github.com/opentracing/opentracing-go" otlog "github.com/opentracing/opentracing-go/log" @@ -19,16 +20,6 @@ import ( "github.com/cortexproject/cortex/pkg/util" ) -var ( - memcacheRequestDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ - Namespace: "cortex", - Name: "memcache_request_duration_seconds", - Help: "Total time spent in seconds doing memcache requests.", - // Memecache requests are very quick: smallest bucket is 16us, biggest is 1s - Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8), - }, []string{"method", "status_code", "name"}) -) - type observableVecCollector struct { v prometheus.ObserverVec } @@ -64,20 +55,26 @@ type Memcached struct { wg sync.WaitGroup inputCh chan *work + + logger log.Logger } // NewMemcached makes a new Memcache. -// TODO(bwplotka): Fix metrics, get them out of globals, separate or allow prefixing. -// TODO(bwplotka): Remove globals & util packages from cache package entirely (e.g util.Logger). -func NewMemcached(cfg MemcachedConfig, client MemcachedClient, name string) *Memcached { +func NewMemcached(cfg MemcachedConfig, client MemcachedClient, name string, reg prometheus.Registerer, logger log.Logger) *Memcached { c := &Memcached{ cfg: cfg, memcache: client, name: name, + logger: logger, requestDuration: observableVecCollector{ - v: memcacheRequestDuration.MustCurryWith(prometheus.Labels{ - "name": name, - }), + v: promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ + Namespace: "cortex", + Name: "memcache_request_duration_seconds", + Help: "Total time spent in seconds doing memcache requests.", + // Memecache requests are very quick: smallest bucket is 16us, biggest is 1s + Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8), + ConstLabels: prometheus.Labels{"name": name}, + }, []string{"method", "status_code"}), }, } @@ -161,7 +158,7 @@ func (c *Memcached) fetch(ctx context.Context, keys []string) (found []string, b // Memcached returns partial results even on error. if err != nil { sp.LogFields(otlog.Error(err)) - level.Error(util.Logger).Log("msg", "Failed to get keys from memcached", "err", err) + level.Error(c.logger).Log("msg", "Failed to get keys from memcached", "err", err) } return err }) @@ -234,7 +231,7 @@ func (c *Memcached) Store(ctx context.Context, keys []string, bufs [][]byte) { return c.memcache.Set(&item) }) if err != nil { - level.Error(util.Logger).Log("msg", "failed to put to memcached", "name", c.name, "err", err) + level.Error(c.logger).Log("msg", "failed to put to memcached", "name", c.name, "err", err) } } } diff --git a/pkg/chunk/cache/memcached_client.go b/pkg/chunk/cache/memcached_client.go index df0969dc78f..6a0b52a0ff5 100644 --- a/pkg/chunk/cache/memcached_client.go +++ b/pkg/chunk/cache/memcached_client.go @@ -11,6 +11,7 @@ import ( "time" "github.com/bradfitz/gomemcache/memcache" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -20,14 +21,6 @@ import ( "github.com/cortexproject/cortex/pkg/util" ) -var ( - memcacheServersDiscovered = promauto.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: "cortex", - Name: "memcache_client_servers", - Help: "The number of memcache servers discovered.", - }, []string{"name"}) -) - // MemcachedClient interface exists for mocking memcacheClient. type MemcachedClient interface { GetMulti(keys []string) (map[string]*memcache.Item, error) @@ -55,6 +48,8 @@ type memcachedClient struct { wait sync.WaitGroup numServers prometheus.Gauge + + logger log.Logger } // MemcachedClientConfig defines how a MemcachedClient should be constructed. @@ -81,7 +76,7 @@ func (cfg *MemcachedClientConfig) RegisterFlagsWithPrefix(prefix, description st // NewMemcachedClient creates a new MemcacheClient that gets its server list // from SRV and updates the server list on a regular basis. -func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Registerer) MemcachedClient { +func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Registerer, logger log.Logger) MemcachedClient { var selector serverSelector if cfg.ConsistentHash { selector = &MemcachedJumpHashSelector{} @@ -102,10 +97,16 @@ func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Reg serverList: selector, hostname: cfg.Host, service: cfg.Service, - provider: dns.NewProvider(util.Logger, dnsProviderRegisterer, dns.GolangResolverType), + logger: logger, + provider: dns.NewProvider(logger, dnsProviderRegisterer, dns.GolangResolverType), quit: make(chan struct{}), - numServers: memcacheServersDiscovered.WithLabelValues(name), + numServers: promauto.With(r).NewGauge(prometheus.GaugeOpts{ + Namespace: "cortex", + Name: "memcache_client_servers", + Help: "The number of memcache servers discovered.", + ConstLabels: prometheus.Labels{"name": name}, + }), } if len(cfg.Addresses) > 0 { @@ -115,7 +116,7 @@ func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Reg err := newClient.updateMemcacheServers() if err != nil { - level.Error(util.Logger).Log("msg", "error setting memcache servers to host", "host", cfg.Host, "err", err) + level.Error(logger).Log("msg", "error setting memcache servers to host", "host", cfg.Host, "err", err) } newClient.wait.Add(1) @@ -153,7 +154,7 @@ func (c *memcachedClient) updateLoop(updateInterval time.Duration) { case <-ticker.C: err := c.updateMemcacheServers() if err != nil { - level.Warn(util.Logger).Log("msg", "error updating memcache servers", "err", err) + level.Warn(c.logger).Log("msg", "error updating memcache servers", "err", err) } case <-c.quit: ticker.Stop() diff --git a/pkg/chunk/cache/memcached_test.go b/pkg/chunk/cache/memcached_test.go index f6f2b83725f..5bf8b6e2aab 100644 --- a/pkg/chunk/cache/memcached_test.go +++ b/pkg/chunk/cache/memcached_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/bradfitz/gomemcache/memcache" + "github.com/go-kit/kit/log" "github.com/stretchr/testify/require" "github.com/cortexproject/cortex/pkg/chunk/cache" @@ -15,7 +16,8 @@ import ( func TestMemcached(t *testing.T) { t.Run("unbatched", func(t *testing.T) { client := newMockMemcache() - memcache := cache.NewMemcached(cache.MemcachedConfig{}, client, "test") + memcache := cache.NewMemcached(cache.MemcachedConfig{}, client, + "test", nil, log.NewNopLogger()) testMemcache(t, memcache) }) @@ -25,7 +27,7 @@ func TestMemcached(t *testing.T) { memcache := cache.NewMemcached(cache.MemcachedConfig{ BatchSize: 10, Parallelism: 5, - }, client, "test") + }, client, "test", nil, log.NewNopLogger()) testMemcache(t, memcache) }) @@ -90,7 +92,8 @@ func (c *mockMemcacheFailing) GetMulti(keys []string) (map[string]*memcache.Item func TestMemcacheFailure(t *testing.T) { t.Run("unbatched", func(t *testing.T) { client := newMockMemcacheFailing() - memcache := cache.NewMemcached(cache.MemcachedConfig{}, client, "test") + memcache := cache.NewMemcached(cache.MemcachedConfig{}, client, + "test", nil, log.NewNopLogger()) testMemcacheFailing(t, memcache) }) @@ -100,7 +103,7 @@ func TestMemcacheFailure(t *testing.T) { memcache := cache.NewMemcached(cache.MemcachedConfig{ BatchSize: 10, Parallelism: 5, - }, client, "test") + }, client, "test", nil, log.NewNopLogger()) testMemcacheFailing(t, memcache) }) diff --git a/pkg/chunk/cache/redis_cache.go b/pkg/chunk/cache/redis_cache.go index fac33bb4589..382290e30ba 100644 --- a/pkg/chunk/cache/redis_cache.go +++ b/pkg/chunk/cache/redis_cache.go @@ -5,6 +5,7 @@ import ( "flag" "time" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/gomodule/redigo/redis" @@ -18,6 +19,7 @@ type RedisCache struct { expiration int timeout time.Duration pool *redis.Pool + logger log.Logger } // RedisConfig defines how a RedisCache should be constructed. @@ -49,7 +51,7 @@ func (cfg *RedisConfig) RegisterFlagsWithPrefix(prefix, description string, f *f } // NewRedisCache creates a new RedisCache -func NewRedisCache(cfg RedisConfig, name string, pool *redis.Pool) *RedisCache { +func NewRedisCache(cfg RedisConfig, name string, pool *redis.Pool, logger log.Logger) *RedisCache { util.WarnExperimentalUse("Redis cache") // pool != nil only in unit tests if pool == nil { @@ -82,10 +84,11 @@ func NewRedisCache(cfg RedisConfig, name string, pool *redis.Pool) *RedisCache { timeout: cfg.Timeout, name: name, pool: pool, + logger: logger, } if err := cache.ping(context.Background()); err != nil { - level.Error(util.Logger).Log("msg", "error connecting to redis", "endpoint", cfg.Endpoint, "err", err) + level.Error(logger).Log("msg", "error connecting to redis", "endpoint", cfg.Endpoint, "err", err) } return cache @@ -96,7 +99,7 @@ func (c *RedisCache) Fetch(ctx context.Context, keys []string) (found []string, data, err := c.mget(ctx, keys) if err != nil { - level.Error(util.Logger).Log("msg", "failed to get from redis", "name", c.name, "err", err) + level.Error(c.logger).Log("msg", "failed to get from redis", "name", c.name, "err", err) missed = make([]string, len(keys)) copy(missed, keys) return @@ -116,7 +119,7 @@ func (c *RedisCache) Fetch(ctx context.Context, keys []string) (found []string, func (c *RedisCache) Store(ctx context.Context, keys []string, bufs [][]byte) { err := c.mset(ctx, keys, bufs, c.expiration) if err != nil { - level.Error(util.Logger).Log("msg", "failed to put to redis", "name", c.name, "err", err) + level.Error(c.logger).Log("msg", "failed to put to redis", "name", c.name, "err", err) } } @@ -126,7 +129,7 @@ func (c *RedisCache) Stop() { } // mset adds key-value pairs to the cache. -func (c *RedisCache) mset(ctx context.Context, keys []string, bufs [][]byte, ttl int) error { +func (c *RedisCache) mset(_ context.Context, keys []string, bufs [][]byte, ttl int) error { conn := c.pool.Get() defer conn.Close() @@ -143,7 +146,7 @@ func (c *RedisCache) mset(ctx context.Context, keys []string, bufs [][]byte, ttl } // mget retrieves values from the cache. -func (c *RedisCache) mget(ctx context.Context, keys []string) ([][]byte, error) { +func (c *RedisCache) mget(_ context.Context, keys []string) ([][]byte, error) { intf := make([]interface{}, len(keys)) for i, key := range keys { intf[i] = key @@ -155,7 +158,7 @@ func (c *RedisCache) mget(ctx context.Context, keys []string) ([][]byte, error) return redis.ByteSlices(redis.DoWithTimeout(conn, c.timeout, "MGET", intf...)) } -func (c *RedisCache) ping(ctx context.Context) error { +func (c *RedisCache) ping(_ context.Context) error { conn := c.pool.Get() defer conn.Close() diff --git a/pkg/chunk/cache/redis_cache_test.go b/pkg/chunk/cache/redis_cache_test.go index 1330cde97fc..1511c11e96b 100644 --- a/pkg/chunk/cache/redis_cache_test.go +++ b/pkg/chunk/cache/redis_cache_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/go-kit/kit/log" "github.com/gomodule/redigo/redis" "github.com/rafaeljusto/redigomock" "github.com/stretchr/testify/require" @@ -53,7 +54,7 @@ func TestRedisCache(t *testing.T) { conn.Command("MGET", missIntf...).ExpectError(nil) // mock the cache - c := cache.NewRedisCache(cfg, "mock", pool) + c := cache.NewRedisCache(cfg, "mock", pool, log.NewNopLogger()) ctx := context.Background() c.Store(ctx, keys, bufs) diff --git a/pkg/chunk/cache/snappy.go b/pkg/chunk/cache/snappy.go index 2fc2308f484..d2ee606eda2 100644 --- a/pkg/chunk/cache/snappy.go +++ b/pkg/chunk/cache/snappy.go @@ -3,20 +3,21 @@ package cache import ( "context" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/golang/snappy" - - "github.com/cortexproject/cortex/pkg/util" ) type snappyCache struct { - next Cache + next Cache + logger log.Logger } // NewSnappy makes a new snappy encoding cache wrapper. -func NewSnappy(next Cache) Cache { +func NewSnappy(next Cache, logger log.Logger) Cache { return &snappyCache{ - next: next, + next: next, + logger: logger, } } @@ -35,7 +36,7 @@ func (s *snappyCache) Fetch(ctx context.Context, keys []string) ([]string, [][]b for _, buf := range bufs { d, err := snappy.Decode(nil, buf) if err != nil { - level.Error(util.Logger).Log("msg", "failed to decode cache entry", "err", err) + level.Error(s.logger).Log("msg", "failed to decode cache entry", "err", err) return nil, nil, keys } ds = append(ds, d) diff --git a/pkg/chunk/chunk_store_test.go b/pkg/chunk/chunk_store_test.go index 536869f63ad..09fb7846a7c 100644 --- a/pkg/chunk/chunk_store_test.go +++ b/pkg/chunk/chunk_store_test.go @@ -10,7 +10,9 @@ import ( "testing" "time" + "github.com/go-kit/kit/log" "github.com/pkg/errors" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/promql/parser" @@ -51,7 +53,7 @@ var stores = []struct { flagext.DefaultValues(&storeCfg) storeCfg.WriteDedupeCacheConfig.Cache = cache.NewFifoCache("test", cache.FifoCacheConfig{ MaxSizeItems: 500, - }) + }, prometheus.NewRegistry(), log.NewNopLogger()) return storeCfg }, }, @@ -91,9 +93,11 @@ func newTestChunkStoreConfigWithMockStorage(t require.TestingT, schemaCfg Schema overrides, err := validation.NewOverrides(limits, nil) require.NoError(t, err) - chunksCache, err := cache.New(storeCfg.ChunkCacheConfig) + reg := prometheus.NewRegistry() + logger := log.NewNopLogger() + chunksCache, err := cache.New(storeCfg.ChunkCacheConfig, reg, logger) require.NoError(t, err) - writeDedupeCache, err := cache.New(storeCfg.WriteDedupeCacheConfig) + writeDedupeCache, err := cache.New(storeCfg.WriteDedupeCacheConfig, reg, logger) require.NoError(t, err) store := NewCompositeStore(nil) @@ -1320,7 +1324,7 @@ func TestDisableIndexDeduplication(t *testing.T) { storeCfg := storeMaker.configFn() storeCfg.ChunkCacheConfig.Cache = cache.NewFifoCache("chunk-cache", cache.FifoCacheConfig{ MaxSizeItems: 5, - }) + }, prometheus.NewRegistry(), log.NewNopLogger()) storeCfg.DisableIndexDeduplication = disableIndexDeduplication store := newTestChunkStoreConfig(t, "v9", storeCfg) diff --git a/pkg/chunk/storage/caching_fixtures.go b/pkg/chunk/storage/caching_fixtures.go index ee032300b80..6c14f496285 100644 --- a/pkg/chunk/storage/caching_fixtures.go +++ b/pkg/chunk/storage/caching_fixtures.go @@ -1,9 +1,12 @@ package storage import ( - io "io" + "io" "time" + "github.com/go-kit/kit/log" + "github.com/prometheus/client_golang/prometheus" + "github.com/cortexproject/cortex/pkg/util/flagext" "github.com/cortexproject/cortex/pkg/util/validation" @@ -25,10 +28,12 @@ func (f fixture) Clients() (chunk.IndexClient, chunk.Client, chunk.TableClient, return nil, nil, nil, chunk.SchemaConfig{}, nil, err } indexClient, chunkClient, tableClient, schemaConfig, closer, err := f.fixture.Clients() + reg := prometheus.NewRegistry() + logger := log.NewNopLogger() indexClient = newCachingIndexClient(indexClient, cache.NewFifoCache("index-fifo", cache.FifoCacheConfig{ MaxSizeItems: 500, Validity: 5 * time.Minute, - }), 5*time.Minute, limits) + }, reg, logger), 5*time.Minute, limits, logger) return indexClient, chunkClient, tableClient, schemaConfig, closer, err } diff --git a/pkg/chunk/storage/caching_index_client.go b/pkg/chunk/storage/caching_index_client.go index cf9e37f1ca8..6408a5c5eab 100644 --- a/pkg/chunk/storage/caching_index_client.go +++ b/pkg/chunk/storage/caching_index_client.go @@ -5,6 +5,7 @@ import ( "sync" "time" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/gogo/protobuf/proto" "github.com/prometheus/client_golang/prometheus" @@ -14,7 +15,6 @@ import ( "github.com/cortexproject/cortex/pkg/chunk" "github.com/cortexproject/cortex/pkg/chunk/cache" chunk_util "github.com/cortexproject/cortex/pkg/chunk/util" - "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/spanlogger" ) @@ -46,18 +46,20 @@ type cachingIndexClient struct { cache cache.Cache validity time.Duration limits StoreLimits + logger log.Logger } -func newCachingIndexClient(client chunk.IndexClient, c cache.Cache, validity time.Duration, limits StoreLimits) chunk.IndexClient { +func newCachingIndexClient(client chunk.IndexClient, c cache.Cache, validity time.Duration, limits StoreLimits, logger log.Logger) chunk.IndexClient { if c == nil || cache.IsEmptyTieredCache(c) { return client } return &cachingIndexClient{ IndexClient: client, - cache: cache.NewSnappy(c), + cache: cache.NewSnappy(c, logger), validity: validity, limits: limits, + logger: logger, } } @@ -226,7 +228,7 @@ func (s *cachingIndexClient) cacheStore(ctx context.Context, keys []string, batc hashed = append(hashed, cache.HashKey(keys[i])) out, err := proto.Marshal(&batches[i]) if err != nil { - level.Warn(util.Logger).Log("msg", "error marshalling ReadBatch", "err", err) + level.Warn(s.logger).Log("msg", "error marshalling ReadBatch", "err", err) cacheEncodeErrs.Inc() return } diff --git a/pkg/chunk/storage/caching_index_client_test.go b/pkg/chunk/storage/caching_index_client_test.go index 3b01e0688d8..2bfc5176dc2 100644 --- a/pkg/chunk/storage/caching_index_client_test.go +++ b/pkg/chunk/storage/caching_index_client_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/go-kit/kit/log" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/weaveworks/common/user" @@ -40,8 +41,9 @@ func TestCachingStorageClientBasic(t *testing.T) { } limits, err := defaultLimits() require.NoError(t, err) - cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}) - client := newCachingIndexClient(store, cache, 1*time.Second, limits) + logger := log.NewNopLogger() + cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}, nil, logger) + client := newCachingIndexClient(store, cache, 1*time.Second, limits, logger) queries := []chunk.IndexQuery{{ TableName: "table", HashValue: "baz", @@ -71,8 +73,9 @@ func TestTempCachingStorageClient(t *testing.T) { } limits, err := defaultLimits() require.NoError(t, err) - cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}) - client := newCachingIndexClient(store, cache, 100*time.Millisecond, limits) + logger := log.NewNopLogger() + cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}, nil, logger) + client := newCachingIndexClient(store, cache, 100*time.Millisecond, limits, logger) queries := []chunk.IndexQuery{ {TableName: "table", HashValue: "foo"}, {TableName: "table", HashValue: "bar"}, @@ -129,8 +132,9 @@ func TestPermCachingStorageClient(t *testing.T) { } limits, err := defaultLimits() require.NoError(t, err) - cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}) - client := newCachingIndexClient(store, cache, 100*time.Millisecond, limits) + logger := log.NewNopLogger() + cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}, nil, logger) + client := newCachingIndexClient(store, cache, 100*time.Millisecond, limits, logger) queries := []chunk.IndexQuery{ {TableName: "table", HashValue: "foo", Immutable: true}, {TableName: "table", HashValue: "bar", Immutable: true}, @@ -180,8 +184,9 @@ func TestCachingStorageClientEmptyResponse(t *testing.T) { store := &mockStore{} limits, err := defaultLimits() require.NoError(t, err) - cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}) - client := newCachingIndexClient(store, cache, 1*time.Second, limits) + logger := log.NewNopLogger() + cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}, nil, logger) + client := newCachingIndexClient(store, cache, 1*time.Second, limits, logger) queries := []chunk.IndexQuery{{TableName: "table", HashValue: "foo"}} err = client.QueryPages(ctx, queries, func(query chunk.IndexQuery, batch chunk.ReadBatch) bool { assert.False(t, batch.Iterator().Next()) @@ -218,8 +223,9 @@ func TestCachingStorageClientCollision(t *testing.T) { } limits, err := defaultLimits() require.NoError(t, err) - cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}) - client := newCachingIndexClient(store, cache, 1*time.Second, limits) + logger := log.NewNopLogger() + cache := cache.NewFifoCache("test", cache.FifoCacheConfig{MaxSizeItems: 10, Validity: 10 * time.Second}, nil, logger) + client := newCachingIndexClient(store, cache, 1*time.Second, limits, logger) queries := []chunk.IndexQuery{ {TableName: "table", HashValue: "foo", RangeValuePrefix: []byte("bar")}, {TableName: "table", HashValue: "foo", RangeValuePrefix: []byte("baz")}, diff --git a/pkg/chunk/storage/factory.go b/pkg/chunk/storage/factory.go index 1629ead9247..d489a1997c8 100644 --- a/pkg/chunk/storage/factory.go +++ b/pkg/chunk/storage/factory.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -114,22 +115,30 @@ func (cfg *Config) Validate() error { } // NewStore makes the storage clients based on the configuration. -func NewStore(cfg Config, storeCfg chunk.StoreConfig, schemaCfg chunk.SchemaConfig, limits StoreLimits, reg prometheus.Registerer, cacheGenNumLoader chunk.CacheGenNumLoader) (chunk.Store, error) { +func NewStore( + cfg Config, + storeCfg chunk.StoreConfig, + schemaCfg chunk.SchemaConfig, + limits StoreLimits, + reg prometheus.Registerer, + cacheGenNumLoader chunk.CacheGenNumLoader, + logger log.Logger, +) (chunk.Store, error) { chunkMetrics := newChunkClientMetrics(reg) - indexReadCache, err := cache.New(cfg.IndexQueriesCacheConfig) + indexReadCache, err := cache.New(cfg.IndexQueriesCacheConfig, reg, logger) if err != nil { return nil, err } - writeDedupeCache, err := cache.New(storeCfg.WriteDedupeCacheConfig) + writeDedupeCache, err := cache.New(storeCfg.WriteDedupeCacheConfig, reg, logger) if err != nil { return nil, err } chunkCacheCfg := storeCfg.ChunkCacheConfig chunkCacheCfg.Prefix = "chunks" - chunksCache, err := cache.New(chunkCacheCfg) + chunksCache, err := cache.New(chunkCacheCfg, reg, logger) if err != nil { return nil, err } @@ -160,7 +169,7 @@ func NewStore(cfg Config, storeCfg chunk.StoreConfig, schemaCfg chunk.SchemaConf if err != nil { return nil, errors.Wrap(err, "error creating index client") } - index = newCachingIndexClient(index, indexReadCache, cfg.IndexCacheValidity, limits) + index = newCachingIndexClient(index, indexReadCache, cfg.IndexCacheValidity, limits, logger) objectStoreType := s.ObjectType if objectStoreType == "" { diff --git a/pkg/chunk/storage/factory_test.go b/pkg/chunk/storage/factory_test.go index e2b09c0e0a2..13141238cef 100644 --- a/pkg/chunk/storage/factory_test.go +++ b/pkg/chunk/storage/factory_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/prometheus/client_golang/prometheus" + "github.com/go-kit/kit/log" "github.com/prometheus/common/model" "github.com/stretchr/testify/require" @@ -42,7 +42,7 @@ func TestFactoryStop(t *testing.T) { limits, err := validation.NewOverrides(defaults, nil) require.NoError(t, err) - store, err := NewStore(cfg, storeConfig, schemaConfig, limits, nil, nil) + store, err := NewStore(cfg, storeConfig, schemaConfig, limits, nil, nil, log.NewNopLogger()) require.NoError(t, err) store.Stop() @@ -190,7 +190,7 @@ func TestCassandraInMultipleSchemas(t *testing.T) { limits, err := validation.NewOverrides(defaults, nil) require.NoError(t, err) - store, err := NewStore(cfg, storeConfig, schemaCfg, limits, prometheus.NewRegistry(), nil) + store, err := NewStore(cfg, storeConfig, schemaCfg, limits, nil, nil, log.NewNopLogger()) require.NoError(t, err) store.Stop() diff --git a/pkg/chunk/storage/index_client_test.go b/pkg/chunk/storage/index_client_test.go index 40514346a40..d83a8a8b666 100644 --- a/pkg/chunk/storage/index_client_test.go +++ b/pkg/chunk/storage/index_client_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/go-kit/kit/log" "github.com/stretchr/testify/require" "github.com/cortexproject/cortex/pkg/chunk" @@ -204,7 +205,7 @@ func TestCardinalityLimit(t *testing.T) { limits, err := defaultLimits() require.NoError(t, err) - client = newCachingIndexClient(client, cache.NewMockCache(), time.Minute, limits) + client = newCachingIndexClient(client, cache.NewMockCache(), time.Minute, limits, log.NewNopLogger()) batch := client.NewWriteBatch() for i := 0; i < 10; i++ { batch.Add(tableName, "bar", []byte(strconv.Itoa(i)), []byte(strconv.Itoa(i))) diff --git a/pkg/cortex/modules.go b/pkg/cortex/modules.go index 25f03ae5e51..49b17498eb6 100644 --- a/pkg/cortex/modules.go +++ b/pkg/cortex/modules.go @@ -316,7 +316,7 @@ func (t *Cortex) initChunkStore() (serv services.Service, err error) { return } - t.Store, err = storage.NewStore(t.Cfg.Storage, t.Cfg.ChunkStore, t.Cfg.Schema, t.Overrides, prometheus.DefaultRegisterer, t.TombstonesLoader) + t.Store, err = storage.NewStore(t.Cfg.Storage, t.Cfg.ChunkStore, t.Cfg.Schema, t.Overrides, prometheus.DefaultRegisterer, t.TombstonesLoader, util.Logger) if err != nil { return } diff --git a/pkg/querier/queryrange/results_cache.go b/pkg/querier/queryrange/results_cache.go index d766c7b5509..30440d0b910 100644 --- a/pkg/querier/queryrange/results_cache.go +++ b/pkg/querier/queryrange/results_cache.go @@ -14,6 +14,7 @@ import ( "github.com/gogo/protobuf/types" "github.com/opentracing/opentracing-go" otlog "github.com/opentracing/opentracing-go/log" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" "github.com/uber/jaeger-client-go" "github.com/weaveworks/common/httpgrpc" @@ -128,8 +129,9 @@ func NewResultsCacheMiddleware( merger Merger, extractor Extractor, cacheGenNumberLoader CacheGenNumberLoader, + reg prometheus.Registerer, ) (Middleware, cache.Cache, error) { - c, err := cache.New(cfg.CacheConfig) + c, err := cache.New(cfg.CacheConfig, reg, logger) if err != nil { return nil, nil, err } diff --git a/pkg/querier/queryrange/results_cache_test.go b/pkg/querier/queryrange/results_cache_test.go index 0121e3ea3c4..c07eeb7b1b5 100644 --- a/pkg/querier/queryrange/results_cache_test.go +++ b/pkg/querier/queryrange/results_cache_test.go @@ -379,6 +379,7 @@ func TestResultsCache(t *testing.T) { PrometheusCodec, PrometheusResponseExtractor{}, nil, + nil, ) require.NoError(t, err) @@ -409,7 +410,16 @@ func TestResultsCacheRecent(t *testing.T) { var cfg ResultsCacheConfig flagext.DefaultValues(&cfg) cfg.CacheConfig.Cache = cache.NewMockCache() - rcm, _, err := NewResultsCacheMiddleware(log.NewNopLogger(), cfg, constSplitter(day), fakeLimitsHighMaxCacheFreshness{}, PrometheusCodec, PrometheusResponseExtractor{}, nil) + rcm, _, err := NewResultsCacheMiddleware( + log.NewNopLogger(), + cfg, + constSplitter(day), + fakeLimitsHighMaxCacheFreshness{}, + PrometheusCodec, + PrometheusResponseExtractor{}, + nil, + nil, + ) require.NoError(t, err) req := parsedRequest.WithStartEnd(int64(model.Now())-(60*1e3), int64(model.Now())) @@ -476,6 +486,7 @@ func TestResultsCacheMaxFreshness(t *testing.T) { PrometheusCodec, PrometheusResponseExtractor{}, nil, + nil, ) require.NoError(t, err) @@ -511,6 +522,7 @@ func Test_resultsCache_MissingData(t *testing.T) { PrometheusCodec, PrometheusResponseExtractor{}, nil, + nil, ) require.NoError(t, err) rc := rm.Wrap(nil).(*resultsCache) diff --git a/pkg/querier/queryrange/roundtrip.go b/pkg/querier/queryrange/roundtrip.go index dac7de72ccc..66c06117bce 100644 --- a/pkg/querier/queryrange/roundtrip.go +++ b/pkg/querier/queryrange/roundtrip.go @@ -159,7 +159,7 @@ func NewTripperware( var c cache.Cache if cfg.CacheResults { - queryCacheMiddleware, cache, err := NewResultsCacheMiddleware(log, cfg.ResultsCacheConfig, constSplitter(cfg.SplitQueriesByInterval), limits, codec, cacheExtractor, cacheGenNumberLoader) + queryCacheMiddleware, cache, err := NewResultsCacheMiddleware(log, cfg.ResultsCacheConfig, constSplitter(cfg.SplitQueriesByInterval), limits, codec, cacheExtractor, cacheGenNumberLoader, registerer) if err != nil { return nil, nil, err }