diff --git a/pkg/cortex/modules_test.go b/pkg/cortex/modules_test.go index ae5fc64582e..2cf79132cb2 100644 --- a/pkg/cortex/modules_test.go +++ b/pkg/cortex/modules_test.go @@ -13,7 +13,6 @@ import ( "github.com/weaveworks/common/server" "github.com/cortexproject/cortex/pkg/cortexpb" - "github.com/cortexproject/cortex/pkg/cortexpbv2" ) func changeTargetConfig(c *Config) { @@ -161,7 +160,7 @@ func TestCortex_InitRulerStorage(t *testing.T) { type myPusher struct{} -func (p *myPusher) PushV2(ctx context.Context, req *cortexpbv2.WriteRequest) (*cortexpbv2.WriteResponse, error) { +func (p *myPusher) PushV2(ctx context.Context, req *cortexpb.WriteRequestV2) (*cortexpb.WriteResponseV2, error) { return nil, nil } diff --git a/pkg/cortexpb/cortex.proto b/pkg/cortexpb/cortex.proto index b16074c007a..c7b1209503a 100644 --- a/pkg/cortexpb/cortex.proto +++ b/pkg/cortexpb/cortex.proto @@ -28,7 +28,7 @@ enum MetricType { // https://github.com/prometheus/prometheus/blob/main/prompb/io/prometheus/write/v2/types.proto message WriteRequestV2 { reserved 1 to 2; - cortexpb.SourceEnum Source = 3; + SourceEnum Source = 3; repeated string symbols = 4; repeated TimeSeriesV2 timeseries = 5 [(gogoproto.nullable) = false, (gogoproto.customtype) = "PreallocTimeseriesV2"]; diff --git a/pkg/cortexpb/slicesPool.go b/pkg/cortexpb/slicesPool.go index eaace237ce3..e28d51d4f23 100644 --- a/pkg/cortexpb/slicesPool.go +++ b/pkg/cortexpb/slicesPool.go @@ -13,7 +13,7 @@ type byteSlicePools struct { pools []sync.Pool } -func NewSlicePool(pools int) *byteSlicePools { +func newSlicePool(pools int) *byteSlicePools { sp := byteSlicePools{} sp.init(pools) return &sp @@ -32,7 +32,7 @@ func (sp *byteSlicePools) init(pools int) { } } -func (sp *byteSlicePools) GetSlice(size int) *[]byte { +func (sp *byteSlicePools) getSlice(size int) *[]byte { index := int(math.Ceil(math.Log2(float64(size)))) - minPoolSizePower if index >= len(sp.pools) { @@ -50,7 +50,7 @@ func (sp *byteSlicePools) GetSlice(size int) *[]byte { return s } -func (sp *byteSlicePools) ReuseSlice(s *[]byte) { +func (sp *byteSlicePools) reuseSlice(s *[]byte) { index := int(math.Floor(math.Log2(float64(cap(*s))))) - minPoolSizePower if index >= len(sp.pools) || index < 0 { diff --git a/pkg/cortexpb/slicesPool_test.go b/pkg/cortexpb/slicesPool_test.go index dd35beb33a0..9bc56cdec3f 100644 --- a/pkg/cortexpb/slicesPool_test.go +++ b/pkg/cortexpb/slicesPool_test.go @@ -9,22 +9,22 @@ import ( ) func TestFuzzyByteSlicePools(t *testing.T) { - sut := NewSlicePool(20) + sut := newSlicePool(20) maxByteSize := int(math.Pow(2, 20+minPoolSizePower-1)) for i := 0; i < 1000; i++ { size := rand.Int() % maxByteSize - s := sut.GetSlice(size) + s := sut.getSlice(size) assert.Equal(t, len(*s), size) - sut.ReuseSlice(s) + sut.reuseSlice(s) } } func TestReturnSliceSmallerThanMin(t *testing.T) { - sut := NewSlicePool(20) + sut := newSlicePool(20) size := 3 buff := make([]byte, 0, size) - sut.ReuseSlice(&buff) - buff2 := sut.GetSlice(size * 2) + sut.reuseSlice(&buff) + buff2 := sut.getSlice(size * 2) assert.Equal(t, len(*buff2), size*2) } diff --git a/pkg/cortexpb/timeseries.go b/pkg/cortexpb/timeseries.go index b880739ae2b..db7354ffe45 100644 --- a/pkg/cortexpb/timeseries.go +++ b/pkg/cortexpb/timeseries.go @@ -47,7 +47,7 @@ var ( } }, } - bytePool = NewSlicePool(20) + bytePool = newSlicePool(20) ) // PreallocConfig configures how structures will be preallocated to optimise @@ -86,7 +86,7 @@ func (p *PreallocTimeseries) Unmarshal(dAtA []byte) error { func (p *PreallocWriteRequest) Marshal() (dAtA []byte, err error) { size := p.Size() - p.data = bytePool.GetSlice(size) + p.data = bytePool.getSlice(size) dAtA = *p.data n, err := p.MarshalToSizedBuffer(dAtA[:size]) if err != nil { @@ -97,7 +97,7 @@ func (p *PreallocWriteRequest) Marshal() (dAtA []byte, err error) { func ReuseWriteRequest(req *PreallocWriteRequest) { if req.data != nil { - bytePool.ReuseSlice(req.data) + bytePool.reuseSlice(req.data) req.data = nil } req.Source = 0 diff --git a/pkg/cortexpb/timeseriesv2.go b/pkg/cortexpb/timeseriesv2.go index 28eca0f9738..2d64b21d7c7 100644 --- a/pkg/cortexpb/timeseriesv2.go +++ b/pkg/cortexpb/timeseriesv2.go @@ -34,7 +34,7 @@ var ( } }, } - bytePoolV2 = NewSlicePool(20) + bytePoolV2 = newSlicePool(20) ) // PreallocWriteRequestV2 is a WriteRequest which preallocs slices on Unmarshal. @@ -51,7 +51,7 @@ func (p *PreallocWriteRequestV2) Unmarshal(dAtA []byte) error { func (p *PreallocWriteRequestV2) Marshal() (dAtA []byte, err error) { size := p.Size() - p.data = bytePool.GetSlice(size) + p.data = bytePool.getSlice(size) dAtA = *p.data n, err := p.MarshalToSizedBuffer(dAtA[:size]) if err != nil { @@ -73,7 +73,7 @@ func (p *PreallocTimeseriesV2) Unmarshal(dAtA []byte) error { func ReuseWriteRequestV2(req *PreallocWriteRequestV2) { if req.data != nil { - bytePoolV2.ReuseSlice(req.data) + bytePoolV2.reuseSlice(req.data) req.data = nil } req.Source = 0 diff --git a/pkg/ingester/client/cortex_mock_test.go b/pkg/ingester/client/cortex_mock_test.go index 5aff8bf302b..d378495dcc7 100644 --- a/pkg/ingester/client/cortex_mock_test.go +++ b/pkg/ingester/client/cortex_mock_test.go @@ -6,16 +6,15 @@ import ( "github.com/stretchr/testify/mock" "github.com/cortexproject/cortex/pkg/cortexpb" - "github.com/cortexproject/cortex/pkg/cortexpbv2" ) type IngesterServerMock struct { mock.Mock } -func (m *IngesterServerMock) PushV2(ctx context.Context, r *cortexpbv2.WriteRequest) (*cortexpbv2.WriteResponse, error) { +func (m *IngesterServerMock) PushV2(ctx context.Context, r *cortexpb.WriteRequestV2) (*cortexpb.WriteResponseV2, error) { args := m.Called(ctx, r) - return args.Get(0).(*cortexpbv2.WriteResponse), args.Error(1) + return args.Get(0).(*cortexpb.WriteResponseV2), args.Error(1) } func (m *IngesterServerMock) Push(ctx context.Context, r *cortexpb.WriteRequest) (*cortexpb.WriteResponse, error) { diff --git a/pkg/ruler/compat_test.go b/pkg/ruler/compat_test.go index 7d489b65b0c..21f76be12c8 100644 --- a/pkg/ruler/compat_test.go +++ b/pkg/ruler/compat_test.go @@ -23,20 +23,19 @@ import ( "github.com/weaveworks/common/httpgrpc" "github.com/cortexproject/cortex/pkg/cortexpb" - "github.com/cortexproject/cortex/pkg/cortexpbv2" "github.com/cortexproject/cortex/pkg/querier/stats" "github.com/cortexproject/cortex/pkg/util/validation" ) type fakePusher struct { request *cortexpb.WriteRequest - requestV2 *cortexpbv2.WriteRequest + requestV2 *cortexpb.WriteRequestV2 response *cortexpb.WriteResponse - responseV2 *cortexpbv2.WriteResponse + responseV2 *cortexpb.WriteResponseV2 err error } -func (p *fakePusher) PushV2(ctx context.Context, r *cortexpbv2.WriteRequest) (*cortexpbv2.WriteResponse, error) { +func (p *fakePusher) PushV2(ctx context.Context, r *cortexpb.WriteRequestV2) (*cortexpb.WriteResponseV2, error) { p.requestV2 = r return p.responseV2, p.err } diff --git a/pkg/ruler/pusher_mock_test.go b/pkg/ruler/pusher_mock_test.go index 02fc5b13de2..c909e66d22a 100644 --- a/pkg/ruler/pusher_mock_test.go +++ b/pkg/ruler/pusher_mock_test.go @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/mock" "github.com/cortexproject/cortex/pkg/cortexpb" - "github.com/cortexproject/cortex/pkg/cortexpbv2" ) type pusherMock struct { @@ -17,9 +16,9 @@ func newPusherMock() *pusherMock { return &pusherMock{} } -func (m *pusherMock) PushV2(ctx context.Context, req *cortexpbv2.WriteRequest) (*cortexpbv2.WriteResponse, error) { +func (m *pusherMock) PushV2(ctx context.Context, req *cortexpb.WriteRequestV2) (*cortexpb.WriteResponseV2, error) { args := m.Called(ctx, req) - return args.Get(0).(*cortexpbv2.WriteResponse), args.Error(1) + return args.Get(0).(*cortexpb.WriteResponseV2), args.Error(1) } func (m *pusherMock) Push(ctx context.Context, req *cortexpb.WriteRequest) (*cortexpb.WriteResponse, error) {