Skip to content

Commit b8e1dbd

Browse files
authored
Add redis as index cache and caching bucket backend (#5057)
* add redis as index cache and caching bucket backend Signed-off-by: Ben Ye <[email protected]> * add e2e test for redis index cache Signed-off-by: Ben Ye <[email protected]> * fix lint and integration test Signed-off-by: Ben Ye <[email protected]> * fix redis address Signed-off-by: Ben Ye <[email protected]> * update doc Signed-off-by: Ben Ye <[email protected]> * use cache backend to create cache Signed-off-by: Ben Ye <[email protected]> * update store gateway docs Signed-off-by: Ben Ye <[email protected]> --------- Signed-off-by: Ben Ye <[email protected]>
1 parent 2f19a1c commit b8e1dbd

File tree

14 files changed

+1296
-53
lines changed

14 files changed

+1296
-53
lines changed

.github/workflows/test-build-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ jobs:
140140
docker pull quay.io/cortexproject/cortex:v1.14.0
141141
fi
142142
docker pull memcached:1.6.1
143+
docker pull redis:7.0.4-alpine
143144
env:
144145
TEST_TAGS: ${{ matrix.tags }}
145146
- name: Integration Tests

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [FEATURE] Querier/Ruler: Support the new thanos promql engine. This is an experimental feature and might change in the future. #5093
3030
* [FEATURE] Added zstd as an option for grpc compression #5092
3131
* [FEATURE] Ring: Add new kv store option `dynamodb`. #5026
32+
* [FEATURE] Cache: Support redis as backend for caching bucket and index cache. #5057
3233
* [BUGFIX] Updated `golang.org/x/net` dependency to fix CVE-2022-27664. #5008
3334
* [BUGFIX] Fix panic when otel and xray tracing is enabled. #5044
3435
* [BUGFIX] Fixed no compact block got grouped in shuffle sharding grouper. #5055

docs/blocks-storage/querier.md

Lines changed: 323 additions & 1 deletion
Large diffs are not rendered by default.

docs/blocks-storage/store-gateway.md

Lines changed: 335 additions & 6 deletions
Large diffs are not rendered by default.

docs/blocks-storage/store-gateway.template

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ The store-gateway can use a cache to speed up lookups of postings and series fro
117117

118118
- `inmemory`
119119
- `memcached`
120+
- `redis`
120121

121122
#### In-memory index cache
122123

@@ -139,20 +140,26 @@ The Memcached client uses a jump hash algorithm to shard cached entries across a
139140
For example, if you're running Memcached in Kubernetes, you may:
140141

141142
1. Deploy your Memcached cluster using a [StatefulSet](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/)
142-
2. Create an [headless service](https://kubernetes.io/docs/concepts/services-networking/service/#headless-services) for Memcached StatefulSet
143+
2. Create a [headless service](https://kubernetes.io/docs/concepts/services-networking/service/#headless-services) for Memcached StatefulSet
143144
3. Configure the Cortex's Memcached client address using the `dnssrvnoa+` [service discovery](../configuration/arguments.md#dns-service-discovery)
144145

146+
#### Redis index cache
147+
148+
The `redis` index cache allows to use [Redis](https://memcached.org/) as cache backend. This cache backend is configured using `-blocks-storage.bucket-store.index-cache.backend=redis` and requires the Redis server(s) addresses via `-blocks-storage.bucket-store.index-cache.redis.addresses` (or config file).
149+
150+
Using `redis` as the cache backend has similar trade-offs as using `memcached` cache backend. However, client side caching can be enabled when using `redis` backend to avoid Store Gateway fetching data from cache each time. See [here](https://redis.io/docs/manual/client-side-caching/) for more info and it can be enabled by setting flag `-blocks-storage.bucket-store.index-cache.redis.cache-size` > 0.
151+
145152
### Chunks cache
146153

147154
Store-gateway can also use a cache for storing chunks fetched from the storage. Chunks contain actual samples, and can be reused if user query hits the same series for the same time range.
148155

149-
To enable chunks cache, please set `-blocks-storage.bucket-store.chunks-cache.backend`. Chunks can currently only be stored into Memcached cache. Memcached client can be configured via flags with `-blocks-storage.bucket-store.chunks-cache.memcached.*` prefix.
156+
To enable chunks cache, please set `-blocks-storage.bucket-store.chunks-cache.backend`. Chunks can be stored into Memcached or Redis cache. Memcached client can be configured via flags with `-blocks-storage.bucket-store.chunks-cache.memcached.*` prefix. Redis client can be configured via flags with `-blocks-storage.bucket-store.chunks-cache.redis.*` prefix.
150157

151158
There are additional low-level options for configuring chunks cache. Please refer to other flags with `-blocks-storage.bucket-store.chunks-cache.*` prefix.
152159

153160
### Metadata cache
154161

155-
Store-gateway and [querier](./querier.md) can use memcached for caching bucket metadata:
162+
Store-gateway and [querier](./querier.md) can use memcached or redis for caching bucket metadata:
156163

157164
- List of tenants
158165
- List of blocks per tenant
@@ -162,11 +169,11 @@ Store-gateway and [querier](./querier.md) can use memcached for caching bucket m
162169

163170
Using the metadata cache can significantly reduce the number of API calls to object storage and protects from linearly scale the number of these API calls with the number of querier and store-gateway instances (because the bucket is periodically scanned and synched by each querier and store-gateway).
164171

165-
To enable metadata cache, please set `-blocks-storage.bucket-store.metadata-cache.backend`. Only `memcached` backend is supported currently. Memcached client has additional configuration available via flags with `-blocks-storage.bucket-store.metadata-cache.memcached.*` prefix.
172+
To enable metadata cache, please set `-blocks-storage.bucket-store.metadata-cache.backend`. `memcached` and `redis` backend are supported currently. Memcached client has additional configuration available via flags with `-blocks-storage.bucket-store.metadata-cache.memcached.*` prefix. Redis client has additional configuration available via flags with `-blocks-storage.bucket-store.metadata-cache.redis.*` prefix.
166173

167174
Additional options for configuring metadata cache have `-blocks-storage.bucket-store.metadata-cache.*` prefix. By configuring TTL to zero or negative value, caching of given item type is disabled.
168175

169-
_The same memcached backend cluster should be shared between store-gateways and queriers._
176+
_The same cache backend deployment should be shared between store-gateways and queriers._
170177

171178
## Store-gateway HTTP endpoints
172179

0 commit comments

Comments
 (0)