-
Notifications
You must be signed in to change notification settings - Fork 611
Add RW2 support #11100
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
Add RW2 support #11100
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4fc7ccd
Add unmarshal benchmark
krajorama 5523a3f
feat(rw2): unmarshal RW1 request from RW2
krajorama f029c1d
test(rw2): enhance distributor integration tests
krajorama 705b352
remove TODO test
krajorama 0ca712c
fix(rw2): fix handling statistics
krajorama bbb59f6
fix(typo): fix wrong docstring
krajorama 264adb1
address review comments
krajorama 6da844c
update expdiff
krajorama bda00c1
followups
krajorama e3c3275
add changelog
krajorama cce29a8
Merge branch 'main' into krajo/wip-rw2-direct
krajorama 944ed6e
update changelog
krajorama 747361b
address review comments
krajorama 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
package mimirpb | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"sync" | ||
) | ||
|
||
// Remote Write 2.0 related variables and functions. | ||
var ( | ||
errorUnexpectedRW1Timeseries = errors.New("proto: Remote Write 1.0 field Timeseries in non-Remote Write 1.0 message") | ||
errorUnexpectedRW1Metadata = errors.New("proto: Remote Write 1.0 field Metadata in non-Remote Write 1.0 message") | ||
errorUnexpectedRW2Timeseries = errors.New("proto: Remote Write 2.0 field Timeseries in non-Remote Write 2.0 message") | ||
errorUnexpectedRW2Symbols = errors.New("proto: Remote Write 2.0 field Symbols in non-Remote Write 2.0 message") | ||
errorOddNumberOfLabelRefs = errors.New("proto: Remote Write 2.0 odd number of label references") | ||
errorOddNumberOfExemplarLabelRefs = errors.New("proto: Remote Write 2.0 odd number of exemplar label references") | ||
errorInvalidLabelRef = errors.New("proto: Remote Write 2.0 invalid label reference") | ||
errorInvalidExemplarLabelRef = errors.New("proto: Remote Write 2.0 invalid exemplar label reference") | ||
errorInternalRW2 = errors.New("proto: Remote Write 2.0 internal error") | ||
errorInvalidHelpRef = errors.New("proto: Remote Write 2.0 invalid help reference") | ||
errorInvalidUnitRef = errors.New("proto: Remote Write 2.0 invalid unit reference") | ||
) | ||
|
||
// rw2SymbolPageSize is the size of each page in bits. | ||
const rw2SymbolPageSize = 16 | ||
|
||
// rw2PagedSymbols is a structure that holds symbols in pages. | ||
// The problem this solves is that protobuf doesn't tell us | ||
// how many symbols there are in advance. Without this paging | ||
// mechanism, we would have to allocate a large amount of memory | ||
// or do reallocation. This is a compromise between the two. | ||
type rw2PagedSymbols struct { | ||
count uint32 | ||
pages [][]string | ||
} | ||
|
||
func (ps *rw2PagedSymbols) append(symbol string) { | ||
nextPage := ps.count >> rw2SymbolPageSize | ||
if int(nextPage) >= len(ps.pages) { | ||
ps.pages = append(ps.pages, rw2PagedSymbolsPool.Get().([]string)) | ||
} | ||
ps.pages[nextPage] = append(ps.pages[nextPage], symbol) | ||
krajorama marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ps.count++ | ||
} | ||
|
||
func (ps *rw2PagedSymbols) releasePages() { | ||
for _, page := range ps.pages { | ||
page = page[:0] | ||
rw2PagedSymbolsPool.Put(page) //nolint:staticcheck | ||
krajorama marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
func (ps *rw2PagedSymbols) get(ref uint32) (string, error) { | ||
if ref < ps.count { | ||
page := ps.pages[ref>>rw2SymbolPageSize] | ||
return page[ref&((1<<rw2SymbolPageSize)-1)], nil | ||
} | ||
return "", fmt.Errorf("symbol reference %d is out of bounds", ref) | ||
} | ||
|
||
var ( | ||
rw2PagedSymbolsPool = sync.Pool{ | ||
New: func() interface{} { | ||
return make([]string, 0, 1<<rw2SymbolPageSize) | ||
}, | ||
} | ||
) |
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.
Uh oh!
There was an error while loading. Please reload this page.