-
Notifications
You must be signed in to change notification settings - Fork 692
Add support for Cortex Background Cache #640
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b8237fa
Add support for Cortex background cache
dgzlopes 3340729
Add Prometheus Registerer
dgzlopes 1a93a97
Use Cortex interface
dgzlopes f00d396
Make background cache configurable
dgzlopes 1429c0b
Add to changelog
dgzlopes 3d995ad
Add docs
dgzlopes fb63db3
From Background to BackgroundCache
dgzlopes 81cf202
Add default values
dgzlopes 6d6c80b
Remove config flags
dgzlopes 2f49a9c
Add note about Cache requirement
dgzlopes 4ada31c
Nit
dgzlopes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,25 +4,20 @@ import ( | |
| "context" | ||
| "io" | ||
|
|
||
| cortex_cache "github.com/cortexproject/cortex/pkg/chunk/cache" | ||
| "github.com/google/uuid" | ||
| "github.com/grafana/tempo/tempodb/backend" | ||
| ) | ||
|
|
||
| type readerWriter struct { | ||
| nextReader backend.Reader | ||
| nextWriter backend.Writer | ||
| client Client | ||
| cache cortex_cache.Cache | ||
| } | ||
|
|
||
| type Client interface { | ||
| Fetch(ctx context.Context, key string) []byte | ||
| Store(ctx context.Context, key string, val []byte) | ||
| Shutdown() | ||
| } | ||
|
Comment on lines
-17
to
-21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Amazing work. Have been wanting to reuse the Cortex Cache interfaces for a long time! |
||
|
|
||
| func NewCache(nextReader backend.Reader, nextWriter backend.Writer, client Client) (backend.Reader, backend.Writer, error) { | ||
| func NewCache(nextReader backend.Reader, nextWriter backend.Writer, cache cortex_cache.Cache) (backend.Reader, backend.Writer, error) { | ||
| rw := &readerWriter{ | ||
| client: client, | ||
| cache: cache, | ||
| nextReader: nextReader, | ||
| nextWriter: nextWriter, | ||
| } | ||
|
|
@@ -48,14 +43,14 @@ func (r *readerWriter) BlockMeta(ctx context.Context, blockID uuid.UUID, tenantI | |
| // Read implements backend.Reader | ||
| func (r *readerWriter) Read(ctx context.Context, name string, blockID uuid.UUID, tenantID string) ([]byte, error) { | ||
| key := key(blockID, tenantID, name) | ||
| val := r.client.Fetch(ctx, key) | ||
| if val != nil { | ||
| return val, nil | ||
| found, vals, _ := r.cache.Fetch(ctx, []string{key}) | ||
| if len(found) > 0 { | ||
| return vals[0], nil | ||
| } | ||
|
|
||
| val, err := r.nextReader.Read(ctx, name, blockID, tenantID) | ||
| if err == nil { | ||
| r.client.Store(ctx, key, val) | ||
| r.cache.Store(ctx, []string{key}, [][]byte{val}) | ||
| } | ||
|
|
||
| return val, err | ||
|
|
@@ -73,12 +68,12 @@ func (r *readerWriter) ReadRange(ctx context.Context, name string, blockID uuid. | |
| // Shutdown implements backend.Reader | ||
| func (r *readerWriter) Shutdown() { | ||
| r.nextReader.Shutdown() | ||
| r.client.Shutdown() | ||
| r.cache.Stop() | ||
| } | ||
|
|
||
| // Write implements backend.Writer | ||
| func (r *readerWriter) Write(ctx context.Context, name string, blockID uuid.UUID, tenantID string, buffer []byte) error { | ||
| r.client.Store(ctx, key(blockID, tenantID, name), buffer) | ||
| r.cache.Store(ctx, []string{key(blockID, tenantID, name)}, [][]byte{buffer}) | ||
|
|
||
| return r.nextWriter.Write(ctx, name, blockID, tenantID, buffer) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.