From 90fb062fe66458da7da9cc25c8bce5389dcb3625 Mon Sep 17 00:00:00 2001 From: jojohappy Date: Tue, 16 Apr 2019 18:26:17 +0800 Subject: [PATCH] Remove partial response logic in store Signed-off-by: jojohappy --- pkg/store/bucket.go | 23 ++++++++--------------- pkg/store/prometheus.go | 34 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/pkg/store/bucket.go b/pkg/store/bucket.go index ba673687cc..b75e16e58c 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, 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() @@ -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...), @@ -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. diff --git a/pkg/store/prometheus.go b/pkg/store/prometheus.go index d8cb1db47b..ea3482a19b 100644 --- a/pkg/store/prometheus.go +++ b/pkg/store/prometheus.go @@ -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 @@ -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"` @@ -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) @@ -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"` @@ -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)