Store Gateway: Cache expanded postings for expensive matcher #8023
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Store Gateway Index Cache caches each posting individually. For example, pod="prometheus-0" is one cache key and pod="prometheus-1" can be another cache key. This is kind of problematic for those high cardinality labels for example,
host
,node
orpod
.When there is a query matcher such as
pod!=""
, Store Gateway tries to get all values of labelpod
and fetches each value from the remote cache. This is ok for small set up. However, we have 100+ vertically sharded blocks per day where each block has close to 1M values forpod
label. When a query tries to fetch 30 days of data with matcherpod!=""
, this ended up fetching 3B cache keys from remote cache. It is even worse when there is cache miss for postings, Store Gateway tries to backfill remote cache with postings data fetched from object store. This can be another 3B SET requests to the cache.Lazy posting is a way to solve high cardinality matchers such as
pod!=""
and we have several attempts to improve that. However, the root cause of the problem is that Index Cache stores each label (posting) separately and it is not doing well against high cardinality labels.Changes
This PR made several changes:
pod!=""
usually matches more than 1 pod so it tries to fetch expanded postings matchingpod!=""
.pod
from cache and object storage.__name__="metric_name"
, it works the same as of today.Basically we change from caching individual postings to caching the whole matcher.
Index Cache interface
FetchExpandedPostings
is updated to support multiple matchers. The previous one is designed to fetch only one set of matchers.Verification
Tests updated.