diff --git a/go.sum b/go.sum index e8269186b4..40dc119b1b 100644 --- a/go.sum +++ b/go.sum @@ -239,7 +239,7 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.2.3-0.20181014000028-04af85275a5c/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/tdewolff/minify/v2 v2.3.7/go.mod h1:DD1stRlSx6JsHfl1+E/HVMQeXiec9rD1UQ0epklIZLc= github.com/tdewolff/parse/v2 v2.3.5/go.mod h1:HansaqmN4I/U7L6/tUp0NcwT2tFO0F4EAWYGSDzkYNk= diff --git a/pkg/store/bucket.go b/pkg/store/bucket.go index 2c722d8c32..ba673687cc 100644 --- a/pkg/store/bucket.go +++ b/pkg/store/bucket.go @@ -856,7 +856,7 @@ func chunksSize(chks []storepb.AggrChunk) (size int) { } // LabelNames implements the storepb.StoreServer interface. -func (s *BucketStore) LabelNames(ctx context.Context, _ *storepb.LabelNamesRequest) (*storepb.LabelNamesResponse, error) { +func (s *BucketStore) LabelNames(ctx context.Context, r *storepb.LabelNamesRequest) (*storepb.LabelNamesResponse, error) { g, gctx := errgroup.WithContext(ctx) s.mtx.RLock() @@ -869,19 +869,24 @@ func (s *BucketStore) LabelNames(ctx context.Context, _ *storepb.LabelNamesReque g.Go(func() error { defer runutil.CloseWithLogOnErr(s.logger, indexr, "label names") - res := indexr.LabelNames() - + res, err := indexr.LabelNames(gctx) + sort.Strings(res) mtx.Lock() sets = append(sets, res) mtx.Unlock() - - return nil + return err }) } s.mtx.RUnlock() if err := g.Wait(); err != nil { + if !r.PartialResponseDisabled { + return &storepb.LabelNamesResponse{ + Names: strutil.MergeSlices(sets...), + Warnings: []string{err.Error()}, + }, nil + } return nil, status.Error(codes.Aborted, err.Error()) } return &storepb.LabelNamesResponse{ @@ -1646,12 +1651,15 @@ func (r *bucketIndexReader) LabelValues(name string) []string { } // LabelNames returns a list of label names. -func (r *bucketIndexReader) LabelNames() []string { +func (r *bucketIndexReader) LabelNames(ctx context.Context) ([]string, error) { res := make([]string, 0, len(r.block.lvals)) for ln, _ := range r.block.lvals { + if ctx.Err() != nil { + return res, ctx.Err() + } res = append(res, ln) } - return res + return res, nil } // Close released the underlying resources of the reader. diff --git a/pkg/store/prometheus.go b/pkg/store/prometheus.go index b96b96c7b0..d8cb1db47b 100644 --- a/pkg/store/prometheus.go +++ b/pkg/store/prometheus.go @@ -379,12 +379,12 @@ func (p *PrometheusStore) LabelNames(ctx context.Context, r *storepb.LabelNamesR if m.Status != "success" { if !r.PartialResponseDisabled { - return &storepb.LabelNamesResponse{Names: m.Data}, nil + return &storepb.LabelNamesResponse{Names: m.Data, Warnings: []string{m.Error}}, nil } code, exists := statusToCode[resp.StatusCode] if !exists { - code = codes.Internal + return nil, status.Error(codes.Internal, m.Error) } return nil, status.Error(code, m.Error) } @@ -435,12 +435,12 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue if m.Status != "success" { if !r.PartialResponseDisabled { - return &storepb.LabelValuesResponse{Values: m.Data}, nil + return &storepb.LabelValuesResponse{Values: m.Data, Warnings: []string{m.Error}}, nil } code, exists := statusToCode[resp.StatusCode] if !exists { - code = codes.Internal + return nil, status.Error(codes.Internal, m.Error) } return nil, status.Error(code, m.Error) }