-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
cache: Enable embedded cache if no other cache is configured. #10620
Conversation
func applyFIFOCacheConfig(r *ConfigWrapper) { | ||
// applyEmbeddedCacheConfig turns on Embedded cache for the chunk store, query range results, | ||
// index stats and volume results only if no other cache storage is configured (redis or memcache). | ||
// Not applicable for the index queries cache or for the write dedupe cache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write dedupe cache
Possibly not for this PR, but I think we can remove this cache; it's been deprecated for ages.
pkg/storage/chunk/cache/cache.go
Outdated
PurgeInterval: cfg.EmbeddedCache.PurgeInterval, | ||
} | ||
if cfg.EmbeddedCache.IsEnabled() { | ||
fifocfg := FifoCacheConfig{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be EmbeddedCacheConfig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it internally uses fifo cache. I think the idea was to abstract away the implementation details; embedded cache would initialize fifo or group cache based on the distributed
flag but the former is now removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not always, it seems:
Lines 587 to 598 in e5c425e
t.Cfg.StorageConfig.IndexQueriesCacheConfig = cache.Config{ | |
EmbeddedCache: cache.EmbeddedCacheConfig{ | |
Enabled: true, | |
MaxSizeMB: 200, | |
// This is a small hack to save some CPU cycles. | |
// We check if the object is still valid after pulling it from cache using the IndexCacheValidity value | |
// however it has to be deserialized to do so, setting the cache validity to some arbitrary amount less than the | |
// IndexCacheValidity guarantees the FIFO cache will expire the object first which can be done without | |
// having to deserialize the object. | |
TTL: t.Cfg.StorageConfig.IndexCacheValidity - 1*time.Minute, | |
}, | |
} |
Things are getting pretty weird in this space. I think we need to standardise on a single, clear approach.
I don't think we want to keep groupcache at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the former is now removed
sorry correction. I meant to say groupcache is now removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a bit weird for me. EmbeddedCacheConfig
and FifoCacheConfig
are almost identical, so we should prefer EmbeddedCacheConfig
to reduce complexity. We're nominally removing fifocache in this PR but by still using its configs and internal structs.
Maybe for another PR, but I think we should rename FifoCache
to EmbeddedCache
and simplify this part of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree with this. pushed commits to remove/rename fifocache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[docs team] Docs LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to unblock, left a comment about still using FifoCache
internally which feels weird.
|
||
if tc.numCaches == 2 { | ||
if tc.equalCaches { | ||
require.Equal(t, caches[0], caches[1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot compare them as they are bound to be different instances of embedded cache.
what we want to compare are configs passed down to the cache
results cache enabled, stats cache enabled but different
I'll raise a separate pr to improve this test
} | ||
|
||
func (cfg *EmbeddedCacheConfig) IsEnabled() bool { | ||
return cfg.Enabled | ||
} | ||
|
||
// NewEmbeddedCache returns a new initialised EmbeddedCache. | ||
func NewEmbeddedCache(name string, cfg EmbeddedCacheConfig, reg prometheus.Registerer, logger log.Logger, cacheType stats.CacheType) *EmbeddedCache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few changes to wire things after renaming fifo_cache.go/embeddedcache.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks a lot @ashwanthgoli!
}), | ||
|
||
entriesAddedNew: promauto.With(reg).NewCounter(prometheus.CounterOpts{ | ||
Namespace: "querier", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should take this opportunity to correct these metrics, too.
All our metrics start with loki_
(well... except the ones that start with cortex_
), but these don't. It also feels weird to limit the scope of this to the querier since many components can use this cache. Again, not necessarily for this PR 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, was talking to @chaudum about renaming these. i'll raise a separate pr
Co-authored-by: Christian Haudum <christian.haudum@gmail.com>
…a#10620) **What this PR does / why we need it**: FIFO cache is replaced by embedded-cache in grafana#6821 This PR enables embedded cache for query range results, chunks cache, index_stats_results and volume_results if no other cache is explicitly configured (redis, memcache). **Special notes for your reviewer**: Also removes a deprecated flag `cache-split-interval` **Checklist** - [x] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [ ] Documentation added - [x] Tests updated - [x] `CHANGELOG.md` updated - [ ] If the change is worth mentioning in the release notes, add `add-to-release-notes` label - [x] Changes that require user attention or interaction to upgrade are documented in `docs/sources/setup/upgrade/_index.md` - [ ] For Helm chart changes bump the Helm chart version in `production/helm/loki/Chart.yaml` and update `production/helm/loki/CHANGELOG.md` and `production/helm/loki/README.md`. [Example PR](grafana@d10549e) --------- Co-authored-by: Christian Haudum <christian.haudum@gmail.com>
What this PR does / why we need it:
FIFO cache is replaced by embedded-cache in #6821
This PR enables embedded cache for query range results, chunks cache, index_stats_results and volume_results if no other cache is explicitly configured (redis, memcache).
Special notes for your reviewer:
Also removes a deprecated flag
cache-split-interval
Checklist
CONTRIBUTING.md
guide (required)CHANGELOG.md
updatedadd-to-release-notes
labeldocs/sources/setup/upgrade/_index.md
production/helm/loki/Chart.yaml
and updateproduction/helm/loki/CHANGELOG.md
andproduction/helm/loki/README.md
. Example PR