-
Notifications
You must be signed in to change notification settings - Fork 821
Ruler: split oversized remote distributor writes #16160
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3e3ac8
Ruler: split oversized remote distributor writes
aknuds1 4200bc8
Use math.MaxInt
aknuds1 f29f7c8
Merge remote-tracking branch 'origin/main' into arve/ruler-split-remo…
aknuds1 6a7cd95
Update pkg/ruler/distributor_client.go
aknuds1 b83b72c
Ruler: refine request split histogram buckets
aknuds1 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,9 @@ package mimirpb | |
| // | ||
| // The returned requests may still retain references to fields in the original WriteRequest, i.e. they are tied to its lifecycle. | ||
| func SplitWriteRequestByMaxMarshalSize(req *WriteRequest, reqSize, maxSize int) []*WriteRequest { | ||
| if maxSize <= 0 { | ||
|
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. [nit] I think it's safe to assume |
||
| return []*WriteRequest{req} | ||
| } | ||
| if reqSize <= maxSize { | ||
| return []*WriteRequest{req} | ||
| } | ||
|
|
@@ -131,55 +134,48 @@ func splitTimeseriesByMaxMarshalSize(req *WriteRequest, reqSize, maxSize int) [] | |
| return nil | ||
| } | ||
|
|
||
| newPartialReq := func() (*WriteRequest, int) { | ||
| r := &WriteRequest{ | ||
| Source: req.Source, | ||
| SkipLabelValidation: req.SkipLabelValidation, | ||
| skipNormalizeMetadataMetricName: req.skipNormalizeMetadataMetricName, | ||
| skipDeduplicateMetadata: req.skipDeduplicateMetadata, | ||
| } | ||
|
|
||
| return r, r.Size() | ||
| } | ||
|
|
||
| // The partial requests returned by this function will not contain any Metadata, | ||
| // so we first compute the request size without it. | ||
| reqSizeWithoutMetadata := reqSize - req.MetadataSize() | ||
| if reqSizeWithoutMetadata <= maxSize { | ||
| partialReq, _ := newPartialReq() | ||
| partialReq := newPartialWriteRequest(req) | ||
| partialReq.Timeseries = req.Timeseries | ||
| return []*WriteRequest{partialReq} | ||
| } | ||
|
|
||
| // We assume that different timeseries roughly have the same size (no huge outliers) | ||
| // so we preallocate the returned slice just adding 1 extra item (+2 because a +1 is to round up). | ||
| estimatedPartialReqs := (reqSizeWithoutMetadata / maxSize) + 2 | ||
| // so we preallocate the returned slice just adding 1 extra item (+2 because a +1 is to round up), | ||
| // capped at the number of timeseries. | ||
| estimatedPartialReqs := min((reqSizeWithoutMetadata/maxSize)+2, len(req.Timeseries)) | ||
| partialReqs := make([]*WriteRequest, 0, estimatedPartialReqs) | ||
|
|
||
| // Split timeseries into partial write requests. | ||
| nextReq, nextReqSize := newPartialReq() | ||
| nextReq := newPartialWriteRequest(req) | ||
| nextReqSize := nextReq.Size() | ||
| nextReqTimeseriesStart := 0 | ||
| nextReqTimeseriesLength := 0 | ||
|
|
||
| for i := 0; i < len(req.Timeseries); i++ { | ||
| seriesSize := req.Timeseries[i].Size() | ||
| seriesFieldSize := embeddedMessageFieldSize(seriesSize) | ||
|
|
||
| // Check if the next partial request is full (or close to be full), and so it's time to finalize it and create a new one. | ||
| // If the next partial request doesn't have any timeseries yet, we add the series anyway, in order to avoid an infinite loop | ||
| // if a single timeseries is bigger than the limit. | ||
| if nextReqSize+seriesSize > maxSize && nextReqTimeseriesLength > 0 { | ||
| if nextReqSize+seriesFieldSize > maxSize && nextReqTimeseriesLength > 0 { | ||
| // Finalize the next partial request. | ||
| nextReq.Timeseries = req.Timeseries[nextReqTimeseriesStart : nextReqTimeseriesStart+nextReqTimeseriesLength] | ||
| partialReqs = append(partialReqs, nextReq) | ||
|
|
||
| // Initialize a new partial request. | ||
| nextReq, nextReqSize = newPartialReq() | ||
| nextReq = newPartialWriteRequest(req) | ||
| nextReqSize = nextReq.Size() | ||
| nextReqTimeseriesStart = i | ||
| nextReqTimeseriesLength = 0 | ||
| } | ||
|
|
||
| // Add the current series to next partial request. | ||
| nextReqSize += seriesSize + 1 + sovMimir(uint64(seriesSize)) // Math copied from Size(). | ||
| nextReqSize += seriesFieldSize | ||
| nextReqTimeseriesLength++ | ||
| } | ||
|
|
||
|
|
@@ -197,55 +193,48 @@ func splitMetadataByMaxMarshalSize(req *WriteRequest, reqSize, maxSize int) []*W | |
| return nil | ||
| } | ||
|
|
||
| newPartialReq := func() (*WriteRequest, int) { | ||
| r := &WriteRequest{ | ||
| Source: req.Source, | ||
| SkipLabelValidation: req.SkipLabelValidation, | ||
| skipUnmarshalingExemplars: req.skipUnmarshalingExemplars, | ||
| skipNormalizeMetadataMetricName: req.skipNormalizeMetadataMetricName, | ||
| skipDeduplicateMetadata: req.skipDeduplicateMetadata, | ||
| } | ||
| return r, r.Size() | ||
| } | ||
|
|
||
| // The partial requests returned by this function will not contain any Timeseries, | ||
| // so we first compute the request size without it. | ||
| reqSizeWithoutTimeseries := reqSize - req.TimeseriesSize() | ||
| if reqSizeWithoutTimeseries <= maxSize { | ||
| partialReq, _ := newPartialReq() | ||
| partialReq := newPartialWriteRequest(req) | ||
| partialReq.Metadata = req.Metadata | ||
| return []*WriteRequest{partialReq} | ||
| } | ||
|
|
||
| // We assume that different metadata roughly have the same size (no huge outliers) | ||
| // so we preallocate the returned slice just adding 1 extra item (+2 because a +1 is to round up). | ||
| estimatedPartialReqs := (reqSizeWithoutTimeseries / maxSize) + 2 | ||
| // so we preallocate the returned slice just adding 1 extra item (+2 because a +1 is to round up), | ||
| // capped at the number of metadata entries. | ||
| estimatedPartialReqs := min((reqSizeWithoutTimeseries/maxSize)+2, len(req.Metadata)) | ||
| partialReqs := make([]*WriteRequest, 0, estimatedPartialReqs) | ||
|
|
||
| // Split metadata into partial write requests. | ||
| nextReq, nextReqSize := newPartialReq() | ||
| nextReq := newPartialWriteRequest(req) | ||
| nextReqSize := nextReq.Size() | ||
| nextReqMetadataStart := 0 | ||
| nextReqMetadataLength := 0 | ||
|
|
||
| for i := 0; i < len(req.Metadata); i++ { | ||
| metadataSize := req.Metadata[i].Size() | ||
| metadataFieldSize := embeddedMessageFieldSize(metadataSize) | ||
|
|
||
| // Check if the next partial request is full (or close to be full), and so it's time to finalize it and create a new one. | ||
| // If the next partial request doesn't have any metadata yet, we add the metadata anyway, in order to avoid an infinite loop | ||
| // if a single metadata is bigger than the limit. | ||
| if nextReqSize+metadataSize > maxSize && nextReqMetadataLength > 0 { | ||
| if nextReqSize+metadataFieldSize > maxSize && nextReqMetadataLength > 0 { | ||
| // Finalize the next partial request. | ||
| nextReq.Metadata = req.Metadata[nextReqMetadataStart : nextReqMetadataStart+nextReqMetadataLength] | ||
| partialReqs = append(partialReqs, nextReq) | ||
|
|
||
| // Initialize a new partial request. | ||
| nextReq, nextReqSize = newPartialReq() | ||
| nextReq = newPartialWriteRequest(req) | ||
| nextReqSize = nextReq.Size() | ||
| nextReqMetadataStart = i | ||
| nextReqMetadataLength = 0 | ||
| } | ||
|
|
||
| // Add the current metadata to next partial request. | ||
| nextReqSize += metadataSize + 1 + sovMimir(uint64(metadataSize)) // Math copied from Size(). | ||
| nextReqSize += metadataFieldSize | ||
| nextReqMetadataLength++ | ||
| } | ||
|
|
||
|
|
@@ -258,6 +247,21 @@ func splitMetadataByMaxMarshalSize(req *WriteRequest, reqSize, maxSize int) []*W | |
| return partialReqs | ||
| } | ||
|
|
||
| func newPartialWriteRequest(req *WriteRequest) *WriteRequest { | ||
| return &WriteRequest{ | ||
| Source: req.Source, | ||
| SkipLabelValidation: req.SkipLabelValidation, | ||
| SkipLabelCountValidation: req.SkipLabelCountValidation, | ||
| skipUnmarshalingExemplars: req.skipUnmarshalingExemplars, | ||
| skipNormalizeMetadataMetricName: req.skipNormalizeMetadataMetricName, | ||
| skipDeduplicateMetadata: req.skipDeduplicateMetadata, | ||
| } | ||
| } | ||
|
|
||
| func embeddedMessageFieldSize(messageSize int) int { | ||
| return 1 + messageSize + sovMimir(uint64(messageSize)) | ||
| } | ||
|
|
||
| // maxSeriesSizeAfterResymbolization calculates an upper bound for the size of the given TimeSeries, and its referenced symbols. | ||
| // It is only an upper bound. The actual series might end up being smaller if it re-uses symbols or has low magnitude references. | ||
| func maxRW2SeriesSizeAfterResymbolization(ts *TimeSeriesRW2, symbols []string, symbolOffset uint32) (seriesSize int, symbolsSize int) { | ||
|
|
||
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
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.
[nit] I don't think there's a way to roll-back a write?
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.
I don't think there's any claim it's possible either, right? It's just clarified they're not going to be undone (rolled back).