Skip to content

Commit 5f5c451

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 5f5c451

File tree

5 files changed

+2078
-211
lines changed

5 files changed

+2078
-211
lines changed

pkg/mimirpb/compat_rw2_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
// Tests related to Prometheus Remote Write v2 (RW2) compatibility.
18+
19+
func TestRW2TypesCompatible(t *testing.T) {
20+
expectedType := reflect.TypeOf(rw2.Request{})
21+
actualType := reflect.TypeOf(WriteRequestRW2{})
22+
23+
expectedTree := treeprint.NewWithRoot("<root>")
24+
// We ignore the XXX_ fields because RW2 in Prometheus has them,
25+
// but we don't. Which also means that the offsets would be different.
26+
// But we are not going to cast between the two types, so offsets
27+
// don't matter.
28+
test.AddTypeToTree(expectedType, expectedTree, false, true, true)
29+
30+
actualTree := treeprint.NewWithRoot("<root>")
31+
test.AddTypeToTree(actualType, actualTree, false, true, true)
32+
33+
// mimirpb.Sample fields order MUST match promql.FPoint so that we can
34+
// cast types between them. However this makes test.RequireSameShape
35+
// fail because the order is different.
36+
// So we need to reverse the order of the fields in the tree.
37+
// Also the name of the Timestamp field is slightly different in the
38+
// two types.
39+
var firstValue, secondValue string
40+
rootNode, _ := actualTree.(*treeprint.Node)
41+
firstValue, _ = rootNode.Nodes[1].Nodes[1].Nodes[0].Value.(string)
42+
secondValue, _ = rootNode.Nodes[1].Nodes[1].Nodes[1].Value.(string)
43+
rootNode.Nodes[1].Nodes[1].Nodes[0].Value = secondValue
44+
rootNode.Nodes[1].Nodes[1].Nodes[1].Value = strings.ReplaceAll(firstValue, "TimestampMs", "Timestamp")
45+
46+
require.Equal(t, expectedTree.String(), actualTree.String(), "Proto types are not compatible")
47+
}

0 commit comments

Comments
 (0)