-
Notifications
You must be signed in to change notification settings - Fork 3.7k
perf(bloom): Compute chunkrefs for series right before sending task to builder #14808
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
salvacorts
merged 6 commits into
main
from
salvacorts/populate-chunks-before-sending-task
Nov 7, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ac8f3f
Do not store chunkrefs in queue task. Defer populating chunks to just…
salvacorts 0d1e610
ToProto implemented in planner.Task
salvacorts a3cb73f
Add comment to proto.Task
salvacorts 4ace777
use protos.Task in strategies.Task
salvacorts 9d6870f
Wrap ToProtoTask
salvacorts ec71ebe
ForSeries in common pkg
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ import ( | |
"time" | ||
|
||
"github.com/prometheus/common/model" | ||
"github.com/prometheus/prometheus/model/labels" | ||
|
||
"github.com/grafana/loki/v3/pkg/compression" | ||
v2 "github.com/grafana/loki/v3/pkg/iter/v2" | ||
v1 "github.com/grafana/loki/v3/pkg/storage/bloom/v1" | ||
"github.com/grafana/loki/v3/pkg/storage/config" | ||
"github.com/grafana/loki/v3/pkg/storage/stores/shipper/bloomshipper" | ||
"github.com/grafana/loki/v3/pkg/storage/stores/shipper/indexshipper/tsdb" | ||
"github.com/grafana/loki/v3/pkg/storage/stores/shipper/indexshipper/tsdb/index" | ||
) | ||
|
||
var TestDay = ParseDayTime("2023-09-01") | ||
|
@@ -87,11 +89,23 @@ func GenBlock(ref bloomshipper.BlockRef) (bloomshipper.Block, error) { | |
}, nil | ||
} | ||
|
||
func GenSeries(bounds v1.FingerprintBounds) []*v1.Series { | ||
func GenSeries(bounds v1.FingerprintBounds) []model.Fingerprint { | ||
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. nit: Should this be GenFingerprint/GenFignerPrintWithStep? |
||
return GenSeriesWithStep(bounds, 1) | ||
} | ||
|
||
func GenSeriesWithStep(bounds v1.FingerprintBounds, step int) []*v1.Series { | ||
func GenSeriesWithStep(bounds v1.FingerprintBounds, step int) []model.Fingerprint { | ||
series := make([]model.Fingerprint, 0, int(bounds.Max-bounds.Min+1)/step) | ||
for i := bounds.Min; i <= bounds.Max; i += model.Fingerprint(step) { | ||
series = append(series, i) | ||
} | ||
return series | ||
} | ||
|
||
func GenV1Series(bounds v1.FingerprintBounds) []*v1.Series { | ||
return GenV1SeriesWithStep(bounds, 1) | ||
} | ||
|
||
func GenV1SeriesWithStep(bounds v1.FingerprintBounds, step int) []*v1.Series { | ||
series := make([]*v1.Series, 0, int(bounds.Max-bounds.Min+1)/step) | ||
for i := bounds.Min; i <= bounds.Max; i += model.Fingerprint(step) { | ||
series = append(series, &v1.Series{ | ||
|
@@ -139,3 +153,43 @@ func ParseDayTime(s string) config.DayTime { | |
Time: model.TimeFromUnix(t.Unix()), | ||
} | ||
} | ||
|
||
type FakeForSeries struct { | ||
series []*v1.Series | ||
} | ||
|
||
func NewFakeForSeries(series []*v1.Series) *FakeForSeries { | ||
return &FakeForSeries{ | ||
series: series, | ||
} | ||
} | ||
|
||
func (f FakeForSeries) ForSeries(_ context.Context, _ string, ff index.FingerprintFilter, _ model.Time, _ model.Time, fn func(labels.Labels, model.Fingerprint, []index.ChunkMeta) (stop bool), _ ...*labels.Matcher) error { | ||
overlapping := make([]*v1.Series, 0, len(f.series)) | ||
for _, s := range f.series { | ||
if ff.Match(s.Fingerprint) { | ||
overlapping = append(overlapping, s) | ||
} | ||
} | ||
|
||
for _, s := range overlapping { | ||
chunks := make([]index.ChunkMeta, 0, len(s.Chunks)) | ||
for _, c := range s.Chunks { | ||
chunks = append(chunks, index.ChunkMeta{ | ||
MinTime: int64(c.From), | ||
MaxTime: int64(c.Through), | ||
Checksum: c.Checksum, | ||
KB: 100, | ||
}) | ||
} | ||
|
||
if fn(labels.EmptyLabels(), s.Fingerprint, chunks) { | ||
break | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (f FakeForSeries) Close() error { | ||
return nil | ||
} |
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.
Nice catch :)