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

embedded-cache: Bring fifocache and groupcache into single tent. #6821

Merged
merged 21 commits into from
Aug 9, 2022

Conversation

kavirajk
Copy link
Contributor

@kavirajk kavirajk commented Aug 1, 2022

Signed-off-by: Kaviraj [email protected]

What this PR does / why we need it:
This PR introduces have following changes

  1. new cache type called "embedded-cache"
  2. Now we bring both fifocache and groupcache into single tent called embedded-cache.
  3. old fifocache is depreicated. New config is embedded-cache.enabled=true && embedded-cache.distributed=false
  4. replaces groupcache references to embedded cache accordingly.
  5. distributed embedded cache is enabled only for results cache.

Usage: Embedded Cache.

embedded_cache:
    enabled: true
    distributed: true|false

Usage: Distributed Embedded cache (supported only for results cache for now)

query_range:
  results_cache:
    cache:
      embedded_cache:
        enabled: true
        distributed: true`

or via flag

-frontend.embedded-cache.distributed -frontend.embedded-cache.enabled

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
This is part of config cleanup before shipping groupcache feature for results cache.

Checklist

  • Documentation added
  • Tests updated
  • Is this an important fix or new feature? Add an entry in the CHANGELOG.md.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/upgrading/_index.md

1. Introduced new config called memorycache config.
2. It has flag `distributed`. By enabling it, we use groupcache

Going forward. We will bring fifocache into memcache config(with distributed:false)

This PR is just a POC. To show how we can simplify in-built memory cache config and bring it into single config.

Signed-off-by: Kaviraj <[email protected]>
@kavirajk kavirajk changed the title chore(groupcache): Rename groupcache into memcache{distributed: true} chore(groupcache): Rename groupcache into memorycache{distributed: true} Aug 1, 2022
Copy link
Contributor

@MasslessParticle MasslessParticle left a comment

Choose a reason for hiding this comment

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

I'm not clear: what happens when we set distributed = false?

Nevemind read the description

pkg/storage/chunk/cache/cache.go Outdated Show resolved Hide resolved
pkg/storage/chunk/cache/groupcache.go Outdated Show resolved Hide resolved
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.

Great start! I was expecting to see some code which applies fifocache when memorycache is set with distributed: false. Did I miss it?

@kavirajk kavirajk changed the title chore(groupcache): Rename groupcache into memorycache{distributed: true} embedded-cache: Bring fifocache and groupcache into single tent. Aug 3, 2022
@kavirajk kavirajk marked this pull request as ready for review August 3, 2022 10:50
@kavirajk kavirajk requested a review from a team as a code owner August 3, 2022 10:50
Signed-off-by: Kaviraj <[email protected]>
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
-               loki	-0.1%

Signed-off-by: Kaviraj <[email protected]>
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.

Great work Kavi! Minor nits, mostly

CHANGELOG.md Outdated Show resolved Hide resolved
pkg/loki/config_wrapper.go Outdated Show resolved Hide resolved
pkg/loki/modules.go Outdated Show resolved Hide resolved
pkg/loki/modules.go Outdated Show resolved Hide resolved
pkg/storage/chunk/cache/cache.go Outdated Show resolved Hide resolved
pkg/storage/chunk/cache/cache.go Outdated Show resolved Hide resolved
pkg/storage/chunk/cache/cache.go Outdated Show resolved Hide resolved
Copy link
Contributor

@MasslessParticle MasslessParticle left a comment

Choose a reason for hiding this comment

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

Overall this looks awesome. I think we need to think through how the ring config works and think about enabling this for the chunks cache.

pkg/storage/chunk/cache/cache.go Outdated Show resolved Hide resolved
pkg/storage/chunk/cache/embeddedcache.go Outdated Show resolved Hide resolved
pkg/storage/chunk/cache/groupcache.go Outdated Show resolved Hide resolved
pkg/loki/modules.go Outdated Show resolved Hide resolved
pkg/loki/config_wrapper.go Outdated Show resolved Hide resolved
pkg/loki/modules.go Outdated Show resolved Hide resolved
Signed-off-by: Kaviraj <[email protected]>
1. update changelog and upgrade guide
2. s/Embeddedcache/EmbeddedCache/g
3. /groupcache/ handler -> /embedded-cache/
4. some typos
5. Fix some cache prefixes

Signed-off-by: Kaviraj <[email protected]>

Signed-off-by: Kaviraj <[email protected]>
@github-actions github-actions bot added the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label Aug 4, 2022
@kavirajk kavirajk requested review from dannykopping and MasslessParticle and removed request for MasslessParticle August 4, 2022 10:05
@kavirajk
Copy link
Contributor Author

kavirajk commented Aug 4, 2022

NOTE: @slim-bean suggested an idea of instead of have boolean flag distributed, we could have type: local|distributed that has the more leverage to add different types of caches in the future.

I like the idea. I will take that up in the follow up PR.

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
-               loki	-0.3%

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.

Looks great Kavi! We should test it out a bit and wait for Travis to approve before merging, but this looks promising. Left a couple very minor wording nits.

Comment on lines 38 to 40
We introduce new cache called `embedded-cache` which is an in-process cache system that make it possible to run loki without the need for an external cache (like memcached, redis, etc). It can be run in two modes `distributed: false` (default, and same as old `fifocache`) and `distributed: true` which runs cache in distributed fashion sharding keys across peers if Loki is run in microservices or SSD mode.

Currently `embedde-cache` with `distributed: true` can be enabled only for results cache.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
We introduce new cache called `embedded-cache` which is an in-process cache system that make it possible to run loki without the need for an external cache (like memcached, redis, etc). It can be run in two modes `distributed: false` (default, and same as old `fifocache`) and `distributed: true` which runs cache in distributed fashion sharding keys across peers if Loki is run in microservices or SSD mode.
Currently `embedde-cache` with `distributed: true` can be enabled only for results cache.
We introduced a new cache called `embedded-cache` which is an in-process cache system that make it possible to run loki without the need for an external cache (like memcached, redis, etc). It can be run in two modes `distributed: false` (default, and same as old `fifocache`) and `distributed: true` which runs cache in distributed fashion sharding keys across peers if Loki is run in microservices or SSD mode.
Currently `embedded-cache` with `distributed: true` can be enabled only for results cache.

Distributed bool `yaml:"distributed,omitempty"`
Enabled bool `yaml:"enabled,omitempty"`
MaxSizeMB int64 `yaml:"max_size_mb"`
MaxItems int `yaml:"max_items"`
MaxItems int `yaml:"max_items"` // TODO(kavi): should we stop supporting it?
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO

}

func (cfg *EmbeddedCacheSingletonConfig) RegisterFlagsWithPrefix(prefix, description string, f *flag.FlagSet) {
f.IntVar(&cfg.ListenPort, prefix+"embedded-cache.listen_port", 4100, "The port to use for groupcache communication")
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's avoid mentioning the underlying technology

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
-               loki	-0.9%

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
-               loki	-0.3%

@KMiller-Grafana
Copy link
Contributor

Should the new configuration parameters be added to this doc section: https://grafana.com/docs/loki/latest/configuration/#cache_config, and should the fifocache configuration parameters be labeled as deprecated? If yes, an example of how the docs identify deprecated configuration parameters is split_queries_by_day.

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki

Change in test coverage per package. Green indicates 0 or positive change, red indicates that test coverage for a package fell.

+           ingester	0%
+        distributor	0%
+            querier	0%
+ querier/queryrange	0%
+               iter	0%
+            storage	0%
+           chunkenc	0%
+              logql	0%
-               loki	-0.3%

@kavirajk
Copy link
Contributor Author

kavirajk commented Aug 8, 2022

Should the new configuration parameters be added to this doc section: https://grafana.com/docs/loki/latest/configuration/#cache_config, and should the fifocache configuration parameters be labeled as deprecated? If yes, an example of how the docs identify deprecated configuration parameters is split_queries_by_day.

Thanks for pointer @KMiller-Grafana. Will definitely do it in the follow up PR. When I fix the distributed bool flag as mentioned in this comment.
#6821 (comment)

@09jvilla
Copy link
Contributor

09jvilla commented Aug 8, 2022

Addresses
#6785

Copy link
Contributor

@KMiller-Grafana KMiller-Grafana left a comment

Choose a reason for hiding this comment

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

Thank you for the changes.

@kavirajk kavirajk merged commit 7e3d243 into main Aug 9, 2022
@kavirajk kavirajk deleted the kaviraj/memorycache-unification-config branch August 9, 2022 10:49
lxwzy pushed a commit to lxwzy/loki that referenced this pull request Nov 7, 2022
…rafana#6821)

* chore(groupcache): Rename groupcache into memcache{distributed: true}

1. Introduced new config called memorycache config.
2. It has flag `distributed`. By enabling it, we use groupcache

Going forward. We will bring fifocache into memcache config(with distributed:false)

This PR is just a POC. To show how we can simplify in-built memory cache config and bring it into single config.

Signed-off-by: Kaviraj <[email protected]>

* Memorycache -> EmbeddedCache

* Bring fifocache into embeddedcache tent

Signed-off-by: Kaviraj <[email protected]>

* Fix edge case with enabling fifocache

Signed-off-by: Kaviraj <[email protected]>

* Fix missing flags for embedded cache

Signed-off-by: Kaviraj <[email protected]>

* Add changelog

Signed-off-by: Kaviraj <[email protected]>

* Warning message for fifocache config

Signed-off-by: Kaviraj <[email protected]>

* Make linter happy

Signed-off-by: Kaviraj <[email protected]>

* Fix listenport issue

Signed-off-by: Kaviraj <[email protected]>

* idk. review remarks

Signed-off-by: Kaviraj <[email protected]>

* PR remarks
1. update changelog and upgrade guide
2. s/Embeddedcache/EmbeddedCache/g
3. /groupcache/ handler -> /embedded-cache/
4. some typos
5. Fix some cache prefixes

Signed-off-by: Kaviraj <[email protected]>

Signed-off-by: Kaviraj <[email protected]>

* Fixing corresponding tests

Signed-off-by: Kaviraj <[email protected]>

* Support extra timeouts on embedded-cache

Signed-off-by: Kaviraj <[email protected]>

* Remove unwanted single struct field

Signed-off-by: Kaviraj <[email protected]>

* fix(stats-collector): Let cache.New() wrap stats collector for distributed cache

Signed-off-by: Kaviraj <[email protected]>

* PR remarks

Signed-off-by: Kaviraj <[email protected]>

* Deprecate max_size_items from fifocache

Signed-off-by: Kaviraj <[email protected]>

* PR remarks about the flag description

Signed-off-by: Kaviraj <[email protected]>

* Update docs/sources/upgrading/_index.md

Co-authored-by: Karen Miller <[email protected]>

Co-authored-by: Karen Miller <[email protected]>
ashwanthgoli added a commit that referenced this pull request Sep 22, 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**
- [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](d10549e)

---------

Co-authored-by: Christian Haudum <[email protected]>
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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L 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.

6 participants