diff --git a/pkg/chunk/aws_storage_client.go b/pkg/chunk/aws_storage_client.go index 926c4862edf..8b13bc4e5f4 100644 --- a/pkg/chunk/aws_storage_client.go +++ b/pkg/chunk/aws_storage_client.go @@ -432,15 +432,13 @@ func (a awsStorageClient) GetChunks(ctx context.Context, chunks []Chunk) ([]Chun var err error s3Chunks, err = a.getS3Chunks(ctx, s3Chunks) if err != nil { - return nil, err + return s3Chunks, err } dynamoDBChunks, err = a.getDynamoDBChunks(ctx, dynamoDBChunks) - if err != nil { - return nil, err - } - return append(dynamoDBChunks, s3Chunks...), nil + // Return any chunks we did receive: a partial result may be useful + return append(dynamoDBChunks, s3Chunks...), err } func (a awsStorageClient) getS3Chunks(ctx context.Context, chunks []Chunk) ([]Chunk, error) { @@ -468,7 +466,8 @@ func (a awsStorageClient) getS3Chunks(ctx context.Context, chunks []Chunk) ([]Ch } } if len(errors) > 0 { - return nil, errors[0] + // Return any chunks we did receive: a partial result may be useful + return result, errors[0] } return result, nil } @@ -575,7 +574,8 @@ func (a awsStorageClient) getDynamoDBChunks(ctx context.Context, chunks []Chunk) } if valuesLeft := outstanding.Len() + unprocessed.Len(); valuesLeft > 0 { - return nil, fmt.Errorf("failed to query chunks after %d retries, %d values remaining", numRetries, valuesLeft) + // Return the chunks we did fetch, because partial results may be useful + return result, fmt.Errorf("failed to query chunks after %d retries, %d values remaining", numRetries, valuesLeft) } return result, nil } diff --git a/pkg/chunk/chunk_store.go b/pkg/chunk/chunk_store.go index e77e2755113..f5dfd645837 100644 --- a/pkg/chunk/chunk_store.go +++ b/pkg/chunk/chunk_store.go @@ -209,12 +209,14 @@ func (c *Store) getMetricNameChunks(ctx context.Context, from, through model.Tim } fromStorage, err := c.storage.GetChunks(ctx, missing) - if err != nil { - return nil, promql.ErrStorage(err) + + // Always cache any chunks we did get + if cacheErr := c.writeBackCache(ctx, fromStorage); cacheErr != nil { + logger.Warnf("Could not store chunks in chunk cache: %v", cacheErr) } - if err = c.writeBackCache(ctx, fromStorage); err != nil { - logger.Warnf("Could not store chunks in chunk cache: %v", err) + if err != nil { + return nil, promql.ErrStorage(err) } // TODO instead of doing this sort, propagate an index and assign chunks