Skip to content

Commit 27b73a1

Browse files
committed
Add a configuration for an index cache ttl
Signed-off-by: SungJin1212 <[email protected]>
1 parent 3b5011b commit 27b73a1

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [FEATURE] Store Gateway: Add an in-memory chunk cache. #6245
1111
* [FEATURE] Chunk Cache: Support multi level cache and add metrics. #6249
1212
* [ENHANCEMENT] Query Frontend: Add new query stats metrics `cortex_query_samples_scanned_total` and `cortex_query_peak_samples` to track scannedSamples and peakSample per user. #6228
13+
* [ENHANCEMENT] Index Cache: Add a configuration for an index cache ttl. #6234
1314
* [ENHANCEMENT] Ingester: Add `blocks-storage.tsdb.wal-compression-type` to support zstd wal compression type. #6232
1415
* [ENHANCEMENT] Query Frontend: Add info field to query response. #6207
1516
* [ENHANCEMENT] Query Frontend: Add peakSample in query stats response. #6188

docs/blocks-storage/querier.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ blocks_storage:
666666
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items
667667
[enabled_items: <list of string> | default = []]
668668

669+
# How long to cache an index for a block.
670+
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl
671+
[index_ttl: <duration> | default = 24h]
672+
669673
redis:
670674
# Comma separated list of redis addresses. Supported prefixes are: dns+
671675
# (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query,
@@ -796,6 +800,10 @@ blocks_storage:
796800
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items
797801
[enabled_items: <list of string> | default = []]
798802

803+
# How long to cache an index for a block.
804+
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl
805+
[index_ttl: <duration> | default = 24h]
806+
799807
multilevel:
800808
# The maximum number of concurrent asynchronous operations can occur
801809
# when backfilling cache items.

docs/blocks-storage/store-gateway.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,10 @@ blocks_storage:
757757
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items
758758
[enabled_items: <list of string> | default = []]
759759

760+
# How long to cache an index for a block.
761+
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl
762+
[index_ttl: <duration> | default = 24h]
763+
760764
redis:
761765
# Comma separated list of redis addresses. Supported prefixes are: dns+
762766
# (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query,
@@ -887,6 +891,10 @@ blocks_storage:
887891
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items
888892
[enabled_items: <list of string> | default = []]
889893

894+
# How long to cache an index for a block.
895+
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl
896+
[index_ttl: <duration> | default = 24h]
897+
890898
multilevel:
891899
# The maximum number of concurrent asynchronous operations can occur
892900
# when backfilling cache items.

docs/configuration/config-file-reference.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,10 @@ bucket_store:
11941194
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items
11951195
[enabled_items: <list of string> | default = []]
11961196

1197+
# How long to cache an index for a block.
1198+
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl
1199+
[index_ttl: <duration> | default = 24h]
1200+
11971201
redis:
11981202
# Comma separated list of redis addresses. Supported prefixes are: dns+
11991203
# (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query,
@@ -1323,6 +1327,10 @@ bucket_store:
13231327
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items
13241328
[enabled_items: <list of string> | default = []]
13251329

1330+
# How long to cache an index for a block.
1331+
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl
1332+
[index_ttl: <duration> | default = 24h]
1333+
13261334
multilevel:
13271335
# The maximum number of concurrent asynchronous operations can occur when
13281336
# backfilling cache items.

pkg/storage/tsdb/index_cache.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (cfg *InMemoryIndexCacheConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, pr
157157
type MemcachedIndexCacheConfig struct {
158158
ClientConfig MemcachedClientConfig `yaml:",inline"`
159159
EnabledItems []string `yaml:"enabled_items"`
160+
IndexTTL time.Duration `yaml:"index_ttl"`
160161
}
161162

162163
func (cfg *MemcachedIndexCacheConfig) Validate() error {
@@ -169,16 +170,19 @@ func (cfg *MemcachedIndexCacheConfig) Validate() error {
169170
func (cfg *MemcachedIndexCacheConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) {
170171
cfg.ClientConfig.RegisterFlagsWithPrefix(f, prefix)
171172
f.Var((*flagext.StringSlice)(&cfg.EnabledItems), prefix+"enabled-items", "Selectively cache index item types. Supported values are Postings, ExpandedPostings and Series")
173+
f.DurationVar(&cfg.IndexTTL, prefix+"index-ttl", defaultTTL, "How long to cache an index for a block.")
172174
}
173175

174176
type RedisIndexCacheConfig struct {
175177
ClientConfig RedisClientConfig `yaml:",inline"`
176178
EnabledItems []string `yaml:"enabled_items"`
179+
IndexTTL time.Duration `yaml:"index_ttl"`
177180
}
178181

179182
func (cfg *RedisIndexCacheConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) {
180183
cfg.ClientConfig.RegisterFlagsWithPrefix(f, prefix)
181184
f.Var((*flagext.StringSlice)(&cfg.EnabledItems), prefix+"enabled-items", "Selectively cache index item types. Supported values are Postings, ExpandedPostings and Series")
185+
f.DurationVar(&cfg.IndexTTL, prefix+"index-ttl", defaultTTL, "How long to cache an index for a block.")
182186
}
183187

184188
func (cfg *RedisIndexCacheConfig) Validate() error {
@@ -217,8 +221,7 @@ func NewIndexCache(cfg IndexCacheConfig, logger log.Logger, registerer prometheu
217221
if err != nil {
218222
return nil, err
219223
}
220-
// TODO(yeya24): expose TTL
221-
cache, err := storecache.NewRemoteIndexCache(logger, c, nil, iReg, defaultTTL)
224+
cache, err := storecache.NewRemoteIndexCache(logger, c, nil, iReg, cfg.Memcached.IndexTTL)
222225
if err != nil {
223226
return nil, err
224227
}
@@ -229,8 +232,7 @@ func NewIndexCache(cfg IndexCacheConfig, logger log.Logger, registerer prometheu
229232
if err != nil {
230233
return nil, err
231234
}
232-
// TODO(yeya24): expose TTL
233-
cache, err := storecache.NewRemoteIndexCache(logger, c, nil, iReg, defaultTTL)
235+
cache, err := storecache.NewRemoteIndexCache(logger, c, nil, iReg, cfg.Redis.IndexTTL)
234236
if err != nil {
235237
return nil, err
236238
}

0 commit comments

Comments
 (0)