Skip to content

Commit 2d996c2

Browse files
committed
move RW2 fields into RW1 proto for direct unmarshal
Add field to differentiate what we unmarshal and add basic protection against unmarshal fields from the wrong verison. Signed-off-by: György Krajcsovits <[email protected]>
1 parent 6be5706 commit 2d996c2

File tree

4 files changed

+398
-273
lines changed

4 files changed

+398
-273
lines changed

pkg/mimirpb/compat_rw2.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
3+
package mimirpb
4+
5+
import (
6+
"errors"
7+
"fmt"
8+
)
9+
10+
// Remote Write 2.0 related variables and functions.
11+
var (
12+
unexpectedRW1TimeseriesError = errors.New("proto: Remote Write 1.0 field Timeseries in non-Remote Write 1.0 message")
13+
unexpectedRW1MetadataError = errors.New("proto: Remote Write 1.0 field Metadata in non-Remote Write 1.0 message")
14+
unexpectedRW2TimeseriesError = errors.New("proto: Remote Write 2.0 field Timeseries in non-Remote Write 2.0 message")
15+
unexpectedRW2SymbolsError = errors.New("proto: Remote Write 2.0 field Symbols in non-Remote Write 2.0 message")
16+
oddNumberOfLabelRefsError = errors.New("proto: Remote Write 2.0 odd number of label references")
17+
invalidLabelRefError = errors.New("proto: Remote Write 2.0 invalid label reference")
18+
internalRW2Error = errors.New("proto: Remote Write 2.0 internal error")
19+
)
20+
21+
// getRW2Symbol resolves the symbol reference to a string.
22+
func getRW2Symbol(ref uint32, symbols []string) (string, error) {
23+
if ref < uint32(len(symbols)) {
24+
return symbols[ref], nil
25+
}
26+
return "", fmt.Errorf("symbol reference %d is out of bounds", ref)
27+
}

0 commit comments

Comments
 (0)