Skip to content

feat(helm): allow external memcached setup - #17432

Merged
Jayclifford345 merged 2 commits into
grafana:mainfrom
abenbachir:abderb/memcached-external
Jul 8, 2025
Merged

feat(helm): allow external memcached setup#17432
Jayclifford345 merged 2 commits into
grafana:mainfrom
abenbachir:abderb/memcached-external

Conversation

@abenbachir

@abenbachir abenbachir commented Apr 24, 2025

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
allow external memcached setup, with overriding addresses.

Which issue(s) this PR fixes:
Fixes #12559

Special notes for your reviewer:
the old config loki.memcached does't work anymore.

New way of setting up external memcache is with:

memcached:
    enabled: false # <- setting false here
resultsCache:
    addresses: 'my-resultsCache-memcached-address' # <- setting custom address here
chunksCache:
    addresses: 'my-chunksCache-memcached-address' # <- setting custom address here

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
@abenbachir
abenbachir requested a review from a team as a code owner April 24, 2025 01:18
@abenbachir
abenbachir force-pushed the abderb/memcached-external branch 2 times, most recently from 0414044 to e06b294 Compare April 30, 2025 00:49
Comment thread production/helm/loki/values.yaml Outdated
Comment thread production/helm/loki/values.yaml Outdated
Comment thread production/helm/loki/CHANGELOG.md Outdated

@Starefossen Starefossen 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.

Looks good to me provided the suggestions are followed up and the tests pass.

@abenbachir
abenbachir force-pushed the abderb/memcached-external branch from e06b294 to 667701f Compare June 18, 2025 20:10
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jun 18, 2025
@abenbachir

Copy link
Copy Markdown
Contributor Author

Looks good to me provided the suggestions are followed up and the tests pass.

thanks for the feedback. Fixed it and rebased it.

@lina-semgrep

Copy link
Copy Markdown

Hi, waiting for the new version of the chart with this fix here as well :)

@abenbachir

Copy link
Copy Markdown
Contributor Author

@Starefossen I don't know why tests are not running.

@Starefossen

Copy link
Copy Markdown
Contributor

We need to ping the official maintainers to get them running.

@abenbachir

Copy link
Copy Markdown
Contributor Author

We need to ping the official maintainers to get them running.

Can you share there usernames, I will ping them.

@lina-semgrep

Copy link
Copy Markdown

We need to ping the official maintainers to get them running.

Can you share there usernames, I will ping them.

- name: trevorwhitney
- name: jeschkies
?

@JStickler

Copy link
Copy Markdown
Contributor

We've started a new Loki maintainers group, and while I was triaging Helm charts PRs, I went ahead and ran the CI for you. I'll flag this for the team to look at.

@lina-semgrep

Copy link
Copy Markdown

@abenbachir it seems there are some helm linting issues - do you have cycles to look at? if not I can try take a look

@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.

Hey @abenbachir

I'm part of a new maintainers group.

I looked through your PR and ask myself, if this can be simplified.

Do we really need to expose host and clientService? addresses also should cover most use-cases and I feel that expose just addresses is enough. Is there a use-case where addresses can't be used?

And here is why: Your example

memcached:
    enabled: false # <- setting false here
resultsCache:
    host: 'my-resultsCache-memcached-host' # <- setting custom host here
    clientService: 'my-memcached-svc'
chunksCache:
    host: 'my-chunksCache-memcached-host' # <- setting custom host here
    clientService: 'my-memcached-svc'

Will not work. Because in that scenario, addresses is still set. If addresses and host is set, loki takes addresses over host. Ref:

if len(c.addresses) > 0 {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := c.provider.Resolve(ctx, c.addresses); err != nil {
return err
}
servers = c.provider.Addresses()
} else {
_, addrs, err := net.LookupSRV(c.service, "tcp", c.hostname)
if err != nil {
return err
}
for _, srv := range addrs {
servers = append(servers, net.JoinHostPort(srv.Target, strconv.Itoa(int(srv.Port))))
}
}

Based on that, the user experience would be not great, because end-user have to set explicit addresses to an empty value to force loki pick addresses.

Comment thread production/helm/loki/templates/chunks-cache/poddisruptionbudget-chunks-cache.yaml Outdated
@abenbachir

abenbachir commented Jul 2, 2025

Copy link
Copy Markdown
Contributor Author

addresses

then I will only expose addresses, thanks for the feedback. below config will be the one to use.

memcached:
    enabled: false # <- setting false here
resultsCache:
    addresses: 'my-resultsCache-memcached-address' # <- setting custom address here
chunksCache:
    addresses: 'my-chunksCache-memcached-address' # <- setting custom address here
@jkroepke

jkroepke commented Jul 2, 2025

Copy link
Copy Markdown
Contributor

Thanks, please take now of the failing jobs.

Comment thread production/helm/loki/templates/memcached/_memcached-svc.tpl Outdated
Comment thread production/helm/loki/values.yaml Outdated
Comment thread production/helm/loki/values.yaml Outdated
Comment thread production/helm/loki/values.yaml Outdated
Comment thread production/helm/loki/values.yaml Outdated
@abenbachir
abenbachir force-pushed the abderb/memcached-external branch from cfe5dc4 to a5179de Compare July 2, 2025 23:08
@pull-request-size pull-request-size Bot added size/M and removed size/L labels Jul 2, 2025
@abenbachir
abenbachir force-pushed the abderb/memcached-external branch 2 times, most recently from b6efaa2 to c924722 Compare July 2, 2025 23:21
@abenbachir

Copy link
Copy Markdown
Contributor Author

@jkroepke thanks for the feedback, I have updated the PR with all suggestions.

@abenbachir
abenbachir force-pushed the abderb/memcached-external branch 7 times, most recently from a4a499a to 681ced9 Compare July 3, 2025 19:04

@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.

Generally, this LGTM. However, I found this sections in value.yaml

# -- Configure memcached as an external cache for chunk and results cache. Disabled by default
# must enable and specify a host for each cache you would like to use.
memcached:
chunk_cache:
enabled: false
host: ""
service: "memcached-client"
batch_size: 256
parallelism: 10
results_cache:
enabled: false
host: ""
service: "memcached-client"
timeout: "500ms"
default_validity: "12h"

This is a documented, but not implemented section in values.

@JStickler I'm not sure how we should proceed here. I recommend removing the section from the values file, as it confuses end users by presenting two configurations for the same functionality, even though only one of them actually works.

However, I'm not sure if this would count as a breaking change from your point of view, since it involves a documented (but non-functional) feature.

Add config support for external memcache cluster by setting the following config
memcached:
    enabled: false # <- setting false here
resultsCache:
    addresses: 'my-resultsCache-memcached-address' # <- setting custom address here
chunksCache:
    addresses: 'my-chunksCache-memcached-address' # <- setting custom address here
@abenbachir
abenbachir force-pushed the abderb/memcached-external branch from 681ced9 to f22417c Compare July 3, 2025 19:50
@abenbachir

Copy link
Copy Markdown
Contributor Author

Configure memcached as an external

yeah, that section is an old config, I removed it.

@Jayclifford345

Copy link
Copy Markdown
Contributor

Hey @jkroepke, @Starefossen
I am happy to merge this if we feel that removing the old config from the values file won't lead to breaking changes for other users. Especially since this changes how the configuration for default deployment detections of memcache that are deployed along side Loki

@jkroepke

jkroepke commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

I scrape through the helm chart and to my best knowledge, the removed lines from the values.yaml are not used anywhere. They are untouched for 3 years as well. They doesn't have any effect. If customers blame for breaking changes, they should consult that the changes did not have any effect.

@Jayclifford345
Jayclifford345 merged commit 013aa17 into grafana:main Jul 8, 2025
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment