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

cache: Enable embedded cache if no other cache is configured. #10620

Merged
merged 15 commits into from
Sep 22, 2023

Conversation

ashwanthgoli
Copy link
Contributor

@ashwanthgoli ashwanthgoli commented Sep 18, 2023

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

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
    • If the change is worth mentioning in the release notes, add add-to-release-notes label
  • 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

@github-actions github-actions bot added the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label Sep 18, 2023
@ashwanthgoli ashwanthgoli marked this pull request as ready for review September 18, 2023 05:59
@ashwanthgoli ashwanthgoli requested a review from a team as a code owner September 18, 2023 05:59
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.
Copy link
Contributor

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/loki/config_wrapper.go Show resolved Hide resolved
PurgeInterval: cfg.EmbeddedCache.PurgeInterval,
}
if cfg.EmbeddedCache.IsEnabled() {
fifocfg := FifoCacheConfig{
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not always, it seems:

loki/pkg/loki/modules.go

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@JStickler JStickler left a 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

Copy link
Contributor

@dannykopping dannykopping left a 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])
Copy link
Contributor Author

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 {
Copy link
Contributor Author

@ashwanthgoli ashwanthgoli Sep 22, 2023

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

Copy link
Contributor

@dannykopping dannykopping 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 a lot @ashwanthgoli!

}),

entriesAddedNew: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Namespace: "querier",
Copy link
Contributor

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 👍

Copy link
Contributor Author

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

docs/sources/configure/query-frontend.md Outdated Show resolved Hide resolved
Co-authored-by: Christian Haudum <christian.haudum@gmail.com>
@ashwanthgoli ashwanthgoli merged commit 2902f98 into main Sep 22, 2023
3 checks passed
@ashwanthgoli ashwanthgoli deleted the ashwanth/apply-embedded-cache-defaults branch September 22, 2023 13:51
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants