Skip to content

Commit 3b0fb0c

Browse files
committed
Add a configuration for an index cache ttl
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
1 parent cccfd73 commit 3b0fb0c

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
@@ -6,6 +6,7 @@
66
* [CHANGE] Enable Compactor and Alertmanager in target all. #6204
77
* [FEATURE] Ruler: Experimental: Add `ruler.frontend-address` to allow query to query frontends instead of ingesters. #6151
88
* [FEATURE] Ruler: Minimize chances of missed rule group evaluations that can occur due to OOM kills, bad underlying nodes, or due to an unhealthy ruler that appears in the ring as healthy. This feature is enabled via `-ruler.enable-ha-evaluation` flag. #6129
9+
* [ENHANCEMENT] Index Cache: Add a configuration for an index cache ttl. #6234
910
* [ENHANCEMENT] Ingester: Add `blocks-storage.tsdb.wal-compression-type` to support zstd wal compression type. #6232
1011
* [ENHANCEMENT] Query Frontend: Add info field to query response. #6207
1112
* [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
@@ -642,6 +642,10 @@ blocks_storage:
642642
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items
643643
[enabled_items: <list of string> | default = []]
644644

645+
# How long to cache an index for a block.
646+
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl
647+
[index_ttl: <duration> | default = 24h]
648+
645649
redis:
646650
# Comma separated list of redis addresses. Supported prefixes are: dns+
647651
# (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query,
@@ -772,6 +776,10 @@ blocks_storage:
772776
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items
773777
[enabled_items: <list of string> | default = []]
774778

779+
# How long to cache an index for a block.
780+
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl
781+
[index_ttl: <duration> | default = 24h]
782+
775783
multilevel:
776784
# The maximum number of concurrent asynchronous operations can occur
777785
# 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)