Skip to content

Commit f8cdc7e

Browse files
committed
feat(rw2): prepare for RW2 support
Add the RW2 proto definition to mimirpb. The implementation will follow but it needs to patch the generated files, so we commit the proto now to have actually readable diff in the PR that has the functionality. See #10423 and especially #11100 diff. Signed-off-by: György Krajcsovits <[email protected]>
1 parent 4f172ba commit f8cdc7e

File tree

5 files changed

+2076
-211
lines changed

5 files changed

+2076
-211
lines changed

pkg/mimirpb/compat_rw2_test.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
3+
package mimirpb
4+
5+
import (
6+
"reflect"
7+
"strings"
8+
"testing"
9+
10+
rw2 "github.com/prometheus/prometheus/prompb/io/prometheus/write/v2"
11+
"github.com/stretchr/testify/require"
12+
"github.com/xlab/treeprint"
13+
14+
"github.com/grafana/mimir/pkg/util/test"
15+
)
16+
17+
func TestRW2TypesCompatible(t *testing.T) {
18+
expectedType := reflect.TypeOf(rw2.Request{})
19+
actualType := reflect.TypeOf(WriteRequestRW2{})
20+
21+
expectedTree := treeprint.NewWithRoot("<root>")
22+
// We ignore the XXX_ fields because RW2 in Promtheus has them,
23+
// but we don't. Which also means that the offsets would be different.
24+
// But we are not going to cast between the two types, so offsets
25+
// don't matter.
26+
test.AddTypeToTree(expectedType, expectedTree, false, true, true)
27+
28+
actualTree := treeprint.NewWithRoot("<root>")
29+
test.AddTypeToTree(actualType, actualTree, false, true, true)
30+
31+
// mimirpb.Sample fields order MUST match promql.FPoint so that we can
32+
// cast types between them. However this makes test.RequireSameShape
33+
// fail because the order is different.
34+
// So we need to reverse the order of the fields in the tree.
35+
// Also the name of the Timestamp field is slightly different in the
36+
// two types.
37+
var firstValue, secondValue string
38+
rootNode, _ := actualTree.(*treeprint.Node)
39+
firstValue, _ = rootNode.Nodes[1].Nodes[1].Nodes[0].Value.(string)
40+
secondValue, _ = rootNode.Nodes[1].Nodes[1].Nodes[1].Value.(string)
41+
rootNode.Nodes[1].Nodes[1].Nodes[0].Value = secondValue
42+
rootNode.Nodes[1].Nodes[1].Nodes[1].Value = strings.ReplaceAll(firstValue, "TimestampMs", "Timestamp")
43+
44+
require.Equal(t, expectedTree.String(), actualTree.String(), "Proto types are not compatible")
45+
}

0 commit comments

Comments
 (0)