Skip to content

Conversation

@mem
Copy link
Contributor

@mem mem commented Nov 12, 2025

In order to have more resilience in the face of outages, implement an out-of-process cache using memcached. In order to support the existing mode of operation, add an in-process-cache using Otter. Rework the tenant cache to use this new system.

In order to have more resilience in the face of outages, implement an
out-of-process cache using memcached. In order to support the existing
mode of operation, add an in-process-cache using Otter. Rework the
tenant cache to use this new system.

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
@mem mem requested a review from a team as a code owner November 12, 2025 01:42
@mem mem requested review from The-9880 and d0ugal November 12, 2025 01:42
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bit that needs the most attention.

//
// This interface allows the agent to use different cache backends interchangeably,
// including a no-op implementation that eliminates the need for nil checks in client code.
type Cache interface {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are three implementations of this interface.

A memcached one. This is the one I would like to use eventually.

A local one, based on Otter.

A noop one, which is a fallback in case the other two are not available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did consider a multi-tiered implementation, too, using L1 with Otter and L2 with memcached. I would prefer to get some numbers before going that way.

type Cache interface {
// Set stores a value in the cache with the specified expiration time.
// Returns an error if the operation fails.
Set(ctx context.Context, key string, value any, expiration time.Duration) error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bit where I struggled the most.

Otter uses generics to have a more strongly-typed cache. Since the goal is to use memcached, which does not have a strongly-typed API, I thought about multiple clients, one per type, but it was weird.

@mem
Copy link
Contributor Author

mem commented Nov 12, 2025

Apologies about the large PR.

I did consider breaking it up into multiple steps, but it's hard to see where this is going without the changes in the tenant manager code, and it's hard to make the tenant manager changes without the other code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant