diff --git a/pkg/storegateway/bucket.go b/pkg/storegateway/bucket.go index d14a60e556..cafda1d9ba 100644 --- a/pkg/storegateway/bucket.go +++ b/pkg/storegateway/bucket.go @@ -769,7 +769,7 @@ func (s *BucketStore) Series(req *storepb.SeriesRequest, srv storepb.Store_Serie if err == nil { return } - code := codes.Aborted + code := codes.Internal if st, ok := status.FromError(errors.Cause(err)); ok { code = st.Code() } else if errors.Is(err, context.Canceled) { @@ -1269,6 +1269,10 @@ func (s *BucketStore) LabelNames(ctx context.Context, req *storepb.LabelNamesReq s.blocksMx.RUnlock() if err := g.Wait(); err != nil { + if errors.Is(err, context.Canceled) { + return nil, status.Error(codes.Canceled, err.Error()) + } + return nil, status.Error(codes.Internal, err.Error()) } @@ -1430,7 +1434,11 @@ func (s *BucketStore) LabelValues(ctx context.Context, req *storepb.LabelValuesR s.blocksMx.RUnlock() if err := g.Wait(); err != nil { - return nil, status.Error(codes.Aborted, err.Error()) + if errors.Is(err, context.Canceled) { + return nil, status.Error(codes.Canceled, err.Error()) + } + + return nil, status.Error(codes.Internal, err.Error()) } anyHints, err := types.MarshalAny(resHints) diff --git a/pkg/storegateway/bucket_test.go b/pkg/storegateway/bucket_test.go index 34923e2d85..14004f6ee6 100644 --- a/pkg/storegateway/bucket_test.go +++ b/pkg/storegateway/bucket_test.go @@ -2298,6 +2298,59 @@ func TestLabelNamesAndValuesHints(t *testing.T) { } } +func TestLabelNames_Cancelled(t *testing.T) { + _, store, _, _, _, _, close := setupStoreForHintsTest(t) + defer close() + + req := &storepb.LabelNamesRequest{ + Start: 0, + End: 1, + Matchers: []storepb.LabelMatcher{ + { + Name: "__name__", + Type: storepb.LabelMatcher_RE, + Value: ".*", + }, + }, + } + + ctx, cancel := context.WithCancel(context.Background()) + cancel() + + _, err := store.LabelNames(ctx, req) + assert.Error(t, err) + s, ok := status.FromError(err) + assert.True(t, ok) + assert.Equal(t, codes.Canceled, s.Code()) +} + +func TestLabelValues_Cancelled(t *testing.T) { + _, store, _, _, _, _, close := setupStoreForHintsTest(t) + defer close() + + req := &storepb.LabelValuesRequest{ + Label: "ext1", + Start: 0, + End: 1, + Matchers: []storepb.LabelMatcher{ + { + Name: "__name__", + Type: storepb.LabelMatcher_RE, + Value: ".*", + }, + }, + } + + ctx, cancel := context.WithCancel(context.Background()) + cancel() + + _, err := store.LabelValues(ctx, req) + assert.Error(t, err) + s, ok := status.FromError(err) + assert.True(t, ok) + assert.Equal(t, codes.Canceled, s.Code()) +} + func labelNamesFromSeriesSet(series []*storepb.Series) []string { labelsMap := map[string]struct{}{}