Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a configuration for an index cache ttl #6234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [FEATURE] Store Gateway: Add an in-memory chunk cache. #6245
* [FEATURE] Chunk Cache: Support multi level cache and add metrics. #6249
* [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
* [ENHANCEMENT] Index Cache: Add a configuration for an index cache ttl. #6234
* [ENHANCEMENT] Ingester: Add `blocks-storage.tsdb.wal-compression-type` to support zstd wal compression type. #6232
* [ENHANCEMENT] Query Frontend: Add info field to query response. #6207
* [ENHANCEMENT] Query Frontend: Add peakSample in query stats response. #6188
Expand Down
8 changes: 8 additions & 0 deletions docs/blocks-storage/querier.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ blocks_storage:
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items
[enabled_items: <list of string> | default = []]

# How long to cache an index for a block.
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl
[index_ttl: <duration> | 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,
Expand Down Expand Up @@ -796,6 +800,10 @@ blocks_storage:
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items
[enabled_items: <list of string> | default = []]

# How long to cache an index for a block.
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl
[index_ttl: <duration> | default = 24h]

multilevel:
# The maximum number of concurrent asynchronous operations can occur
# when backfilling cache items.
Expand Down
8 changes: 8 additions & 0 deletions docs/blocks-storage/store-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ blocks_storage:
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items
[enabled_items: <list of string> | default = []]

# How long to cache an index for a block.
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl
[index_ttl: <duration> | 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,
Expand Down Expand Up @@ -887,6 +891,10 @@ blocks_storage:
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items
[enabled_items: <list of string> | default = []]

# How long to cache an index for a block.
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl
[index_ttl: <duration> | default = 24h]

multilevel:
# The maximum number of concurrent asynchronous operations can occur
# when backfilling cache items.
Expand Down
8 changes: 8 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ bucket_store:
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.enabled-items
[enabled_items: <list of string> | default = []]

# How long to cache an index for a block.
# CLI flag: -blocks-storage.bucket-store.index-cache.memcached.index-ttl
[index_ttl: <duration> | 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,
Expand Down Expand Up @@ -1323,6 +1327,10 @@ bucket_store:
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.enabled-items
[enabled_items: <list of string> | default = []]

# How long to cache an index for a block.
# CLI flag: -blocks-storage.bucket-store.index-cache.redis.index-ttl
[index_ttl: <duration> | default = 24h]

multilevel:
# The maximum number of concurrent asynchronous operations can occur when
# backfilling cache items.
Expand Down
10 changes: 6 additions & 4 deletions pkg/storage/tsdb/index_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
Loading