From b43ddd9313569ef3bcfdc5d013a97918bbb3bbd9 Mon Sep 17 00:00:00 2001 From: SungJin1212 Date: Wed, 25 Sep 2024 16:37:06 +0900 Subject: [PATCH] Add a configuration for an index cache ttl Signed-off-by: SungJin1212 --- CHANGELOG.md | 1 + docs/blocks-storage/querier.md | 8 ++++++++ docs/blocks-storage/store-gateway.md | 8 ++++++++ docs/configuration/config-file-reference.md | 8 ++++++++ pkg/storage/tsdb/index_cache.go | 10 ++++++---- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c692798ac..f69f050237 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [CHANGE] Enable Compactor and Alertmanager in target all. #6204 * [FEATURE] Ruler: Experimental: Add `ruler.frontend-address` to allow query to query frontends instead of ingesters. #6151 * [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 +* [ENHANCEMENT] Index Cache: Add a configuration for an index cache ttl. #6234 * [ENHANCEMENT] Query Frontend: Add info field to query response. #6207 * [ENHANCEMENT] Query Frontend: Add peakSample in query stats response. #6188 * [ENHANCEMENT] Ruler: Add new ruler metric `cortex_ruler_rule_groups_in_store` that is the total rule groups per tenant in store, which can be used to compare with `cortex_prometheus_rule_group_rules` to count the number of rule groups that are not loaded by a ruler. #5869 diff --git a/docs/blocks-storage/querier.md b/docs/blocks-storage/querier.md index 7fdfaf89a4..c9fe619e76 100644 --- a/docs/blocks-storage/querier.md +++ b/docs/blocks-storage/querier.md @@ -642,6 +642,10 @@ blocks_storage: # CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items [enabled_items: | default = []] + # How long to cache an index for a block. + # CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl + [index_ttl: | default = 24h] + redis: # Comma separated list of redis addresses. Supported prefixes are: dns+ # (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query, @@ -772,6 +776,10 @@ blocks_storage: # CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items [enabled_items: | default = []] + # How long to cache an index for a block. + # CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl + [index_ttl: | default = 24h] + multilevel: # The maximum number of concurrent asynchronous operations can occur # when backfilling cache items. diff --git a/docs/blocks-storage/store-gateway.md b/docs/blocks-storage/store-gateway.md index 6c31046b1f..64dc508e39 100644 --- a/docs/blocks-storage/store-gateway.md +++ b/docs/blocks-storage/store-gateway.md @@ -757,6 +757,10 @@ blocks_storage: # CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items [enabled_items: | default = []] + # How long to cache an index for a block. + # CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl + [index_ttl: | default = 24h] + redis: # Comma separated list of redis addresses. Supported prefixes are: dns+ # (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query, @@ -887,6 +891,10 @@ blocks_storage: # CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items [enabled_items: | default = []] + # How long to cache an index for a block. + # CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl + [index_ttl: | default = 24h] + multilevel: # The maximum number of concurrent asynchronous operations can occur # when backfilling cache items. diff --git a/docs/configuration/config-file-reference.md b/docs/configuration/config-file-reference.md index 58c3fdec63..78ec5abd28 100644 --- a/docs/configuration/config-file-reference.md +++ b/docs/configuration/config-file-reference.md @@ -1194,6 +1194,10 @@ bucket_store: # CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items [enabled_items: | default = []] + # How long to cache an index for a block. + # CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl + [index_ttl: | default = 24h] + redis: # Comma separated list of redis addresses. Supported prefixes are: dns+ # (looked up as an A/AAAA query), dnssrv+ (looked up as a SRV query, @@ -1323,6 +1327,10 @@ bucket_store: # CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items [enabled_items: | default = []] + # How long to cache an index for a block. + # CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl + [index_ttl: | default = 24h] + multilevel: # The maximum number of concurrent asynchronous operations can occur when # backfilling cache items. diff --git a/pkg/storage/tsdb/index_cache.go b/pkg/storage/tsdb/index_cache.go index 24dcd09411..69c6272c81 100644 --- a/pkg/storage/tsdb/index_cache.go +++ b/pkg/storage/tsdb/index_cache.go @@ -157,6 +157,7 @@ func (cfg *InMemoryIndexCacheConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, pr type MemcachedIndexCacheConfig struct { ClientConfig MemcachedClientConfig `yaml:",inline"` EnabledItems []string `yaml:"enabled_items"` + IndexTTL time.Duration `yaml:"index_ttl"` } func (cfg *MemcachedIndexCacheConfig) Validate() error { @@ -169,16 +170,19 @@ func (cfg *MemcachedIndexCacheConfig) Validate() error { func (cfg *MemcachedIndexCacheConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) { cfg.ClientConfig.RegisterFlagsWithPrefix(f, prefix) f.Var((*flagext.StringSlice)(&cfg.EnabledItems), prefix+"enabled-items", "Selectively cache index item types. Supported values are Postings, ExpandedPostings and Series") + f.DurationVar(&cfg.IndexTTL, prefix+"index-ttl", defaultTTL, "How long to cache an index for a block.") } type RedisIndexCacheConfig struct { ClientConfig RedisClientConfig `yaml:",inline"` EnabledItems []string `yaml:"enabled_items"` + IndexTTL time.Duration `yaml:"index_ttl"` } func (cfg *RedisIndexCacheConfig) RegisterFlagsWithPrefix(f *flag.FlagSet, prefix string) { cfg.ClientConfig.RegisterFlagsWithPrefix(f, prefix) f.Var((*flagext.StringSlice)(&cfg.EnabledItems), prefix+"enabled-items", "Selectively cache index item types. Supported values are Postings, ExpandedPostings and Series") + f.DurationVar(&cfg.IndexTTL, prefix+"index-ttl", defaultTTL, "How long to cache an index for a block.") } func (cfg *RedisIndexCacheConfig) Validate() error { @@ -217,8 +221,7 @@ func NewIndexCache(cfg IndexCacheConfig, logger log.Logger, registerer prometheu if err != nil { return nil, err } - // TODO(yeya24): expose TTL - cache, err := storecache.NewRemoteIndexCache(logger, c, nil, iReg, defaultTTL) + cache, err := storecache.NewRemoteIndexCache(logger, c, nil, iReg, cfg.Memcached.IndexTTL) if err != nil { return nil, err } @@ -229,8 +232,7 @@ func NewIndexCache(cfg IndexCacheConfig, logger log.Logger, registerer prometheu if err != nil { return nil, err } - // TODO(yeya24): expose TTL - cache, err := storecache.NewRemoteIndexCache(logger, c, nil, iReg, defaultTTL) + cache, err := storecache.NewRemoteIndexCache(logger, c, nil, iReg, cfg.Redis.IndexTTL) if err != nil { return nil, err }