From 7713ff78e2627b835d1ad73afb3695d25943ebf1 Mon Sep 17 00:00:00 2001 From: Kaviraj Kanagaraj Date: Tue, 25 Jan 2022 14:00:23 +0100 Subject: [PATCH] Fix `cortexpb` -> `logproto` rename in some tests (#5231) * Fix `cortexpg` -> `logproto` rename in some tests Signed-off-by: Kaviraj * Fix TimestampMs rename Signed-off-by: Kaviraj * queryrange test Signed-off-by: Kaviraj * Fix tests on queryrangebase pacakage\ Signed-off-by: Kaviraj * Fix some typos Signed-off-by: Kaviraj --- .../base/active-query-tracker/queries.active | Bin 0 -> 20001 bytes .../queryrangebase/marshaling_test.go | 13 +-- .../queryrangebase/query_range_test.go | 79 +++++++++--------- .../queryrangebase/queryable_test.go | 58 ++++++------- .../queryrangebase/querysharding_test.go | 26 +++--- .../queryrangebase/results_cache_test.go | 24 +++--- .../queryrange/queryrangebase/series_test.go | 33 ++++---- .../queryrangebase/split_by_interval_test.go | 4 + .../queryrange/queryrangebase/value_test.go | 48 +++++------ 9 files changed, 144 insertions(+), 141 deletions(-) create mode 100644 pkg/querier/base/active-query-tracker/queries.active diff --git a/pkg/querier/base/active-query-tracker/queries.active b/pkg/querier/base/active-query-tracker/queries.active new file mode 100644 index 0000000000000000000000000000000000000000..8bfef0eabd49630443efda04a88fc8fb2b6b67bd GIT binary patch literal 20001 zcmeIuu>b%700OW)^Y=)jV?$Vj0RsjM7%*VKfB^#r3>YwAz<>b*1`HT5V8DO@0|pEj zFkrxd0RsjM7%*VKfB^#r3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM7%*VKfB^#r H3|tHh6@UO- literal 0 HcmV?d00001 diff --git a/pkg/querier/queryrange/queryrangebase/marshaling_test.go b/pkg/querier/queryrange/queryrangebase/marshaling_test.go index 955735bcef..0d936b433d 100644 --- a/pkg/querier/queryrange/queryrangebase/marshaling_test.go +++ b/pkg/querier/queryrange/queryrangebase/marshaling_test.go @@ -8,8 +8,9 @@ import ( "net/http" "testing" - "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/stretchr/testify/require" + + "github.com/grafana/loki/pkg/logproto" ) func BenchmarkPrometheusCodec_DecodeResponse(b *testing.B) { @@ -59,16 +60,16 @@ func mockPrometheusResponse(numSeries, numSamplesPerSeries int) *PrometheusRespo stream := make([]SampleStream, numSeries) for s := 0; s < numSeries; s++ { // Generate random samples. - samples := make([]cortexpb.Sample, numSamplesPerSeries) + samples := make([]logproto.Sample, numSamplesPerSeries) for i := 0; i < numSamplesPerSeries; i++ { - samples[i] = cortexpb.Sample{ - Value: rand.Float64(), - TimestampMs: int64(i), + samples[i] = logproto.Sample{ + Value: rand.Float64(), + Timestamp: int64(i), } } // Generate random labels. - lbls := make([]cortexpb.LabelAdapter, 10) + lbls := make([]logproto.LabelAdapter, 10) for i := range lbls { lbls[i].Name = "a_medium_size_label_name" lbls[i].Value = "a_medium_size_label_value_that_is_used_to_benchmark_marshalling" diff --git a/pkg/querier/queryrange/queryrangebase/query_range_test.go b/pkg/querier/queryrange/queryrangebase/query_range_test.go index 09c55ffd77..81b7f81595 100644 --- a/pkg/querier/queryrange/queryrangebase/query_range_test.go +++ b/pkg/querier/queryrange/queryrangebase/query_range_test.go @@ -8,12 +8,13 @@ import ( "strconv" "testing" - "github.com/cortexproject/cortex/pkg/cortexpb" jsoniter "github.com/json-iterator/go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/weaveworks/common/httpgrpc" "github.com/weaveworks/common/user" + + "github.com/grafana/loki/pkg/logproto" ) func TestRequest(t *testing.T) { @@ -185,10 +186,10 @@ func TestMergeAPIResponses(t *testing.T) { ResultType: matrix, Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{}, - Samples: []cortexpb.Sample{ - {Value: 0, TimestampMs: 0}, - {Value: 1, TimestampMs: 1}, + Labels: []logproto.LabelAdapter{}, + Samples: []logproto.Sample{ + {Value: 0, Timestamp: 0}, + {Value: 1, Timestamp: 1}, }, }, }, @@ -199,10 +200,10 @@ func TestMergeAPIResponses(t *testing.T) { ResultType: matrix, Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{}, - Samples: []cortexpb.Sample{ - {Value: 2, TimestampMs: 2}, - {Value: 3, TimestampMs: 3}, + Labels: []logproto.LabelAdapter{}, + Samples: []logproto.Sample{ + {Value: 2, Timestamp: 2}, + {Value: 3, Timestamp: 3}, }, }, }, @@ -215,12 +216,12 @@ func TestMergeAPIResponses(t *testing.T) { ResultType: matrix, Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{}, - Samples: []cortexpb.Sample{ - {Value: 0, TimestampMs: 0}, - {Value: 1, TimestampMs: 1}, - {Value: 2, TimestampMs: 2}, - {Value: 3, TimestampMs: 3}, + Labels: []logproto.LabelAdapter{}, + Samples: []logproto.Sample{ + {Value: 0, Timestamp: 0}, + {Value: 1, Timestamp: 1}, + {Value: 2, Timestamp: 2}, + {Value: 3, Timestamp: 3}, }, }, }, @@ -240,12 +241,12 @@ func TestMergeAPIResponses(t *testing.T) { ResultType: matrix, Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, - Samples: []cortexpb.Sample{ - {Value: 0, TimestampMs: 0}, - {Value: 1, TimestampMs: 1000}, - {Value: 2, TimestampMs: 2000}, - {Value: 3, TimestampMs: 3000}, + Labels: []logproto.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, + Samples: []logproto.Sample{ + {Value: 0, Timestamp: 0}, + {Value: 1, Timestamp: 1000}, + {Value: 2, Timestamp: 2000}, + {Value: 3, Timestamp: 3000}, }, }, }, @@ -265,11 +266,11 @@ func TestMergeAPIResponses(t *testing.T) { ResultType: matrix, Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, - Samples: []cortexpb.Sample{ - {Value: 1, TimestampMs: 1000}, - {Value: 2, TimestampMs: 2000}, - {Value: 3, TimestampMs: 3000}, + Labels: []logproto.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, + Samples: []logproto.Sample{ + {Value: 1, Timestamp: 1000}, + {Value: 2, Timestamp: 2000}, + {Value: 3, Timestamp: 3000}, }, }, }, @@ -288,13 +289,13 @@ func TestMergeAPIResponses(t *testing.T) { ResultType: matrix, Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, - Samples: []cortexpb.Sample{ - {Value: 1, TimestampMs: 1000}, - {Value: 2, TimestampMs: 2000}, - {Value: 3, TimestampMs: 3000}, - {Value: 4, TimestampMs: 4000}, - {Value: 5, TimestampMs: 5000}, + Labels: []logproto.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, + Samples: []logproto.Sample{ + {Value: 1, Timestamp: 1000}, + {Value: 2, Timestamp: 2000}, + {Value: 3, Timestamp: 3000}, + {Value: 4, Timestamp: 4000}, + {Value: 5, Timestamp: 5000}, }, }, }, @@ -313,12 +314,12 @@ func TestMergeAPIResponses(t *testing.T) { ResultType: matrix, Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, - Samples: []cortexpb.Sample{ - {Value: 2, TimestampMs: 2000}, - {Value: 3, TimestampMs: 3000}, - {Value: 4, TimestampMs: 4000}, - {Value: 5, TimestampMs: 5000}, + Labels: []logproto.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, + Samples: []logproto.Sample{ + {Value: 2, Timestamp: 2000}, + {Value: 3, Timestamp: 3000}, + {Value: 4, Timestamp: 4000}, + {Value: 5, Timestamp: 5000}, }, }, }, diff --git a/pkg/querier/queryrange/queryrangebase/queryable_test.go b/pkg/querier/queryrange/queryrangebase/queryable_test.go index ed1de014bf..b0193a86c4 100644 --- a/pkg/querier/queryrange/queryrangebase/queryable_test.go +++ b/pkg/querier/queryrange/queryrangebase/queryable_test.go @@ -4,12 +4,12 @@ import ( "context" "testing" - "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/pkg/errors" "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/promql/parser" "github.com/stretchr/testify/require" + "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/querier/astmapper" ) @@ -91,34 +91,34 @@ func TestSelect(t *testing.T) { ResultType: string(parser.ValueTypeVector), Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 1, - TimestampMs: 1, + Value: 1, + Timestamp: 1, }, { - Value: 2, - TimestampMs: 2, + Value: 2, + Timestamp: 2, }, }, }, { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 8, - TimestampMs: 1, + Value: 8, + Timestamp: 1, }, { - Value: 9, - TimestampMs: 2, + Value: 9, + Timestamp: 2, }, }, }, @@ -141,34 +141,34 @@ func TestSelect(t *testing.T) { t, NewSeriesSet([]SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 1, - TimestampMs: 1, + Value: 1, + Timestamp: 1, }, { - Value: 2, - TimestampMs: 2, + Value: 2, + Timestamp: 2, }, }, }, { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 8, - TimestampMs: 1, + Value: 8, + Timestamp: 1, }, { - Value: 9, - TimestampMs: 2, + Value: 9, + Timestamp: 2, }, }, }, @@ -219,13 +219,13 @@ func TestSelectConcurrent(t *testing.T) { ResultType: string(parser.ValueTypeVector), Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 1, - TimestampMs: 1, + Value: 1, + Timestamp: 1, }, }, }, diff --git a/pkg/querier/queryrange/queryrangebase/querysharding_test.go b/pkg/querier/queryrange/queryrangebase/querysharding_test.go index b32a8351c7..3617ce70d0 100644 --- a/pkg/querier/queryrange/queryrangebase/querysharding_test.go +++ b/pkg/querier/queryrange/queryrangebase/querysharding_test.go @@ -8,7 +8,6 @@ import ( "testing" "time" - "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/cortexproject/cortex/pkg/util" "github.com/go-kit/log" "github.com/pkg/errors" @@ -18,6 +17,7 @@ import ( "github.com/prometheus/prometheus/storage" "github.com/stretchr/testify/require" + "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/storage/chunk" ) @@ -122,34 +122,34 @@ func sampleMatrixResponse() *PrometheusResponse { ResultType: string(parser.ValueTypeMatrix), Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - TimestampMs: 5, - Value: 1, + Timestamp: 5, + Value: 1, }, { - TimestampMs: 10, - Value: 2, + Timestamp: 10, + Value: 2, }, }, }, { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - TimestampMs: 5, - Value: 8, + Timestamp: 5, + Value: 8, }, { - TimestampMs: 10, - Value: 9, + Timestamp: 10, + Value: 9, }, }, }, diff --git a/pkg/querier/queryrange/queryrangebase/results_cache_test.go b/pkg/querier/queryrange/queryrangebase/results_cache_test.go index 75756b3b06..8296c6b978 100644 --- a/pkg/querier/queryrange/queryrangebase/results_cache_test.go +++ b/pkg/querier/queryrange/queryrangebase/results_cache_test.go @@ -7,7 +7,6 @@ import ( "testing" "time" - "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/go-kit/log" "github.com/gogo/protobuf/types" "github.com/grafana/dskit/flagext" @@ -16,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/weaveworks/common/user" + "github.com/grafana/loki/pkg/logproto" "github.com/grafana/loki/pkg/storage/chunk/cache" ) @@ -58,12 +58,12 @@ var ( ResultType: model.ValMatrix.String(), Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "foo", Value: "bar"}, }, - Samples: []cortexpb.Sample{ - {Value: 137, TimestampMs: 1536673680000}, - {Value: 137, TimestampMs: 1536673780000}, + Samples: []logproto.Sample{ + {Value: 137, Timestamp: 1536673680000}, + {Value: 137, Timestamp: 1536673780000}, }, }, }, @@ -72,11 +72,11 @@ var ( ) func mkAPIResponse(start, end, step int64) *PrometheusResponse { - var samples []cortexpb.Sample + var samples []logproto.Sample for i := start; i <= end; i += step { - samples = append(samples, cortexpb.Sample{ - TimestampMs: i, - Value: float64(i), + samples = append(samples, logproto.Sample{ + Timestamp: i, + Value: float64(i), }) } @@ -86,7 +86,7 @@ func mkAPIResponse(start, end, step int64) *PrometheusResponse { ResultType: matrix, Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "foo", Value: "bar"}, }, Samples: samples, @@ -1024,10 +1024,6 @@ func TestResultsCacheShouldCacheFunc(t *testing.T) { } } -func toMs(t time.Duration) int64 { - return int64(t / time.Millisecond) -} - type mockCacheGenNumberLoader struct { } diff --git a/pkg/querier/queryrange/queryrangebase/series_test.go b/pkg/querier/queryrange/queryrangebase/series_test.go index 728e0f01b7..539f610736 100644 --- a/pkg/querier/queryrange/queryrangebase/series_test.go +++ b/pkg/querier/queryrange/queryrangebase/series_test.go @@ -3,9 +3,10 @@ package queryrangebase import ( "testing" - "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/prometheus/prometheus/promql/parser" "github.com/stretchr/testify/require" + + "github.com/grafana/loki/pkg/logproto" ) func Test_ResponseToSamples(t *testing.T) { @@ -14,34 +15,34 @@ func Test_ResponseToSamples(t *testing.T) { ResultType: string(parser.ValueTypeMatrix), Result: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 1, - TimestampMs: 1, + Value: 1, + Timestamp: 1, }, { - Value: 2, - TimestampMs: 2, + Value: 2, + Timestamp: 2, }, }, }, { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 8, - TimestampMs: 1, + Value: 8, + Timestamp: 1, }, { - Value: 9, - TimestampMs: 2, + Value: 9, + Timestamp: 2, }, }, }, @@ -49,9 +50,9 @@ func Test_ResponseToSamples(t *testing.T) { }, } - streams, err := ResponseToSamples(input) + stream, err := ResponseToSamples(input) require.Nil(t, err) - set := NewSeriesSet(streams) + set := NewSeriesSet(stream) setCt := 0 @@ -62,7 +63,7 @@ func Test_ResponseToSamples(t *testing.T) { sampleCt := 0 for iter.Next() { ts, v := iter.At() - require.Equal(t, input.Data.Result[setCt].Samples[sampleCt].TimestampMs, ts) + require.Equal(t, input.Data.Result[setCt].Samples[sampleCt].Timestamp, ts) require.Equal(t, input.Data.Result[setCt].Samples[sampleCt].Value, v) sampleCt++ } diff --git a/pkg/querier/queryrange/queryrangebase/split_by_interval_test.go b/pkg/querier/queryrange/queryrangebase/split_by_interval_test.go index 03c8050a9d..f59f560f40 100644 --- a/pkg/querier/queryrange/queryrangebase/split_by_interval_test.go +++ b/pkg/querier/queryrange/queryrangebase/split_by_interval_test.go @@ -377,3 +377,7 @@ func Test_evaluateAtModifier(t *testing.T) { }) } } + +func toMs(t time.Duration) int64 { + return int64(t / time.Millisecond) +} diff --git a/pkg/querier/queryrange/queryrangebase/value_test.go b/pkg/querier/queryrange/queryrangebase/value_test.go index ffaed937ba..ca8f4759e4 100644 --- a/pkg/querier/queryrange/queryrangebase/value_test.go +++ b/pkg/querier/queryrange/queryrangebase/value_test.go @@ -9,7 +9,7 @@ import ( "github.com/prometheus/prometheus/promql" "github.com/stretchr/testify/require" - "github.com/cortexproject/cortex/pkg/cortexpb" + "github.com/grafana/loki/pkg/logproto" ) func TestFromValue(t *testing.T) { @@ -33,10 +33,10 @@ func TestFromValue(t *testing.T) { err: false, expected: []SampleStream{ { - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 1, - TimestampMs: 1, + Value: 1, + Timestamp: 1, }, }, }, @@ -65,26 +65,26 @@ func TestFromValue(t *testing.T) { err: false, expected: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 1, - TimestampMs: 1, + Value: 1, + Timestamp: 1, }, }, }, { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a2"}, {Name: "b", Value: "b2"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 2, - TimestampMs: 2, + Value: 2, + Timestamp: 2, }, }, }, @@ -119,34 +119,34 @@ func TestFromValue(t *testing.T) { err: false, expected: []SampleStream{ { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a1"}, {Name: "b", Value: "b1"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 1, - TimestampMs: 1, + Value: 1, + Timestamp: 1, }, { - Value: 2, - TimestampMs: 2, + Value: 2, + Timestamp: 2, }, }, }, { - Labels: []cortexpb.LabelAdapter{ + Labels: []logproto.LabelAdapter{ {Name: "a", Value: "a2"}, {Name: "b", Value: "b2"}, }, - Samples: []cortexpb.Sample{ + Samples: []logproto.Sample{ { - Value: 8, - TimestampMs: 1, + Value: 8, + Timestamp: 1, }, { - Value: 9, - TimestampMs: 2, + Value: 9, + Timestamp: 2, }, }, },