Skip to content

Commit

Permalink
Remove partial response logic in store
Browse files Browse the repository at this point in the history
Signed-off-by: jojohappy <sarahdj0917@gmail.com>
  • Loading branch information
jojohappy committed Apr 17, 2019
1 parent 63ef9ca commit 90fb062
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
23 changes: 8 additions & 15 deletions pkg/store/bucket.go
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, r *storepb.LabelNamesRequest) (*storepb.LabelNamesResponse, error) {
func (s *BucketStore) LabelNames(ctx context.Context, _ *storepb.LabelNamesRequest) (*storepb.LabelNamesResponse, error) {
g, gctx := errgroup.WithContext(ctx)

s.mtx.RLock()
Expand All @@ -869,25 +869,21 @@ func (s *BucketStore) LabelNames(ctx context.Context, r *storepb.LabelNamesReque
g.Go(func() error {
defer runutil.CloseWithLogOnErr(s.logger, indexr, "label names")

res, err := indexr.LabelNames(gctx)
res := indexr.LabelNames()
sort.Strings(res)

mtx.Lock()
sets = append(sets, res)
mtx.Unlock()
return err

return nil
})
}

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 nil, status.Error(codes.Internal, err.Error())
}
return &storepb.LabelNamesResponse{
Names: strutil.MergeSlices(sets...),
Expand Down Expand Up @@ -1651,15 +1647,12 @@ func (r *bucketIndexReader) LabelValues(name string) []string {
}

// LabelNames returns a list of label names.
func (r *bucketIndexReader) LabelNames(ctx context.Context) ([]string, error) {
func (r *bucketIndexReader) LabelNames() []string {
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, nil
return res
}

// Close released the underlying resources of the reader.
Expand Down
34 changes: 17 additions & 17 deletions pkg/store/prometheus.go
Expand Up @@ -344,7 +344,7 @@ func extendLset(lset []storepb.Label, extend labels.Labels) []storepb.Label {
}

// LabelNames returns all known label names.
func (p *PrometheusStore) LabelNames(ctx context.Context, r *storepb.LabelNamesRequest) (
func (p *PrometheusStore) LabelNames(ctx context.Context, _ *storepb.LabelNamesRequest) (
*storepb.LabelNamesResponse, error,
) {
u := *p.base
Expand All @@ -364,6 +364,14 @@ func (p *PrometheusStore) LabelNames(ctx context.Context, r *storepb.LabelNamesR
}
defer runutil.CloseWithLogOnErr(p.logger, resp.Body, "label names request body")

if resp.StatusCode/100 != 2 {
return nil, status.Error(codes.Internal, fmt.Sprintf("request Prometheus server failed, code %s", resp.Status))
}

if resp.StatusCode == http.StatusNoContent {
return &storepb.LabelNamesResponse{Names: []string{}}, nil
}

var m struct {
Data []string `json:"data"`
Status string `json:"status"`
Expand All @@ -373,15 +381,7 @@ func (p *PrometheusStore) LabelNames(ctx context.Context, r *storepb.LabelNamesR
return nil, status.Error(codes.Internal, err.Error())
}

if resp.StatusCode == http.StatusNoContent {
return &storepb.LabelNamesResponse{Names: []string{}}, nil
}

if m.Status != "success" {
if !r.PartialResponseDisabled {
return &storepb.LabelNamesResponse{Names: m.Data, Warnings: []string{m.Error}}, nil
}

code, exists := statusToCode[resp.StatusCode]
if !exists {
return nil, status.Error(codes.Internal, m.Error)
Expand Down Expand Up @@ -418,6 +418,14 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue
}
defer runutil.CloseWithLogOnErr(p.logger, resp.Body, "label values request body")

if resp.StatusCode/100 != 2 {
return nil, status.Error(codes.Internal, fmt.Sprintf("request Prometheus server failed, code %s", resp.Status))
}

if resp.StatusCode == http.StatusNoContent {
return &storepb.LabelValuesResponse{Values: []string{}}, nil
}

var m struct {
Data []string `json:"data"`
Status string `json:"status"`
Expand All @@ -429,15 +437,7 @@ func (p *PrometheusStore) LabelValues(ctx context.Context, r *storepb.LabelValue

sort.Strings(m.Data)

if resp.StatusCode == http.StatusNoContent {
return &storepb.LabelValuesResponse{Values: []string{}}, nil
}

if m.Status != "success" {
if !r.PartialResponseDisabled {
return &storepb.LabelValuesResponse{Values: m.Data, Warnings: []string{m.Error}}, nil
}

code, exists := statusToCode[resp.StatusCode]
if !exists {
return nil, status.Error(codes.Internal, m.Error)
Expand Down

0 comments on commit 90fb062

Please sign in to comment.