Skip to content

Commit f2b7591

Browse files
authored
Fix redis cache client metrics registration error (#5751)
* fix redis cache registration error Signed-off-by: Ben Ye <[email protected]> * integration tests for having both index and chunks cache Signed-off-by: Ben Ye <[email protected]> * update tests Signed-off-by: Ben Ye <[email protected]> * fix lint Signed-off-by: Ben Ye <[email protected]> --------- Signed-off-by: Ben Ye <[email protected]>
1 parent 8ef6813 commit f2b7591

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

integration/querier_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,32 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
3131
tenantShardSize int
3232
ingesterStreamingEnabled bool
3333
indexCacheBackend string
34+
chunkCacheBackend string
3435
bucketIndexEnabled bool
3536
}{
3637
"blocks sharding disabled, ingester gRPC streaming disabled, memcached index cache": {
3738
blocksShardingStrategy: "",
3839
ingesterStreamingEnabled: false,
3940
indexCacheBackend: tsdb.IndexCacheBackendMemcached,
41+
chunkCacheBackend: tsdb.CacheBackendMemcached,
4042
},
4143
"blocks sharding disabled, ingester gRPC streaming disabled, multilevel index cache (inmemory, memcached)": {
4244
blocksShardingStrategy: "",
4345
ingesterStreamingEnabled: false,
4446
indexCacheBackend: fmt.Sprintf("%v,%v", tsdb.IndexCacheBackendInMemory, tsdb.IndexCacheBackendMemcached),
47+
chunkCacheBackend: tsdb.CacheBackendMemcached,
4548
},
4649
"blocks sharding disabled, ingester gRPC streaming disabled, redis index cache": {
4750
blocksShardingStrategy: "",
4851
ingesterStreamingEnabled: false,
4952
indexCacheBackend: tsdb.IndexCacheBackendRedis,
53+
chunkCacheBackend: tsdb.CacheBackendRedis,
5054
},
5155
"blocks sharding disabled, ingester gRPC streaming disabled, multilevel index cache (inmemory, redis)": {
5256
blocksShardingStrategy: "",
5357
ingesterStreamingEnabled: false,
5458
indexCacheBackend: fmt.Sprintf("%v,%v", tsdb.IndexCacheBackendInMemory, tsdb.IndexCacheBackendRedis),
59+
chunkCacheBackend: tsdb.CacheBackendRedis,
5560
},
5661
"blocks default sharding, ingester gRPC streaming disabled, inmemory index cache": {
5762
blocksShardingStrategy: "default",
@@ -67,12 +72,14 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
6772
blocksShardingStrategy: "default",
6873
ingesterStreamingEnabled: true,
6974
indexCacheBackend: tsdb.IndexCacheBackendMemcached,
75+
chunkCacheBackend: tsdb.CacheBackendMemcached,
7076
},
7177
"blocks shuffle sharding, ingester gRPC streaming enabled, memcached index cache": {
7278
blocksShardingStrategy: "shuffle-sharding",
7379
tenantShardSize: 1,
7480
ingesterStreamingEnabled: true,
7581
indexCacheBackend: tsdb.IndexCacheBackendMemcached,
82+
chunkCacheBackend: tsdb.CacheBackendMemcached,
7683
},
7784
"blocks default sharding, ingester gRPC streaming enabled, inmemory index cache, bucket index enabled": {
7885
blocksShardingStrategy: "default",
@@ -91,13 +98,15 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
9198
blocksShardingStrategy: "default",
9299
ingesterStreamingEnabled: true,
93100
indexCacheBackend: tsdb.IndexCacheBackendRedis,
101+
chunkCacheBackend: tsdb.CacheBackendRedis,
94102
bucketIndexEnabled: true,
95103
},
96104
"blocks shuffle sharding, ingester gRPC streaming enabled, redis index cache, bucket index enabled": {
97105
blocksShardingStrategy: "shuffle-sharding",
98106
tenantShardSize: 1,
99107
ingesterStreamingEnabled: true,
100108
indexCacheBackend: tsdb.IndexCacheBackendRedis,
109+
chunkCacheBackend: tsdb.CacheBackendRedis,
101110
bucketIndexEnabled: true,
102111
},
103112
}
@@ -121,6 +130,7 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
121130
"-blocks-storage.bucket-store.sync-interval": "1s",
122131
"-blocks-storage.tsdb.retention-period": ((blockRangePeriod * 2) - 1).String(),
123132
"-blocks-storage.bucket-store.index-cache.backend": testCfg.indexCacheBackend,
133+
"-blocks-storage.bucket-store.chunks-cache.backend": testCfg.chunkCacheBackend,
124134
"-store-gateway.sharding-enabled": strconv.FormatBool(testCfg.blocksShardingStrategy != ""),
125135
"-store-gateway.sharding-strategy": testCfg.blocksShardingStrategy,
126136
"-store-gateway.tenant-shard-size": fmt.Sprintf("%d", testCfg.tenantShardSize),
@@ -144,6 +154,11 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
144154
if strings.Contains(testCfg.indexCacheBackend, tsdb.IndexCacheBackendRedis) {
145155
flags["-blocks-storage.bucket-store.index-cache.redis.addresses"] = redis.NetworkEndpoint(e2ecache.RedisPort)
146156
}
157+
if testCfg.chunkCacheBackend == tsdb.CacheBackendMemcached {
158+
flags["-blocks-storage.bucket-store.chunks-cache.memcached.addresses"] = "dns+" + memcached.NetworkEndpoint(e2ecache.MemcachedPort)
159+
} else if testCfg.chunkCacheBackend == tsdb.CacheBackendRedis {
160+
flags["-blocks-storage.bucket-store.chunks-cache.redis.addresses"] = redis.NetworkEndpoint(e2ecache.RedisPort)
161+
}
147162

148163
// Start Cortex components.
149164
distributor := e2ecortex.NewDistributor("distributor", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), flags, "")
@@ -257,17 +272,12 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
257272
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(float64((5+5+2)*numberOfCacheBackends)), "thanos_store_index_cache_requests_total"))
258273
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(0), "thanos_store_index_cache_hits_total")) // no cache hit cause the cache was empty
259274

260-
if testCfg.indexCacheBackend == tsdb.IndexCacheBackendMemcached {
261-
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(21), "thanos_memcached_operations_total")) // 14 gets + 7 sets
262-
}
263-
264275
// Query back again the 1st series from storage. This time it should use the index cache.
265276
result, err = c.Query("series_1", series1Timestamp)
266277
require.NoError(t, err)
267278
require.Equal(t, model.ValVector, result.Type())
268279
assert.Equal(t, expectedVector1, result.(model.Vector))
269280

270-
var l0CacheHits float64
271281
if numberOfCacheBackends > 1 {
272282
// 6 requests for Expanded Postings, 5 for Postings and 3 for Series.
273283
require.NoError(t, storeGateways.WaitSumMetricsWithOptions(e2e.Equals(float64(6+5+3)), []string{"thanos_store_index_cache_requests_total"}, e2e.WithLabelMatchers(
@@ -287,17 +297,12 @@ func TestQuerierWithBlocksStorageRunningInMicroservicesMode(t *testing.T) {
287297
require.NoError(t, err)
288298
// Make sure l1 cache requests + l0 cache hits is 14.
289299
require.Equal(t, float64(14), l1IndexCacheRequests[0]+l0IndexCacheHits[0])
290-
l0CacheHits = l0IndexCacheHits[0]
291300
} else {
292301
// 6 requests for Expanded Postings, 5 for Postings and 3 for Series.
293302
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(float64(6+5+3)), "thanos_store_index_cache_requests_total"))
294303
}
295304
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(2), "thanos_store_index_cache_hits_total")) // this time has used the index cache
296305

297-
if testCfg.indexCacheBackend == tsdb.IndexCacheBackendMemcached {
298-
require.NoError(t, storeGateways.WaitSumMetrics(e2e.Equals(23-l0CacheHits), "thanos_memcached_operations_total")) // as before + 2 gets - cache hits
299-
}
300-
301306
// Query metadata.
302307
testMetadataQueriesWithBlocksStorage(t, c, series1[0], series2[0], series3[0], blockRangePeriod)
303308

pkg/storage/tsdb/index_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func NewIndexCache(cfg IndexCacheConfig, logger log.Logger, registerer prometheu
225225
caches = append(caches, cache)
226226
enabledItems = append(enabledItems, cfg.Memcached.EnabledItems)
227227
case IndexCacheBackendRedis:
228-
c, err := newRedisIndexCacheClient(cfg.Redis.ClientConfig, logger, iReg)
228+
c, err := newRedisIndexCacheClient(cfg.Redis.ClientConfig, logger, registerer)
229229
if err != nil {
230230
return nil, err
231231
}

0 commit comments

Comments
 (0)