-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
feat(blooms): Prefetch bloom blocks as soon as they are built #15050
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fd25955
feat(blooms): Add PrefetchBloomBlocks to bloomgateway service
salvacorts 204acaa
Implement `PrefetchBloomBlocks` gRPC method on gateway
chaudum a90607d
fixup! Implement `PrefetchBloomBlocks` gRPC method on gateway
chaudum b141863
fixup! fixup! Implement `PrefetchBloomBlocks` gRPC method on gateway
chaudum 94face5
Builders call PrefetchBloomBlocks
salvacorts 6a79cee
fixup
salvacorts 685e871
CR feedback
salvacorts bb2c7c2
remove unused cfg
salvacorts d3fc8be
use running ctx to fetch blocks async
salvacorts db765bb
pass background ctx
salvacorts 7fc112c
increase queue size
salvacorts 1679110
Skip reporting hit/miss in cache
salvacorts a1ae1b0
Metrics
salvacorts 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 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 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 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 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 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 |
---|---|---|
|
@@ -161,6 +161,43 @@ func (g *Gateway) stopping(_ error) error { | |
return services.StopManagerAndAwaitStopped(context.Background(), g.serviceMngr) | ||
} | ||
|
||
func (g *Gateway) PrefetchBloomBlocks(_ context.Context, req *logproto.PrefetchBloomBlocksRequest) (*logproto.PrefetchBloomBlocksResponse, error) { | ||
refs, err := decodeBlockKeys(req.Blocks) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
bqs, err := g.bloomStore.FetchBlocks( | ||
// We don't use the ctx passed to the handler since its canceled when the handler returns | ||
context.Background(), | ||
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. Not passing a timeout here since you always need to call the cancel function before returning, which would trigger the download to stop. This is not an issue since when the gateway stops, the queue is closed and any pending block download is stopped. |
||
refs, | ||
bloomshipper.WithFetchAsync(true), | ||
bloomshipper.WithIgnoreNotFound(true), | ||
bloomshipper.WithCacheGetOptions( | ||
bloomshipper.WithSkipHitMissMetrics(true), | ||
), | ||
) | ||
if err != nil { | ||
g.metrics.prefetchedBlocks.WithLabelValues(typeError).Add(float64(len(refs))) | ||
return nil, err | ||
} | ||
|
||
for _, bq := range bqs { | ||
if bq == nil { | ||
// This is the expected case: the blocks is not yet downloaded and the block querier is nil | ||
continue | ||
} | ||
|
||
// Close any block querier that were already downloaded | ||
if err := bq.Close(); err != nil { | ||
level.Warn(g.logger).Log("msg", "failed to close block querier", "err", err) | ||
} | ||
} | ||
|
||
g.metrics.prefetchedBlocks.WithLabelValues(typeSuccess).Add(float64(len(refs))) | ||
return &logproto.PrefetchBloomBlocksResponse{}, err | ||
} | ||
|
||
// FilterChunkRefs implements BloomGatewayServer | ||
func (g *Gateway) FilterChunkRefs(ctx context.Context, req *logproto.FilterChunkRefRequest) (*logproto.FilterChunkRefResponse, error) { | ||
tenantID, err := tenant.TenantID(ctx) | ||
|
@@ -204,14 +241,10 @@ func (g *Gateway) FilterChunkRefs(ctx context.Context, req *logproto.FilterChunk | |
return &logproto.FilterChunkRefResponse{ChunkRefs: req.Refs}, nil | ||
} | ||
|
||
blocks := make([]bloomshipper.BlockRef, 0, len(req.Blocks)) | ||
for _, key := range req.Blocks { | ||
block, err := bloomshipper.BlockRefFromKey(key) | ||
if err != nil { | ||
stats.Status = labelFailure | ||
return nil, errors.New("could not parse block key") | ||
} | ||
blocks = append(blocks, block) | ||
blocks, err := decodeBlockKeys(req.Blocks) | ||
if err != nil { | ||
stats.Status = labelFailure | ||
return nil, err | ||
} | ||
|
||
// Shortcut if request does not contain blocks | ||
|
@@ -470,3 +503,15 @@ func filterChunkRefsForSeries(cur *logproto.GroupedChunkRefs, removals v1.ChunkR | |
|
||
cur.Refs = cur.Refs[:len(res)] | ||
} | ||
|
||
func decodeBlockKeys(keys []string) ([]bloomshipper.BlockRef, error) { | ||
blocks := make([]bloomshipper.BlockRef, 0, len(keys)) | ||
for _, key := range keys { | ||
block, err := bloomshipper.BlockRefFromKey(key) | ||
if err != nil { | ||
return nil, errors.New("could not parse block key") | ||
} | ||
blocks = append(blocks, block) | ||
} | ||
return blocks, nil | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need prefetch-specific metrics so we can measure the impact of this? (for example, how many blocks were downloaded via a prefetch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added