From 2c96cb629ccd4dc8cdf3a2efc4dcb90cc0040dfa Mon Sep 17 00:00:00 2001 From: Junang Li Date: Sat, 14 Sep 2024 11:46:22 -0400 Subject: [PATCH] WIP --- prompb/io/prometheus/write/v2/custom_test.go | 2 +- .../prometheusremotewrite/helper_test.go | 9 +++- .../prometheusremotewrite/histograms_test.go | 44 +++++++++---------- .../number_data_points_test.go | 4 +- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/prompb/io/prometheus/write/v2/custom_test.go b/prompb/io/prometheus/write/v2/custom_test.go index d565461ec8..3e0a8fce60 100644 --- a/prompb/io/prometheus/write/v2/custom_test.go +++ b/prompb/io/prometheus/write/v2/custom_test.go @@ -50,7 +50,7 @@ func TestOptimizedMarshal(t *testing.T) { { LabelsRefs: []uint32{ 0, 1, - 2, 3, + 2, 3, 4, 5, 6, 7, 8, 9, diff --git a/storage/remote/otlptranslator/prometheusremotewrite/helper_test.go b/storage/remote/otlptranslator/prometheusremotewrite/helper_test.go index fe8f5435bf..26a2c90d3f 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/helper_test.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/helper_test.go @@ -18,6 +18,7 @@ package prometheusremotewrite import ( "context" + "sort" "testing" "time" @@ -165,8 +166,14 @@ func TestCreateAttributes(t *testing.T) { PromoteResourceAttributes: tc.promoteResourceAttributes, } 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 { + require.Equal(t, &tc.expectedLabels[i], lbls[i]) require.True(t, proto.Equal(lbls[i], &tc.expectedLabels[i])) } }) diff --git a/storage/remote/otlptranslator/prometheusremotewrite/histograms_test.go b/storage/remote/otlptranslator/prometheusremotewrite/histograms_test.go index 492a006cfc..ad7e2b5af7 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/histograms_test.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/histograms_test.go @@ -33,7 +33,7 @@ import ( ) type expectedBucketLayout struct { - wantSpans []prompb.BucketSpan + wantSpans []*prompb.BucketSpan wantDeltas []int64 } @@ -53,7 +53,7 @@ func TestConvertBucketsLayout(t *testing.T) { }, wantLayout: map[int32]expectedBucketLayout{ 0: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 1, Length: 4, @@ -62,7 +62,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{4, -1, -1, -1}, }, 1: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 1, Length: 2, @@ -72,7 +72,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{7, -4}, }, 2: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 1, Length: 1, @@ -93,7 +93,7 @@ func TestConvertBucketsLayout(t *testing.T) { }, wantLayout: map[int32]expectedBucketLayout{ 0: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 2, Length: 4, @@ -102,7 +102,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{4, -1, -1, -1}, }, 1: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 1, 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 }, 2: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 1, Length: 2, @@ -131,7 +131,7 @@ func TestConvertBucketsLayout(t *testing.T) { }, wantLayout: map[int32]expectedBucketLayout{ 0: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 5, Length: 4, @@ -144,7 +144,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{4, -2, -2, 2, -1}, }, 1: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 3, Length: 2, @@ -159,7 +159,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{6, -4, -1}, }, 2: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 2, Length: 1, @@ -186,7 +186,7 @@ func TestConvertBucketsLayout(t *testing.T) { }, wantLayout: map[int32]expectedBucketLayout{ 0: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 5, Length: 4, @@ -199,7 +199,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{4, -2, -2, 2, -1}, }, 1: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 3, Length: 2, @@ -214,7 +214,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{6, -4, -1}, }, 2: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 2, Length: 4, @@ -237,7 +237,7 @@ func TestConvertBucketsLayout(t *testing.T) { }, wantLayout: map[int32]expectedBucketLayout{ 0: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: -1, Length: 2, @@ -250,7 +250,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{3, -2, 0}, }, 1: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 0, Length: 3, @@ -261,7 +261,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{4, -4, 1}, }, 2: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 0, Length: 2, @@ -283,7 +283,7 @@ func TestConvertBucketsLayout(t *testing.T) { }, wantLayout: map[int32]expectedBucketLayout{ 0: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: -1, Length: 6, @@ -292,7 +292,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{3, -2, -1, 1, -1, 1}, }, 1: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 0, Length: 3, @@ -303,7 +303,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{4, -3, 0}, }, 2: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 0, Length: 2, @@ -325,7 +325,7 @@ func TestConvertBucketsLayout(t *testing.T) { }, wantLayout: map[int32]expectedBucketLayout{ 0: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: -1, Length: 7, @@ -334,7 +334,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{3, -3, 0, 1, -1, 0, 1}, }, 1: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 0, Length: 4, @@ -345,7 +345,7 @@ func TestConvertBucketsLayout(t *testing.T) { wantDeltas: []int64{3, -2, -1, 1}, }, 2: { - wantSpans: []prompb.BucketSpan{ + wantSpans: []*prompb.BucketSpan{ { Offset: 0, Length: 3, diff --git a/storage/remote/otlptranslator/prometheusremotewrite/number_data_points_test.go b/storage/remote/otlptranslator/prometheusremotewrite/number_data_points_test.go index 5ba5f260ac..d00c56ab95 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/number_data_points_test.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/number_data_points_test.go @@ -18,6 +18,7 @@ package prometheusremotewrite import ( "context" + "fmt" "testing" "time" @@ -253,7 +254,8 @@ func TestPrometheusConverter_addSumNumberDataPoints(t *testing.T) { }, metric.Name(), ) - + fmt.Println(tt.want()) + fmt.Println(converter.unique) assert.Equal(t, tt.want(), converter.unique) assert.Empty(t, converter.conflicts) })