Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC for splitting SG into chunk store and index store #5613

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/cortex/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ const (
Configs string = "configs"
AlertManager string = "alertmanager"
Compactor string = "compactor"
StoreGateway string = "store-gateway"
IndexGateway string = "index-gateway"
ChunksGateway string = "chunks-gateway"
MemberlistKV string = "memberlist-kv"
TenantDeletion string = "tenant-deletion"
Purger string = "purger"
Expand Down Expand Up @@ -758,7 +759,8 @@ func (t *Cortex) setupModuleManager() error {
mm.RegisterModule(Configs, t.initConfig)
mm.RegisterModule(AlertManager, t.initAlertManager)
mm.RegisterModule(Compactor, t.initCompactor)
mm.RegisterModule(StoreGateway, t.initStoreGateway)
mm.RegisterModule(IndexGateway, t.initStoreGateway)
mm.RegisterModule(ChunksGateway, t.initStoreGateway)
mm.RegisterModule(TenantDeletion, t.initTenantDeletionAPI, modules.UserInvisibleModule)
mm.RegisterModule(Purger, nil)
mm.RegisterModule(QueryScheduler, t.initQueryScheduler)
Expand Down Expand Up @@ -789,11 +791,12 @@ func (t *Cortex) setupModuleManager() error {
Configs: {API},
AlertManager: {API, MemberlistKV, Overrides},
Compactor: {API, MemberlistKV, Overrides},
StoreGateway: {API, Overrides, MemberlistKV},
IndexGateway: {API, Overrides, MemberlistKV},
ChunksGateway: {API, Overrides, MemberlistKV},
TenantDeletion: {API, Overrides, DeleteRequestsStore},
Purger: {TenantDeletion},
TenantFederation: {Queryable},
All: {QueryFrontend, Querier, Ingester, Distributor, Purger, StoreGateway, Ruler},
All: {QueryFrontend, Querier, Ingester, Distributor, Purger, ChunksGateway, IndexGateway, Ruler},
}
if t.Cfg.ExternalPusher != nil && t.Cfg.ExternalQueryable != nil {
deps[Ruler] = []string{Overrides, DeleteRequestsStore, RulerStorage}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync"
"time"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/gogo/status"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/thanos-io/objstore"
"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/shipper"
"github.com/thanos-io/thanos/pkg/store/storepb"
"github.com/weaveworks/common/httpgrpc"
"go.uber.org/atomic"
"golang.org/x/sync/errgroup"
Expand Down
10 changes: 5 additions & 5 deletions pkg/querier/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"math"
"sort"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/prometheus/prometheus/util/annotations"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/store/storepb"

"github.com/cortexproject/cortex/pkg/querier/iterators"
"github.com/cortexproject/cortex/pkg/querier/series"
Expand All @@ -22,13 +22,13 @@ func convertMatchersToLabelMatcher(matchers []*labels.Matcher) []storepb.LabelMa
var t storepb.LabelMatcher_Type
switch m.Type {
case labels.MatchEqual:
t = storepb.LabelMatcher_EQ
t = storepb.EQ
case labels.MatchNotEqual:
t = storepb.LabelMatcher_NEQ
t = storepb.NEQ
case labels.MatchRegexp:
t = storepb.LabelMatcher_RE
t = storepb.RE
case labels.MatchNotRegexp:
t = storepb.LabelMatcher_NRE
t = storepb.NRE
}

converted = append(converted, storepb.LabelMatcher{
Expand Down
8 changes: 4 additions & 4 deletions pkg/querier/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"
"time"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql"
Expand All @@ -15,7 +16,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/store/storepb"

"github.com/cortexproject/cortex/pkg/util"
)
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestBlockQuerierSeries(t *testing.T) {
{Name: "foo", Value: "bar"},
},
Chunks: []storepb.AggrChunk{
{MinTime: minTimestamp.Unix() * 1000, MaxTime: maxTimestamp.Unix() * 1000, Raw: &storepb.Chunk{Type: storepb.Chunk_XOR, Data: mockTSDBChunkData()}},
{MinTime: minTimestamp.Unix() * 1000, MaxTime: maxTimestamp.Unix() * 1000, Raw: &storepb.Chunk{Type: storepb.XOR, Data: mockTSDBChunkData()}},
},
},
expectedMetric: labels.Labels{
Expand All @@ -59,7 +59,7 @@ func TestBlockQuerierSeries(t *testing.T) {
series: &storepb.Series{
Labels: []labelpb.ZLabel{{Name: "foo", Value: "bar"}},
Chunks: []storepb.AggrChunk{
{MinTime: minTimestamp.Unix() * 1000, MaxTime: maxTimestamp.Unix() * 1000, Raw: &storepb.Chunk{Type: storepb.Chunk_XOR, Data: []byte{0, 1}}},
{MinTime: minTimestamp.Unix() * 1000, MaxTime: maxTimestamp.Unix() * 1000, Raw: &storepb.Chunk{Type: storepb.XOR, Data: []byte{0, 1}}},
},
},
expectedMetric: labels.Labels{labels.Label{Name: "foo", Value: "bar"}},
Expand Down Expand Up @@ -259,7 +259,7 @@ func createAggrChunk(minTime, maxTime int64, samples ...promql.FPoint) storepb.A
MinTime: minTime,
MaxTime: maxTime,
Raw: &storepb.Chunk{
Type: storepb.Chunk_XOR,
Type: storepb.XOR,
Data: chunk.Bytes(),
},
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/querier/blocks_store_queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/cortexproject/cortex/pkg/storegateway/hintspb"
"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/gogo/protobuf/types"
Expand All @@ -25,8 +27,6 @@ import (
"github.com/thanos-io/thanos/pkg/block"
"github.com/thanos-io/thanos/pkg/extprom"
"github.com/thanos-io/thanos/pkg/pool"
"github.com/thanos-io/thanos/pkg/store/hintspb"
"github.com/thanos-io/thanos/pkg/store/storepb"
"github.com/thanos-io/thanos/pkg/strutil"
"go.uber.org/atomic"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -1013,7 +1013,7 @@ func createSeriesRequest(minT, maxT int64, matchers []storepb.LabelMatcher, shar
hints := &hintspb.SeriesRequestHints{
BlockMatchers: []storepb.LabelMatcher{
{
Type: storepb.LabelMatcher_RE,
Type: storepb.RE,
Name: block.BlockIDLabel,
Value: strings.Join(convertULIDsToString(blockIDs), "|"),
},
Expand All @@ -1030,7 +1030,7 @@ func createSeriesRequest(minT, maxT int64, matchers []storepb.LabelMatcher, shar
MinTime: minT,
MaxTime: maxT,
Matchers: matchers,
PartialResponseStrategy: storepb.PartialResponseStrategy_ABORT,
PartialResponseStrategy: storepb.ABORT,
Hints: anyHints,
SkipChunks: skipChunks,
ShardInfo: shardingInfo,
Expand All @@ -1048,7 +1048,7 @@ func createLabelNamesRequest(minT, maxT int64, blockIDs []ulid.ULID, matchers []
hints := &hintspb.LabelNamesRequestHints{
BlockMatchers: []storepb.LabelMatcher{
{
Type: storepb.LabelMatcher_RE,
Type: storepb.RE,
Name: block.BlockIDLabel,
Value: strings.Join(convertULIDsToString(blockIDs), "|"),
},
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func createLabelValuesRequest(minT, maxT int64, label string, blockIDs []ulid.UL
hints := &hintspb.LabelValuesRequestHints{
BlockMatchers: []storepb.LabelMatcher{
{
Type: storepb.LabelMatcher_RE,
Type: storepb.RE,
Name: block.BlockIDLabel,
Value: strings.Join(convertULIDsToString(blockIDs), "|"),
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/querier/blocks_store_queryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/go-kit/log"
"github.com/gogo/protobuf/types"
"github.com/oklog/ulid"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/thanos-io/thanos/pkg/pool"
"github.com/thanos-io/thanos/pkg/store/hintspb"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/store/storepb"
"github.com/weaveworks/common/user"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -1740,7 +1740,7 @@ func mockSeriesResponse(lbls labels.Labels, timeMillis int64, value float64) *st
Series: &storepb.Series{
Labels: labelpb.ZLabelsFromPromLabels(lbls),
Chunks: []storepb.AggrChunk{
{MinTime: timeMillis, MaxTime: timeMillis, Raw: &storepb.Chunk{Type: storepb.Chunk_XOR, Data: chunkData}},
{MinTime: timeMillis, MaxTime: timeMillis, Raw: &storepb.Chunk{Type: storepb.XOR, Data: chunkData}},
},
},
},
Expand Down Expand Up @@ -1849,7 +1849,7 @@ func TestCountSamplesAndChunks(t *testing.T) {
Chunks: []storepb.AggrChunk{
{
Raw: &storepb.Chunk{
Type: storepb.Chunk_XOR,
Type: storepb.XOR,
Data: c.Bytes(),
},
},
Expand All @@ -1865,13 +1865,13 @@ func TestCountSamplesAndChunks(t *testing.T) {
Chunks: []storepb.AggrChunk{
{
Raw: &storepb.Chunk{
Type: storepb.Chunk_XOR,
Type: storepb.XOR,
Data: c.Bytes(),
},
},
{
Raw: &storepb.Chunk{
Type: storepb.Chunk_XOR,
Type: storepb.XOR,
Data: c.Bytes(),
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/store_gateway_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"net"
"testing"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/thanos-io/thanos/pkg/store/storepb"
"github.com/weaveworks/common/user"
"google.golang.org/grpc"

Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/tripperware/shard_by.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"net/http"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/thanos-io/thanos/pkg/querysharding"
"github.com/thanos-io/thanos/pkg/store/storepb"
"github.com/weaveworks/common/httpgrpc"

querier_stats "github.com/cortexproject/cortex/pkg/querier/stats"
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/tripperware/test_shard_by_query_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"testing"
"time"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/go-kit/log"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/promql/parser"
"github.com/stretchr/testify/require"
thanosquerysharding "github.com/thanos-io/thanos/pkg/querysharding"
"github.com/thanos-io/thanos/pkg/store/storepb"
"github.com/weaveworks/common/user"

"github.com/cortexproject/cortex/pkg/querysharding"
Expand Down
2 changes: 1 addition & 1 deletion pkg/querysharding/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"encoding/base64"
"sync"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/promql/parser"
"github.com/thanos-io/thanos/pkg/store/storepb"
)

const (
Expand Down
71 changes: 71 additions & 0 deletions pkg/storegateway/block_chunks_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package storegateway

import (
"context"

"github.com/cortexproject/cortex/pkg/storegateway/storepb"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
)

// Loads a batch of chunks
type blockChunkClient struct {
ctx context.Context
logger log.Logger

mint int64
maxt int64
chunkr *bucketChunkReader
loadAggregates []storepb.Aggr
chunksLimiter ChunksLimiter
bytesLimiter BytesLimiter

calculateChunkHash bool
seriesFetchDurationSum *prometheus.HistogramVec
chunkFetchDuration *prometheus.HistogramVec
chunkFetchDurationSum *prometheus.HistogramVec
tenant string

batchSize int
}

func newBlockChunksClient(
ctx context.Context,
logger log.Logger,
b *bucketBlock,
req *storepb.SeriesRequest,
limiter ChunksLimiter,
bytesLimiter BytesLimiter,
calculateChunkHash bool,
batchSize int,
chunkFetchDuration *prometheus.HistogramVec,
chunkFetchDurationSum *prometheus.HistogramVec,
tenant string,
) *blockChunkClient {
return &blockChunkClient{
ctx: ctx,
logger: logger,
mint: req.MinTime,
maxt: req.MaxTime,
chunkr: b.chunkReader(),
}
}

func (b *blockChunkClient) loadChunks(entries []seriesEntry) error {
b.chunkr.reset()

for i, s := range entries {
for j := range s.chks {
if err := b.chunkr.addLoad(s.refs[j], i, j); err != nil {
return errors.Wrap(err, "add chunk load")
}
}
}

if err := b.chunkr.load(b.ctx, entries, b.loadAggregates, b.calculateChunkHash, b.bytesLimiter, b.tenant); err != nil {
return errors.Wrap(err, "load chunks")
}

return nil
}
Loading
Loading