Skip to content

feat(helm): Implementing support of l2 chunksCache memcache - #17556

Merged
nicolevanderhoeven merged 28 commits into
grafana:mainfrom
andrejshapal:patch-1
Jul 24, 2025
Merged

feat(helm): Implementing support of l2 chunksCache memcache#17556
nicolevanderhoeven merged 28 commits into
grafana:mainfrom
andrejshapal:patch-1

Conversation

@andrejshapal

@andrejshapal andrejshapal commented May 2, 2025

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
Not sure about speed (which should be the case), but cache reduces costs very much.
Even having 100 GB logs per day, the caching levels could help to avoid extra bucket operations.
Currently, the helm chart support chunksCache with ability to configure persistent storage and use memcached feature to store cold data on the disk. Without this feature, the volume of cache was limited by memory (memory is expensive...). Storing on disk made it possible to increase the cache volume, but there is a significant problem. In most of cases, the recent logs are queried (like few days old) and then there is a huge range of old logs which could be potentially queried (maybe just once). In cache we try to store the logs which likely to be queried. But when the disk space finished, we start to replace data. When old logs are queried, we put them in cache and potentially remove fresh logs. So, we keep in cache logs which likely will be not queried again and we remove those probably will be queried. To avoid this, we should avoid replacing new logs with old logs. This is where l2 cache appears. The logs older than n days are not being put in l1 cache and instead in l2 small cache. The old logs persist there for short period of time (in case if query will be executed multiple times while somebody searching something).

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR
@andrejshapal
andrejshapal requested a review from a team as a code owner May 2, 2025 14:58
@CLAassistant

CLAassistant commented May 2, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@pull-request-size pull-request-size Bot added size/XL and removed size/L labels May 8, 2025
@andrejshapal andrejshapal changed the title Implementing support of l2 chunksCache memcache May 8, 2025

@jkroepke jkroepke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

context: #10061

For records, I can't really find documentation.

Please do a rebase first, and avoid any changes not related to L2 - then I can do a full review again.

Comment thread production/helm/loki/CHANGELOG.md Outdated
Comment thread production/helm/loki/CHANGELOG.md Outdated
Comment thread production/helm/loki/CHANGELOG.md Outdated
@andrejshapal

Copy link
Copy Markdown
Contributor Author

context: #10061

For records, I can't really find documentation.

Please do a rebase first, and avoid any changes not related to L2 - then I can do a full review again.

Done. Thank you.

@jkroepke jkroepke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, I go through your PR and it looks good for now. Thanks a lot.

Here are my thoughts:

Could you please add a file named "non-default.values.yaml" in https://github.com/grafana/loki/tree/main/production/helm/loki/ci

and enable both cache l1 and l2? Then this larger code would be part of the CI tests.

Comment thread production/helm/loki/templates/chunks-cache/poddisruptionbudget-chunks-cache.yaml Outdated
Comment thread production/helm/loki/Chart.yaml Outdated
Comment thread production/helm/loki/CHANGELOG.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think tests were failing. But don't remember honestly. Reverted for now.

Comment thread production/helm/loki/values.yaml Outdated
Comment thread production/helm/loki/values.yaml Outdated
Comment thread production/helm/loki/templates/memcached/_memcached-statefulset.tpl Outdated
Comment thread production/helm/loki/values.yaml Outdated
@andrejshapal

Copy link
Copy Markdown
Contributor Author

@jkroepke I think all comments resolved.

@jkroepke

jkroepke commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

I do not have permissions yet to approve the CI, looking forward to next week for now

@JStickler

Copy link
Copy Markdown
Contributor

I kicked off the CI tests for you.

Conventional commits - The heading should be either fix(helm): or feat(helm):.

@andrejshapal andrejshapal changed the title Helm: Implementing support of l2 chunksCache memcache Jul 3, 2025
@andrejshapal

Copy link
Copy Markdown
Contributor Author

I kicked off the CI tests for you.

Conventional commits - The heading should be either fix(helm): or feat(helm):.

fixed, lint stage also

@andrejshapal

Copy link
Copy Markdown
Contributor Author

I kicked off the CI tests for you.

Conventional commits - The heading should be either fix(helm): or feat(helm):.

Rebased as well. Please, trigger pipeline again.

@jkroepke

jkroepke commented Jul 3, 2025

Copy link
Copy Markdown
Contributor

something looks odd here. maybe a rebase, then merge from origin mess-up.

@andrejshapal

Copy link
Copy Markdown
Contributor Author

something looks odd here. maybe a rebase, then merge from origin mess-up.

I had to force push amending previous commit due to missing email on my another PC and failing CLA signature.

@nicolevanderhoeven

Copy link
Copy Markdown
Contributor

@andrejshapal Sorry about that. Please go ahead!

@jkroepke

jkroepke commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

And sorry for the trouble. We have a very high merge volume in the last 3 weeks. Merge conflicts are expectable.

@andrejshapal

andrejshapal commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

@jkroepke Should be better. Could you launch tests?

There is actually thing I doubt. Now the pdb should not work with 1 replica. But I think people could be using it as prevention to restart memcache single pod loosing all the collected cache in memory (when pv is not used).

non-default values ci values should have only pdb for l2 cache to check functionality.

andrejshapal and others added 2 commits July 22, 2025 19:56
Signed-off-by: Andrejs Šapals <njuhaandrej@gmail.com>
@jkroepke

Copy link
Copy Markdown
Contributor

But I think people could be using it as prevention to restart memcache single pod loosing all the collected cache in memory (when pv is not used).

I can understand that i feel thats a bad design to choice a PDB as protection.If there is a node drain request incoming, the situation might be in stale unless the pod is removed. We should think about this request, if there is an user request for it.

@andrejshapal

Copy link
Copy Markdown
Contributor Author

But I think people could be using it as prevention to restart memcache single pod loosing all the collected cache in memory (when pv is not used).

I can understand that i feel thats a bad design to choice a PDB as protection.If there is a node drain request incoming, the situation might be in stale unless the pod is removed. We should think about this request, if there is an user request for it.

Well, it anyway is not related to my MR, but rather to #18321

@jkroepke

Copy link
Copy Markdown
Contributor

PDB tested locally.

LGTM!

1 similar comment
@jkroepke

Copy link
Copy Markdown
Contributor

PDB tested locally.

LGTM!

@jkroepke jkroepke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread production/helm/loki/ci/non-default-values.yaml
baz: qux
chunksCache:
l2:
enabled: true

@andrejshapal andrejshapal Jul 23, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@QuentinBisson Could you double check as you are commenting ci test values?

Comment thread production/helm/loki/values.yaml
@QuentinBisson

Copy link
Copy Markdown
Contributor

Same as @jkroepke LGTM. This might need some extra documentation to explain how and why to use this cache but this can bé done later. This is some really nice improvement

@jkroepke

Copy link
Copy Markdown
Contributor

This might need some extra documentation to explain how and why to use this cache but this can bé done later.

Yeah, I agree. But this is more in scope of the Loki product, not the Helm Chart.

#10061 is all what I found.

@QuentinBisson

Copy link
Copy Markdown
Contributor

100% but once it's documented it needs to bé linked here later still :)

@andrejshapal

Copy link
Copy Markdown
Contributor Author

@jkroepke @QuentinBisson fixed/resolved comments above, created task for docs #18563

andrejshapal and others added 2 commits July 23, 2025 21:41
Signed-off-by: nicolevanderhoeven <36070553+nicolevanderhoeven@users.noreply.github.com>

@nicolevanderhoeven nicolevanderhoeven left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @andrejshapal for your work here-- this is a great addition to the Helm chart! Thanks @jkroepke and @QuentinBisson for your reviews!

@nicolevanderhoeven
nicolevanderhoeven merged commit 039e7c1 into grafana:main Jul 24, 2025
75 checks passed
@andrejshapal
andrejshapal deleted the patch-1 branch July 24, 2025 15:56
felix0102 pushed a commit to felix0102/loki that referenced this pull request Aug 2, 2026
…17556)

Signed-off-by: Andrejs Šapals <njuhaandrej@gmail.com>
Signed-off-by: nicolevanderhoeven <36070553+nicolevanderhoeven@users.noreply.github.com>
Co-authored-by: Jan-Otto Kröpke <mail@jkroepke.de>
Co-authored-by: Nicole van der Hoeven <nicole@nicolevanderhoeven.com>
Co-authored-by: nicolevanderhoeven <36070553+nicolevanderhoeven@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment