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

Loki: Enable FIFO cache by default #4519

Merged
merged 5 commits into from
Oct 25, 2021

Conversation

DylanGuedes
Copy link
Contributor

@DylanGuedes DylanGuedes commented Oct 21, 2021

Co-Authored-By: Mauro Stettler mauro.stettler@gmail.com

What this PR does / why we need it:

  • Enable FIFO cache by default for chunks store and for query results if no other cache storage is set
  • Sets defaults for the cache validity and for the FIFO cache's max-size-bytes

Which issue(s) this PR fixes:
N/A

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated

@DylanGuedes DylanGuedes force-pushed the new-default-cache-fifo-behavior branch from 3c77808 to 9d84947 Compare October 21, 2021 15:02
@DylanGuedes DylanGuedes marked this pull request as ready for review October 21, 2021 15:02
@DylanGuedes DylanGuedes requested review from KMiller-Grafana and a team as code owners October 21, 2021 15:02
@DylanGuedes DylanGuedes force-pushed the new-default-cache-fifo-behavior branch 2 times, most recently from 9b1a25f to 66b9c0d Compare October 21, 2021 16:27
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.

Docs change of the default values LGTM.

@DylanGuedes DylanGuedes force-pushed the new-default-cache-fifo-behavior branch 6 times, most recently from 4bfa44c to b014756 Compare October 21, 2021 21:02
replay and others added 3 commits October 22, 2021 08:17
Signed-off-by: Mauro Stettler <mauro.stettler@gmail.com>
- We noticed that we always want that behavior, so the logic is better
  implemented in the `ApplyDinamicConfig` method
- Update documentation
- Move FIFO cache default behavior implementation to ApplyDinamicConfig
@DylanGuedes DylanGuedes force-pushed the new-default-cache-fifo-behavior branch 2 times, most recently from 5e092bb to cdd3c01 Compare October 22, 2021 11:35
@@ -21,41 +21,41 @@ import (
"github.com/grafana/loki/pkg/util/cfg"
)

func Test_ApplyDynamicConfig(t *testing.T) {
testContextExposingErrs := func(configFileString string, args []string) (error, ConfigWrapper, ConfigWrapper) {
Copy link
Contributor Author

@DylanGuedes DylanGuedes Oct 22, 2021

Choose a reason for hiding this comment

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

Here I'm moving this block to a separate function to reuse it in other tests.

edit: I've also moved the returned error from first to last param

- The tests tests the behavior of the four existing caches (query results, query
index, write dedupe, and chunk results)
- Add changelog entry
- Fix lint issues regarding import order
- Revert moving of EnableFifoCache check
@DylanGuedes DylanGuedes force-pushed the new-default-cache-fifo-behavior branch from cdd3c01 to afcaee8 Compare October 22, 2021 21:45
Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

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

Still thinking about this one. I don't think we'll want write_dedupe_cache to automatically be enabled: it's unused with boltdb shipper and is only helpful coordinating which chunks have been flushed between multiple nodes (local fifo cache isn't helpful here). I'm leaning towards just enabling this for chunks,index, and query-results caches. Then again, enabling a local write-dedupe-cache won't do anything aside take some cpu cycles and memory, so it may just be simpler to eat the performance hit for config simplicity. WDYT @slim-bean ?

}
}

// isRedisSet is a duplicate of cache.IsRedisSet.
Copy link
Member

Choose a reason for hiding this comment

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

If the structs are identical, can we instead just call lokicache.IsRedisSet(cortexcache.RedisConfig(config))? That would also be less likely to cause errors in the future as we extend the code. Instead, it would cause compiler errors which we could fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow that looks cool. I'll try it, let's see.

Copy link
Contributor Author

@DylanGuedes DylanGuedes Oct 25, 2021

Choose a reason for hiding this comment

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

Oh, it didn't work for a similar reason :(
It conflicts because "github.com/cortexproject/cortex/pkg/chunk/cache".RedisConfig) != "github.com/grafana/loki/pkg/storage/chunk/cache".RedisConfig.

edit: In short: even if the structs are exactly the same, you can't just cast them because in essence they are different types (for being in different packages). One solution that I can think of is expecting a interface{} and then casting to cortexcache.Config and if it doesn't work, casting to lokicache.Config, but that looks weird/too much.

edit2: snippet:

func IsRedisSet(genericCfg interface{}) bool {
	if cortexCfg, ok := genericCfg.(cortexcache.Config); ok {
		return cortexCfg.RedisConfig.Address != ""
        }
        if lokiCfg, ok := genericCfg.(lokicache.Config); ok {
		return lokiCfg.RedisConfig.Address != ""
	}
	return false
}

@DylanGuedes
Copy link
Contributor Author

Still thinking about this one. I don't think we'll want write_dedupe_cache to automatically be enabled: it's unused with boltdb shipper and is only helpful coordinating which chunks have been flushed between multiple nodes (local fifo cache isn't helpful here). I'm leaning towards just enabling this for chunks,index, and query-results caches. Then again, enabling a local write-dedupe-cache won't do anything aside take some cpu cycles and memory, so it may just be simpler to eat the performance hit for config simplicity. WDYT @slim-bean ?

The local cache is set to only be enabled by default for chunk store and for query results (so yeah, no default cache for dedupe_writes). That said, looks like you think index cache should be enabled by default. Do you mind sharing why?

Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

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

Upon further thinking, we don't want the index cache to be enabled by default because we don't want the ingester to cache these queries when it's configured to query the store. Let's add a couple tests to ensure we're not setting FIFO caches for the index or write_dedupe caches even when no other cache is set for those, then LGTM!

pkg/storage/chunk/cache/cache.go Outdated Show resolved Hide resolved
- Change `EnableFifoCache` description to mention that it is only applied for chunk and query results cache

Co-authored-by: Owen Diehl <ow.diehl@gmail.com>
@DylanGuedes
Copy link
Contributor Author

Upon further thinking, we don't want the index cache to be enabled by default because we don't want the ingester to cache these queries when it's configured to query the store. Let's add a couple tests to ensure we're not setting FIFO caches for the index or write_dedupe caches even when no other cache is set for those, then LGTM!

WDYT of the tests at lines 716 and 748 from pkg/loki/config_wrapper_test.go? They are covering that enableFifoCache isn't affected for the index and dedupe caches (although I agree that I'm not really checking if the final cache being used is the local/FIFO or not).

@owen-d
Copy link
Member

owen-d commented Oct 25, 2021

Ah, I didn't catch that case. Nice work :)

@owen-d owen-d merged commit 77ea117 into grafana:main Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants