Fix `cortexpb` -> `logproto` rename in some tests (#5231)

* Fix `cortexpg` -> `logproto` rename in some tests

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* Fix TimestampMs rename

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* queryrange test

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* Fix tests on queryrangebase pacakage\

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>

* Fix some typos

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
pull/5232/head
Kaviraj Kanagaraj 3 years ago committed by GitHub
parent f24b84c15a
commit 7713ff78e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      pkg/querier/base/active-query-tracker/queries.active
  2. 13
      pkg/querier/queryrange/queryrangebase/marshaling_test.go
  3. 79
      pkg/querier/queryrange/queryrangebase/query_range_test.go
  4. 58
      pkg/querier/queryrange/queryrangebase/queryable_test.go
  5. 26
      pkg/querier/queryrange/queryrangebase/querysharding_test.go
  6. 24
      pkg/querier/queryrange/queryrangebase/results_cache_test.go
  7. 33
      pkg/querier/queryrange/queryrangebase/series_test.go
  8. 4
      pkg/querier/queryrange/queryrangebase/split_by_interval_test.go
  9. 48
      pkg/querier/queryrange/queryrangebase/value_test.go

@ -8,8 +8,9 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/cortexproject/cortex/pkg/cortexpb"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/loki/pkg/logproto"
) )
func BenchmarkPrometheusCodec_DecodeResponse(b *testing.B) { func BenchmarkPrometheusCodec_DecodeResponse(b *testing.B) {
@ -59,16 +60,16 @@ func mockPrometheusResponse(numSeries, numSamplesPerSeries int) *PrometheusRespo
stream := make([]SampleStream, numSeries) stream := make([]SampleStream, numSeries)
for s := 0; s < numSeries; s++ { for s := 0; s < numSeries; s++ {
// Generate random samples. // Generate random samples.
samples := make([]cortexpb.Sample, numSamplesPerSeries) samples := make([]logproto.Sample, numSamplesPerSeries)
for i := 0; i < numSamplesPerSeries; i++ { for i := 0; i < numSamplesPerSeries; i++ {
samples[i] = cortexpb.Sample{ samples[i] = logproto.Sample{
Value: rand.Float64(), Value: rand.Float64(),
TimestampMs: int64(i), Timestamp: int64(i),
} }
} }
// Generate random labels. // Generate random labels.
lbls := make([]cortexpb.LabelAdapter, 10) lbls := make([]logproto.LabelAdapter, 10)
for i := range lbls { for i := range lbls {
lbls[i].Name = "a_medium_size_label_name" lbls[i].Name = "a_medium_size_label_name"
lbls[i].Value = "a_medium_size_label_value_that_is_used_to_benchmark_marshalling" lbls[i].Value = "a_medium_size_label_value_that_is_used_to_benchmark_marshalling"

@ -8,12 +8,13 @@ import (
"strconv" "strconv"
"testing" "testing"
"github.com/cortexproject/cortex/pkg/cortexpb"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/weaveworks/common/httpgrpc" "github.com/weaveworks/common/httpgrpc"
"github.com/weaveworks/common/user" "github.com/weaveworks/common/user"
"github.com/grafana/loki/pkg/logproto"
) )
func TestRequest(t *testing.T) { func TestRequest(t *testing.T) {
@ -185,10 +186,10 @@ func TestMergeAPIResponses(t *testing.T) {
ResultType: matrix, ResultType: matrix,
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{}, Labels: []logproto.LabelAdapter{},
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{Value: 0, TimestampMs: 0}, {Value: 0, Timestamp: 0},
{Value: 1, TimestampMs: 1}, {Value: 1, Timestamp: 1},
}, },
}, },
}, },
@ -199,10 +200,10 @@ func TestMergeAPIResponses(t *testing.T) {
ResultType: matrix, ResultType: matrix,
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{}, Labels: []logproto.LabelAdapter{},
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{Value: 2, TimestampMs: 2}, {Value: 2, Timestamp: 2},
{Value: 3, TimestampMs: 3}, {Value: 3, Timestamp: 3},
}, },
}, },
}, },
@ -215,12 +216,12 @@ func TestMergeAPIResponses(t *testing.T) {
ResultType: matrix, ResultType: matrix,
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{}, Labels: []logproto.LabelAdapter{},
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{Value: 0, TimestampMs: 0}, {Value: 0, Timestamp: 0},
{Value: 1, TimestampMs: 1}, {Value: 1, Timestamp: 1},
{Value: 2, TimestampMs: 2}, {Value: 2, Timestamp: 2},
{Value: 3, TimestampMs: 3}, {Value: 3, Timestamp: 3},
}, },
}, },
}, },
@ -240,12 +241,12 @@ func TestMergeAPIResponses(t *testing.T) {
ResultType: matrix, ResultType: matrix,
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, Labels: []logproto.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}},
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{Value: 0, TimestampMs: 0}, {Value: 0, Timestamp: 0},
{Value: 1, TimestampMs: 1000}, {Value: 1, Timestamp: 1000},
{Value: 2, TimestampMs: 2000}, {Value: 2, Timestamp: 2000},
{Value: 3, TimestampMs: 3000}, {Value: 3, Timestamp: 3000},
}, },
}, },
}, },
@ -265,11 +266,11 @@ func TestMergeAPIResponses(t *testing.T) {
ResultType: matrix, ResultType: matrix,
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, Labels: []logproto.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}},
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{Value: 1, TimestampMs: 1000}, {Value: 1, Timestamp: 1000},
{Value: 2, TimestampMs: 2000}, {Value: 2, Timestamp: 2000},
{Value: 3, TimestampMs: 3000}, {Value: 3, Timestamp: 3000},
}, },
}, },
}, },
@ -288,13 +289,13 @@ func TestMergeAPIResponses(t *testing.T) {
ResultType: matrix, ResultType: matrix,
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, Labels: []logproto.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}},
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{Value: 1, TimestampMs: 1000}, {Value: 1, Timestamp: 1000},
{Value: 2, TimestampMs: 2000}, {Value: 2, Timestamp: 2000},
{Value: 3, TimestampMs: 3000}, {Value: 3, Timestamp: 3000},
{Value: 4, TimestampMs: 4000}, {Value: 4, Timestamp: 4000},
{Value: 5, TimestampMs: 5000}, {Value: 5, Timestamp: 5000},
}, },
}, },
}, },
@ -313,12 +314,12 @@ func TestMergeAPIResponses(t *testing.T) {
ResultType: matrix, ResultType: matrix,
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}}, Labels: []logproto.LabelAdapter{{Name: "a", Value: "b"}, {Name: "c", Value: "d"}},
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{Value: 2, TimestampMs: 2000}, {Value: 2, Timestamp: 2000},
{Value: 3, TimestampMs: 3000}, {Value: 3, Timestamp: 3000},
{Value: 4, TimestampMs: 4000}, {Value: 4, Timestamp: 4000},
{Value: 5, TimestampMs: 5000}, {Value: 5, Timestamp: 5000},
}, },
}, },
}, },

@ -4,12 +4,12 @@ import (
"context" "context"
"testing" "testing"
"github.com/cortexproject/cortex/pkg/cortexpb"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/promql/parser"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/querier/astmapper" "github.com/grafana/loki/pkg/querier/astmapper"
) )
@ -91,34 +91,34 @@ func TestSelect(t *testing.T) {
ResultType: string(parser.ValueTypeVector), ResultType: string(parser.ValueTypeVector),
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 1, Value: 1,
TimestampMs: 1, Timestamp: 1,
}, },
{ {
Value: 2, Value: 2,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 8, Value: 8,
TimestampMs: 1, Timestamp: 1,
}, },
{ {
Value: 9, Value: 9,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },
@ -141,34 +141,34 @@ func TestSelect(t *testing.T) {
t, t,
NewSeriesSet([]SampleStream{ NewSeriesSet([]SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 1, Value: 1,
TimestampMs: 1, Timestamp: 1,
}, },
{ {
Value: 2, Value: 2,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 8, Value: 8,
TimestampMs: 1, Timestamp: 1,
}, },
{ {
Value: 9, Value: 9,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },
@ -219,13 +219,13 @@ func TestSelectConcurrent(t *testing.T) {
ResultType: string(parser.ValueTypeVector), ResultType: string(parser.ValueTypeVector),
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "1"}, {Name: "a", Value: "1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 1, Value: 1,
TimestampMs: 1, Timestamp: 1,
}, },
}, },
}, },

@ -8,7 +8,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/cortexproject/cortex/pkg/cortexpb"
"github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util"
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -18,6 +17,7 @@ import (
"github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/storage/chunk" "github.com/grafana/loki/pkg/storage/chunk"
) )
@ -122,34 +122,34 @@ func sampleMatrixResponse() *PrometheusResponse {
ResultType: string(parser.ValueTypeMatrix), ResultType: string(parser.ValueTypeMatrix),
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
TimestampMs: 5, Timestamp: 5,
Value: 1, Value: 1,
}, },
{ {
TimestampMs: 10, Timestamp: 10,
Value: 2, Value: 2,
}, },
}, },
}, },
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
TimestampMs: 5, Timestamp: 5,
Value: 8, Value: 8,
}, },
{ {
TimestampMs: 10, Timestamp: 10,
Value: 9, Value: 9,
}, },
}, },
}, },

@ -7,7 +7,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/cortexproject/cortex/pkg/cortexpb"
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/gogo/protobuf/types" "github.com/gogo/protobuf/types"
"github.com/grafana/dskit/flagext" "github.com/grafana/dskit/flagext"
@ -16,6 +15,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/weaveworks/common/user" "github.com/weaveworks/common/user"
"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/storage/chunk/cache" "github.com/grafana/loki/pkg/storage/chunk/cache"
) )
@ -58,12 +58,12 @@ var (
ResultType: model.ValMatrix.String(), ResultType: model.ValMatrix.String(),
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "foo", Value: "bar"}, {Name: "foo", Value: "bar"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{Value: 137, TimestampMs: 1536673680000}, {Value: 137, Timestamp: 1536673680000},
{Value: 137, TimestampMs: 1536673780000}, {Value: 137, Timestamp: 1536673780000},
}, },
}, },
}, },
@ -72,11 +72,11 @@ var (
) )
func mkAPIResponse(start, end, step int64) *PrometheusResponse { func mkAPIResponse(start, end, step int64) *PrometheusResponse {
var samples []cortexpb.Sample var samples []logproto.Sample
for i := start; i <= end; i += step { for i := start; i <= end; i += step {
samples = append(samples, cortexpb.Sample{ samples = append(samples, logproto.Sample{
TimestampMs: i, Timestamp: i,
Value: float64(i), Value: float64(i),
}) })
} }
@ -86,7 +86,7 @@ func mkAPIResponse(start, end, step int64) *PrometheusResponse {
ResultType: matrix, ResultType: matrix,
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "foo", Value: "bar"}, {Name: "foo", Value: "bar"},
}, },
Samples: samples, 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 { type mockCacheGenNumberLoader struct {
} }

@ -3,9 +3,10 @@ package queryrangebase
import ( import (
"testing" "testing"
"github.com/cortexproject/cortex/pkg/cortexpb"
"github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/promql/parser"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/grafana/loki/pkg/logproto"
) )
func Test_ResponseToSamples(t *testing.T) { func Test_ResponseToSamples(t *testing.T) {
@ -14,34 +15,34 @@ func Test_ResponseToSamples(t *testing.T) {
ResultType: string(parser.ValueTypeMatrix), ResultType: string(parser.ValueTypeMatrix),
Result: []SampleStream{ Result: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 1, Value: 1,
TimestampMs: 1, Timestamp: 1,
}, },
{ {
Value: 2, Value: 2,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 8, Value: 8,
TimestampMs: 1, Timestamp: 1,
}, },
{ {
Value: 9, Value: 9,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },
@ -49,9 +50,9 @@ func Test_ResponseToSamples(t *testing.T) {
}, },
} }
streams, err := ResponseToSamples(input) stream, err := ResponseToSamples(input)
require.Nil(t, err) require.Nil(t, err)
set := NewSeriesSet(streams) set := NewSeriesSet(stream)
setCt := 0 setCt := 0
@ -62,7 +63,7 @@ func Test_ResponseToSamples(t *testing.T) {
sampleCt := 0 sampleCt := 0
for iter.Next() { for iter.Next() {
ts, v := iter.At() 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) require.Equal(t, input.Data.Result[setCt].Samples[sampleCt].Value, v)
sampleCt++ sampleCt++
} }

@ -377,3 +377,7 @@ func Test_evaluateAtModifier(t *testing.T) {
}) })
} }
} }
func toMs(t time.Duration) int64 {
return int64(t / time.Millisecond)
}

@ -9,7 +9,7 @@ import (
"github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/promql"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/cortexproject/cortex/pkg/cortexpb" "github.com/grafana/loki/pkg/logproto"
) )
func TestFromValue(t *testing.T) { func TestFromValue(t *testing.T) {
@ -33,10 +33,10 @@ func TestFromValue(t *testing.T) {
err: false, err: false,
expected: []SampleStream{ expected: []SampleStream{
{ {
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 1, Value: 1,
TimestampMs: 1, Timestamp: 1,
}, },
}, },
}, },
@ -65,26 +65,26 @@ func TestFromValue(t *testing.T) {
err: false, err: false,
expected: []SampleStream{ expected: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 1, Value: 1,
TimestampMs: 1, Timestamp: 1,
}, },
}, },
}, },
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a2"}, {Name: "a", Value: "a2"},
{Name: "b", Value: "b2"}, {Name: "b", Value: "b2"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 2, Value: 2,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },
@ -119,34 +119,34 @@ func TestFromValue(t *testing.T) {
err: false, err: false,
expected: []SampleStream{ expected: []SampleStream{
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a1"}, {Name: "a", Value: "a1"},
{Name: "b", Value: "b1"}, {Name: "b", Value: "b1"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 1, Value: 1,
TimestampMs: 1, Timestamp: 1,
}, },
{ {
Value: 2, Value: 2,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },
{ {
Labels: []cortexpb.LabelAdapter{ Labels: []logproto.LabelAdapter{
{Name: "a", Value: "a2"}, {Name: "a", Value: "a2"},
{Name: "b", Value: "b2"}, {Name: "b", Value: "b2"},
}, },
Samples: []cortexpb.Sample{ Samples: []logproto.Sample{
{ {
Value: 8, Value: 8,
TimestampMs: 1, Timestamp: 1,
}, },
{ {
Value: 9, Value: 9,
TimestampMs: 2, Timestamp: 2,
}, },
}, },
}, },

Loading…
Cancel
Save