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

Allow use of Redis for all caches #4371

Merged
merged 5 commits into from
Mar 7, 2023
Merged

Conversation

56quarters
Copy link
Contributor

@56quarters 56quarters commented Mar 3, 2023

What this PR does

This change pulls in a version of dskit that supports using Redis implementations for the cache.Cache and cache.RemoteCacheClient interfaces. The query-frontend caching integration test now runs with both Memcached and Redis caches. Redis can also be enabled for the microservices docker compose environment.

Which issue(s) this PR fixes or relates to

See #4236
Fixes #4341

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@56quarters 56quarters force-pushed the 56quarters/enable-redis-support branch 2 times, most recently from ea0aa80 to 8e15750 Compare March 3, 2023 20:03
@56quarters
Copy link
Contributor Author

Note that I am purposefully not including updates to the Jsonnet or Helm chart as part of these changes (there's enough to review as-is).

@56quarters 56quarters marked this pull request as ready for review March 3, 2023 21:28
@56quarters 56quarters requested review from a team as code owners March 3, 2023 21:28
cmd/mimir/help.txt.tmpl Outdated Show resolved Hide resolved
@@ -119,3 +125,17 @@ func newMemcachedIndexCache(cfg cache.MemcachedConfig, logger log.Logger, regist

return indexcache.NewTracingIndexCache(c, logger), nil
}

func newRedisIndexCache(cfg cache.RedisClientConfig, logger log.Logger, registerer prometheus.Registerer) (indexcache.IndexCache, error) {
client, err := cache.NewRedisClient(logger, "index-cache", cfg, prometheus.WrapRegistererWithPrefix("thanos_", registerer))
Copy link
Contributor

@lamida lamida Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a discussion to deprecate thanos_ metrics prefix. Should we just use cortex_ prefix for the new change in this PR? Applicable also for memcached client metrics prefix few lines above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather make the change to all cache metrics at the same time. It's the same amount of work if we support cortex_ for Redis metrics and thanos_ for Memcached vs using thanos_ for both now and cortex_ for both later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific, using thanos_ here now means Redis will work with our dashboards as currently written with no extra effort. Then, they can be migrated to use the cortex_ prefix at the same time as the Memcached backend also with no extra effort.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Nick. I think for now we should just aim for consistency (unfortunately...).

Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good job, LGTM! I just left a couple of comments I would be glad if you could look at before merging. I would love to merge this PR asap, cause I want to add metadata cache support to compactor and I would love to do it on top of this. Thanks!

- Query-scheduler
- `-query-scheduler.querier-forget-delay`
- Max number of used instances (`-query-scheduler.max-used-instances`)
- Store-gateway
- `-blocks-storage.bucket-store.chunks-cache.fine-grained-chunks-caching-enabled`
- Use of Redis cache backend (`-blocks-storage.bucket-store.chunks-cache.backend=redis`, `-blocks-storage.bucket-store.index-cache.backend=redis`, `-blocks-storage.bucket-store.metadata-cache.backend=redis`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The metadata cache is used also by the querier.

cfg.Memcached.RegisterFlagsWithPrefix(f, prefix+"memcached.")
cfg.InMemory.RegisterFlagsWithPrefix(prefix+"inmemory.", f)
cfg.Memcached.RegisterFlagsWithPrefix(prefix+"memcached.", f)
cfg.Redis.RegisterFlagsWithPrefix(prefix+"redis.", f)
}

// Validate the config.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the IndexCacheConfig.Validate() below to run the validation on BackendConfig.Validate() instead of just BackendConfig.Memcached.Validate(), please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh, will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing the errors here so I can write a test against the validation method: grafana/dskit#276

@@ -119,3 +125,17 @@ func newMemcachedIndexCache(cfg cache.MemcachedConfig, logger log.Logger, regist

return indexcache.NewTracingIndexCache(c, logger), nil
}

func newRedisIndexCache(cfg cache.RedisClientConfig, logger log.Logger, registerer prometheus.Registerer) (indexcache.IndexCache, error) {
client, err := cache.NewRedisClient(logger, "index-cache", cfg, prometheus.WrapRegistererWithPrefix("thanos_", registerer))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Nick. I think for now we should just aim for consistency (unfortunately...).

56quarters added a commit to grafana/dskit that referenced this pull request Mar 7, 2023
See grafana/mimir#4371

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
56quarters added a commit to grafana/dskit that referenced this pull request Mar 7, 2023
…276)

* Export Redis config validation errors so they can be tested against

See grafana/mimir#4371

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
Copy link
Collaborator

@pracucci pracucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

This change pulls in a version of dskit that supports using Redis
implementations for the `cache.Cache` and `cache.RemoteCacheClient`
interfaces. The query-frontend caching integration test now runs
with both Memcached and Redis caches. Redis can also be enabled
for the microservices docker compose environment.

See #4236
Fixes #4341

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
@56quarters 56quarters force-pushed the 56quarters/enable-redis-support branch from ba50778 to 07eff10 Compare March 7, 2023 17:35
Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
@56quarters 56quarters merged commit 607d7dc into main Mar 7, 2023
@56quarters 56quarters deleted the 56quarters/enable-redis-support branch March 7, 2023 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Async cache writes use request scoped context which gets cancelled
4 participants