This commit is contained in:
Junang Li 2024-09-14 11:46:22 -04:00
parent b1096fe71b
commit 2c96cb629c
4 changed files with 34 additions and 25 deletions

View file

@ -50,7 +50,7 @@ func TestOptimizedMarshal(t *testing.T) {
{ {
LabelsRefs: []uint32{ LabelsRefs: []uint32{
0, 1, 0, 1,
2, 3, 2, 3,
4, 5, 4, 5,
6, 7, 6, 7,
8, 9, 8, 9,

View file

@ -18,6 +18,7 @@ package prometheusremotewrite
import ( import (
"context" "context"
"sort"
"testing" "testing"
"time" "time"
@ -165,8 +166,14 @@ func TestCreateAttributes(t *testing.T) {
PromoteResourceAttributes: tc.promoteResourceAttributes, PromoteResourceAttributes: tc.promoteResourceAttributes,
} }
lbls := createAttributes(resource, attrs, settings, nil, false) lbls := createAttributes(resource, attrs, settings, nil, false)
sort.Slice(lbls, func(i, j int) bool {
return lbls[i].Name < lbls[j].Name
})
sort.Slice(tc.expectedLabels, func(i, j int) bool {
return tc.expectedLabels[i].Name < tc.expectedLabels[j].Name
})
for i := range lbls { for i := range lbls {
require.Equal(t, &tc.expectedLabels[i], lbls[i])
require.True(t, proto.Equal(lbls[i], &tc.expectedLabels[i])) require.True(t, proto.Equal(lbls[i], &tc.expectedLabels[i]))
} }
}) })

View file

@ -33,7 +33,7 @@ import (
) )
type expectedBucketLayout struct { type expectedBucketLayout struct {
wantSpans []prompb.BucketSpan wantSpans []*prompb.BucketSpan
wantDeltas []int64 wantDeltas []int64
} }
@ -53,7 +53,7 @@ func TestConvertBucketsLayout(t *testing.T) {
}, },
wantLayout: map[int32]expectedBucketLayout{ wantLayout: map[int32]expectedBucketLayout{
0: { 0: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 1, Offset: 1,
Length: 4, Length: 4,
@ -62,7 +62,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{4, -1, -1, -1}, wantDeltas: []int64{4, -1, -1, -1},
}, },
1: { 1: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 1, Offset: 1,
Length: 2, Length: 2,
@ -72,7 +72,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{7, -4}, wantDeltas: []int64{7, -4},
}, },
2: { 2: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 1, Offset: 1,
Length: 1, Length: 1,
@ -93,7 +93,7 @@ func TestConvertBucketsLayout(t *testing.T) {
}, },
wantLayout: map[int32]expectedBucketLayout{ wantLayout: map[int32]expectedBucketLayout{
0: { 0: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 2, Offset: 2,
Length: 4, Length: 4,
@ -102,7 +102,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{4, -1, -1, -1}, wantDeltas: []int64{4, -1, -1, -1},
}, },
1: { 1: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 1, Offset: 1,
Length: 3, Length: 3,
@ -111,7 +111,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{4, 1, -4}, // 0+4, 3+2, 1+0 = 4, 5, 1 wantDeltas: []int64{4, 1, -4}, // 0+4, 3+2, 1+0 = 4, 5, 1
}, },
2: { 2: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 1, Offset: 1,
Length: 2, Length: 2,
@ -131,7 +131,7 @@ func TestConvertBucketsLayout(t *testing.T) {
}, },
wantLayout: map[int32]expectedBucketLayout{ wantLayout: map[int32]expectedBucketLayout{
0: { 0: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 5, Offset: 5,
Length: 4, Length: 4,
@ -144,7 +144,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{4, -2, -2, 2, -1}, wantDeltas: []int64{4, -2, -2, 2, -1},
}, },
1: { 1: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 3, Offset: 3,
Length: 2, Length: 2,
@ -159,7 +159,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{6, -4, -1}, wantDeltas: []int64{6, -4, -1},
}, },
2: { 2: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 2, Offset: 2,
Length: 1, Length: 1,
@ -186,7 +186,7 @@ func TestConvertBucketsLayout(t *testing.T) {
}, },
wantLayout: map[int32]expectedBucketLayout{ wantLayout: map[int32]expectedBucketLayout{
0: { 0: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 5, Offset: 5,
Length: 4, Length: 4,
@ -199,7 +199,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{4, -2, -2, 2, -1}, wantDeltas: []int64{4, -2, -2, 2, -1},
}, },
1: { 1: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 3, Offset: 3,
Length: 2, Length: 2,
@ -214,7 +214,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{6, -4, -1}, wantDeltas: []int64{6, -4, -1},
}, },
2: { 2: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 2, Offset: 2,
Length: 4, Length: 4,
@ -237,7 +237,7 @@ func TestConvertBucketsLayout(t *testing.T) {
}, },
wantLayout: map[int32]expectedBucketLayout{ wantLayout: map[int32]expectedBucketLayout{
0: { 0: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: -1, Offset: -1,
Length: 2, Length: 2,
@ -250,7 +250,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{3, -2, 0}, wantDeltas: []int64{3, -2, 0},
}, },
1: { 1: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 0, Offset: 0,
Length: 3, Length: 3,
@ -261,7 +261,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{4, -4, 1}, wantDeltas: []int64{4, -4, 1},
}, },
2: { 2: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 0, Offset: 0,
Length: 2, Length: 2,
@ -283,7 +283,7 @@ func TestConvertBucketsLayout(t *testing.T) {
}, },
wantLayout: map[int32]expectedBucketLayout{ wantLayout: map[int32]expectedBucketLayout{
0: { 0: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: -1, Offset: -1,
Length: 6, Length: 6,
@ -292,7 +292,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{3, -2, -1, 1, -1, 1}, wantDeltas: []int64{3, -2, -1, 1, -1, 1},
}, },
1: { 1: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 0, Offset: 0,
Length: 3, Length: 3,
@ -303,7 +303,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{4, -3, 0}, wantDeltas: []int64{4, -3, 0},
}, },
2: { 2: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 0, Offset: 0,
Length: 2, Length: 2,
@ -325,7 +325,7 @@ func TestConvertBucketsLayout(t *testing.T) {
}, },
wantLayout: map[int32]expectedBucketLayout{ wantLayout: map[int32]expectedBucketLayout{
0: { 0: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: -1, Offset: -1,
Length: 7, Length: 7,
@ -334,7 +334,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{3, -3, 0, 1, -1, 0, 1}, wantDeltas: []int64{3, -3, 0, 1, -1, 0, 1},
}, },
1: { 1: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 0, Offset: 0,
Length: 4, Length: 4,
@ -345,7 +345,7 @@ func TestConvertBucketsLayout(t *testing.T) {
wantDeltas: []int64{3, -2, -1, 1}, wantDeltas: []int64{3, -2, -1, 1},
}, },
2: { 2: {
wantSpans: []prompb.BucketSpan{ wantSpans: []*prompb.BucketSpan{
{ {
Offset: 0, Offset: 0,
Length: 3, Length: 3,

View file

@ -18,6 +18,7 @@ package prometheusremotewrite
import ( import (
"context" "context"
"fmt"
"testing" "testing"
"time" "time"
@ -253,7 +254,8 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) {
}, },
metric.Name(), metric.Name(),
) )
fmt.Println(tt.want())
fmt.Println(converter.unique)
assert.Equal(t, tt.want(), converter.unique) assert.Equal(t, tt.want(), converter.unique)
assert.Empty(t, converter.conflicts) assert.Empty(t, converter.conflicts)
}) })