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

Use CacheKeyGenerator implementation in error caching middleware #9644

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

56quarters
Copy link
Contributor

@56quarters 56quarters commented Oct 16, 2024

What this PR does

Use an implementation of the CacheKeyGenerator interface instead of bare function to generate cache keys for error caching. This allows downstream consumers (GEM) to inject custom logic for caching based on LBAC rules.

Which issue(s) this PR fixes or relates to

Related #9028

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

Use an implementation of the CacheKeyGenerator interface instead of bare
function to generate cache keys for error caching. This allows downstream
consumers (GEM) to inject custom logic for caching based on LBAC rules.

Signed-off-by: Nick Pillitteri <[email protected]>
@56quarters 56quarters marked this pull request as ready for review October 16, 2024 14:15
@56quarters 56quarters requested a review from a team as a code owner October 16, 2024 14:15
@@ -85,7 +86,7 @@ func (e *errorCachingHandler) Do(ctx context.Context, request MetricsQueryReques
}

e.cacheLoadAttempted.Inc()
key := errorCachingKey(tenant.JoinTenantIDs(tenantIDs), request)
key := e.keyGen.QueryRequestError(ctx, tenant.JoinTenantIDs(tenantIDs), request)
hashedKey := cacheHashKey(key)

if cachedErr := e.loadErrorFromCache(ctx, key, hashedKey, spanLog); cachedErr != nil {
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 method uses the hashedKey to fetch the value from cache and then compares the stored key to generated one.

@56quarters 56quarters merged commit 4377b80 into main Oct 17, 2024
29 checks passed
@56quarters 56quarters deleted the 56quarters/error-cache-key branch October 17, 2024 20:59
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.

2 participants