Skip to content

Return data fetched from a subset of store-gateways instead of returning error if a single store-gateway fails #4532

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

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## master / unreleased
* [FEATURE] Compactor: Added `-compactor.block-files-concurrency` allowing to configure number of go routines for download/upload block files during compaction. #4784
* [ENHANCEMENT] Querier/Ruler: Retry store-gateway in case of unexpected failure, instead of failing the query. #4532

## 1.13.0 in progress
* [CHANGE] Changed default for `-ingester.min-ready-duration` from 1 minute to 15 seconds. #4539
Expand Down
9 changes: 5 additions & 4 deletions integration/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,18 +734,19 @@ func TestQuerierWithBlocksStorageOnMissingBlocksFromStorage(t *testing.T) {
require.NoError(t, ingester.WaitSumMetrics(e2e.Equals(1), "cortex_ingester_memory_series_removed_total"))
require.NoError(t, ingester.WaitSumMetrics(e2e.Equals(1), "cortex_ingester_memory_series"))

// Start the querier and store-gateway, and configure them to not frequently sync blocks.
// Start the querier and store-gateway, and configure them to frequently sync blocks fast enough to trigger consistency check.
storeGateway := e2ecortex.NewStoreGateway("store-gateway", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), mergeFlags(flags, map[string]string{
"-blocks-storage.bucket-store.sync-interval": "1m",
"-blocks-storage.bucket-store.sync-interval": "5s",
}), "")
querier := e2ecortex.NewQuerier("querier", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), mergeFlags(flags, map[string]string{
"-blocks-storage.bucket-store.sync-interval": "1m",
"-blocks-storage.bucket-store.sync-interval": "5s",
}), "")
require.NoError(t, s.StartAndWaitReady(querier, storeGateway))

// Wait until the querier and store-gateway have updated the ring.
// Wait until the querier and store-gateway have updated the ring, and wait until the blocks are old enough for consistency check
require.NoError(t, querier.WaitSumMetrics(e2e.Equals(512*2), "cortex_ring_tokens_total"))
require.NoError(t, storeGateway.WaitSumMetrics(e2e.Equals(512), "cortex_ring_tokens_total"))
require.NoError(t, querier.WaitSumMetricsWithOptions(e2e.GreaterOrEqual(4), []string{"cortex_querier_blocks_scan_duration_seconds"}, e2e.WithMetricCount))

// Query back the series.
c, err = e2ecortex.NewClient("", querier.HTTPEndpoint(), "", "", "user-1")
Expand Down
29 changes: 29 additions & 0 deletions pkg/querier/blocks_store_queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"sync"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/gogo/protobuf/types"
Expand Down Expand Up @@ -419,6 +422,7 @@ func (q *blocksStoreQuerier) selectSorted(sp *storage.SelectHints, matchers ...*
queryFunc := func(clients map[BlocksStoreClient][]ulid.ULID, minT, maxT int64) ([]ulid.ULID, error) {
seriesSets, queriedBlocks, warnings, numChunks, err := q.fetchSeriesFromStores(spanCtx, sp, clients, minT, maxT, matchers, convertedMatchers, maxChunksLimit, leftChunksLimit)
if err != nil {

return nil, err
}

Expand Down Expand Up @@ -586,6 +590,9 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
// TODO(goutham): we should ideally be passing the hints down to the storage layer
// and let the TSDB return us data with no chunks as in prometheus#8050.
// But this is an acceptable workaround for now.

// Only fail the function if we have validation error. We should return blocks that were successfully
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also fail the function when store-gateways return a limit error. It'll be good to avoid unnecessary retries in that case.

// retrieved.
skipChunks := sp != nil && sp.Func == "series"

req, err := createSeriesRequest(minT, maxT, convertedMatchers, skipChunks, blockIDs)
Expand All @@ -595,6 +602,10 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(

stream, err := c.Series(gCtx, req)
if err != nil {
if isRetryableError(err) {
level.Warn(spanLog).Log("err", errors.Wrapf(err, "failed to fetch series from %s due to retryable error", c.RemoteAddress()))
return nil
}
return errors.Wrapf(err, "failed to fetch series from %s", c.RemoteAddress())
}

Expand Down Expand Up @@ -725,6 +736,10 @@ func (q *blocksStoreQuerier) fetchLabelNamesFromStore(

namesResp, err := c.LabelNames(gCtx, req)
if err != nil {
if isRetryableError(err) {
level.Warn(spanLog).Log("err", errors.Wrapf(err, "failed to fetch series from %s due to retryable error", c.RemoteAddress()))
return nil
}
return errors.Wrapf(err, "failed to fetch series from %s", c.RemoteAddress())
}

Expand Down Expand Up @@ -802,6 +817,10 @@ func (q *blocksStoreQuerier) fetchLabelValuesFromStore(

valuesResp, err := c.LabelValues(gCtx, req)
if err != nil {
if isRetryableError(err) {
level.Warn(spanLog).Log("err", errors.Wrapf(err, "failed to fetch series from %s due to retryable error", c.RemoteAddress()))
return nil
}
return errors.Wrapf(err, "failed to fetch series from %s", c.RemoteAddress())
}

Expand Down Expand Up @@ -967,3 +986,13 @@ func countChunkBytes(series ...*storepb.Series) (count int) {

return count
}

// only retry connection issues
func isRetryableError(err error) bool {
switch status.Code(err) {
case codes.Unavailable:
return true
default:
return false
}
}
73 changes: 71 additions & 2 deletions pkg/querier/blocks_store_queryable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"testing"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/go-kit/log"
"github.com/gogo/protobuf/types"
"github.com/oklog/ulid"
Expand Down Expand Up @@ -584,6 +587,35 @@ func TestBlocksStoreQuerier_Select(t *testing.T) {
queryLimiter: limiter.NewQueryLimiter(0, 8, 0),
expectedErr: validation.LimitError(fmt.Sprintf(limiter.ErrMaxChunkBytesHit, 8)),
},
"multiple store-gateways has the block, but one of them fails to return": {
finderResult: bucketindex.Blocks{
{ID: block1},
},
storeSetResponses: []interface{}{
map[BlocksStoreClient][]ulid.ULID{
&storeGatewayClientMock{
remoteAddr: "1.1.1.1",
mockedSeriesErr: status.Error(codes.Unavailable, "unavailable"),
}: {block1},
},
map[BlocksStoreClient][]ulid.ULID{
&storeGatewayClientMock{remoteAddr: "2.2.2.2", mockedSeriesResponses: []*storepb.SeriesResponse{
mockSeriesResponse(labels.Labels{metricNameLabel, series1Label}, minT, 2),
mockHintsResponse(block1),
}}: {block1},
},
},
limits: &blocksStoreLimitsMock{},
queryLimiter: noOpQueryLimiter,
expectedSeries: []seriesResult{
{
lbls: labels.New(metricNameLabel, series1Label),
values: []valueResult{
{t: minT, v: 2},
},
},
},
},
}

for testName, testData := range tests {
Expand Down Expand Up @@ -1059,6 +1091,41 @@ func TestBlocksStoreQuerier_Labels(t *testing.T) {
cortex_querier_storegateway_refetches_per_query_count 1
`,
},
"multiple store-gateways has the block, but one of them fails to return": {
finderResult: bucketindex.Blocks{
{ID: block1},
},
storeSetResponses: []interface{}{
map[BlocksStoreClient][]ulid.ULID{
&storeGatewayClientMock{
remoteAddr: "1.1.1.1",
mockedLabelNamesResponse: &storepb.LabelNamesResponse{
Names: namesFromSeries(series1),
Warnings: []string{},
Hints: mockNamesHints(block1),
},
mockedLabelValuesErr: status.Error(codes.Unavailable, "unavailable"),
}: {block1},
},
map[BlocksStoreClient][]ulid.ULID{
&storeGatewayClientMock{
remoteAddr: "2.2.2.2",
mockedLabelNamesResponse: &storepb.LabelNamesResponse{
Names: namesFromSeries(series1),
Warnings: []string{},
Hints: mockNamesHints(block1),
},
mockedLabelValuesResponse: &storepb.LabelValuesResponse{
Values: valuesFromSeries(labels.MetricName, series1),
Warnings: []string{},
Hints: mockValuesHints(block1),
},
}: {block1},
},
},
expectedLabelNames: namesFromSeries(series1),
expectedLabelValues: valuesFromSeries(labels.MetricName, series1),
},
}

for testName, testData := range tests {
Expand Down Expand Up @@ -1361,24 +1428,26 @@ func (m *blocksFinderMock) GetBlocks(ctx context.Context, userID string, minT, m
type storeGatewayClientMock struct {
remoteAddr string
mockedSeriesResponses []*storepb.SeriesResponse
mockedSeriesErr error
mockedLabelNamesResponse *storepb.LabelNamesResponse
mockedLabelValuesResponse *storepb.LabelValuesResponse
mockedLabelValuesErr error
}

func (m *storeGatewayClientMock) Series(ctx context.Context, in *storepb.SeriesRequest, opts ...grpc.CallOption) (storegatewaypb.StoreGateway_SeriesClient, error) {
seriesClient := &storeGatewaySeriesClientMock{
mockedResponses: m.mockedSeriesResponses,
}

return seriesClient, nil
return seriesClient, m.mockedSeriesErr
}

func (m *storeGatewayClientMock) LabelNames(context.Context, *storepb.LabelNamesRequest, ...grpc.CallOption) (*storepb.LabelNamesResponse, error) {
return m.mockedLabelNamesResponse, nil
}

func (m *storeGatewayClientMock) LabelValues(context.Context, *storepb.LabelValuesRequest, ...grpc.CallOption) (*storepb.LabelValuesResponse, error) {
return m.mockedLabelValuesResponse, nil
return m.mockedLabelValuesResponse, m.mockedLabelValuesErr
}

func (m *storeGatewayClientMock) RemoteAddress() string {
Expand Down