Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: jojohappy <[email protected]>
  • Loading branch information
jojohappy committed Apr 17, 2019
1 parent 8441a17 commit 63ef9ca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
22 changes: 15 additions & 7 deletions pkg/store/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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{
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions pkg/store/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 63ef9ca

Please sign in to comment.