From c995a4b805757bdcf214603208f1517297c26cb6 Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Tue, 15 Jun 2021 17:08:03 +0200 Subject: [PATCH 1/2] Shards Series API. This PR introduces Series Queries Sharding. It does not check the boundaries of ingesters data since I'm assuming https://github.com/grafana/loki/pull/3852 will be merge first. Signed-off-by: Cyril Tovena --- pkg/loghttp/series.go | 2 +- pkg/logproto/logproto.pb.go | 243 ++++++++++++------- pkg/logproto/logproto.proto | 3 +- pkg/logql/shardmapper.go | 14 +- pkg/querier/querier.go | 10 +- pkg/querier/queryrange/codec.go | 15 +- pkg/querier/queryrange/queryrange.pb.go | 185 +++++++++----- pkg/querier/queryrange/queryrange.proto | 4 +- pkg/querier/queryrange/querysharding.go | 85 ++++++- pkg/querier/queryrange/querysharding_test.go | 75 +++++- pkg/querier/queryrange/roundtrip.go | 19 +- pkg/querier/queryrange/split_by_interval.go | 1 + pkg/storage/store.go | 29 ++- 13 files changed, 505 insertions(+), 180 deletions(-) diff --git a/pkg/loghttp/series.go b/pkg/loghttp/series.go index ccce5b6f0aad..f956598dd883 100644 --- a/pkg/loghttp/series.go +++ b/pkg/loghttp/series.go @@ -41,8 +41,8 @@ func ParseSeriesQuery(r *http.Request) (*logproto.SeriesRequest, error) { Start: start, End: end, Groups: deduped, + Shards: shards(r), }, nil - } func union(cols ...[]string) []string { diff --git a/pkg/logproto/logproto.pb.go b/pkg/logproto/logproto.pb.go index b1acaa0d5d59..a2cb57939409 100644 --- a/pkg/logproto/logproto.pb.go +++ b/pkg/logproto/logproto.pb.go @@ -785,6 +785,7 @@ type SeriesRequest struct { Start time.Time `protobuf:"bytes,1,opt,name=start,proto3,stdtime" json:"start"` End time.Time `protobuf:"bytes,2,opt,name=end,proto3,stdtime" json:"end"` Groups []string `protobuf:"bytes,3,rep,name=groups,proto3" json:"groups,omitempty"` + Shards []string `protobuf:"bytes,4,rep,name=shards,proto3" json:"shards,omitempty"` } func (m *SeriesRequest) Reset() { *m = SeriesRequest{} } @@ -840,6 +841,13 @@ func (m *SeriesRequest) GetGroups() []string { return nil } +func (m *SeriesRequest) GetShards() []string { + if m != nil { + return m.Shards + } + return nil +} + type SeriesResponse struct { Series []SeriesIdentifier `protobuf:"bytes,1,rep,name=series,proto3" json:"series"` } @@ -1395,93 +1403,93 @@ func init() { func init() { proto.RegisterFile("pkg/logproto/logproto.proto", fileDescriptor_c28a5f14f1f4c79a) } var fileDescriptor_c28a5f14f1f4c79a = []byte{ - // 1366 bytes of a gzipped FileDescriptorProto + // 1370 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x57, 0x4b, 0x8f, 0x13, 0xc7, - 0x13, 0x77, 0xfb, 0x31, 0xb6, 0xcb, 0x0f, 0xac, 0xde, 0x65, 0xd7, 0x7f, 0x03, 0x63, 0xab, 0x85, + 0x13, 0x77, 0xfb, 0x31, 0xb6, 0xcb, 0x0f, 0xac, 0xde, 0x65, 0xd7, 0x7f, 0x03, 0x63, 0x6b, 0x84, 0xc0, 0xfa, 0x87, 0x78, 0x83, 0xf3, 0xe2, 0x91, 0x87, 0xd6, 0x6c, 0x08, 0x4b, 0x50, 0x80, 0x01, - 0x09, 0x09, 0x29, 0x42, 0xb3, 0x76, 0xaf, 0x3d, 0x5a, 0x7b, 0xc6, 0xcc, 0xb4, 0x91, 0xf6, 0x96, - 0x0f, 0x90, 0x48, 0xdc, 0x72, 0xe0, 0x9a, 0x43, 0x94, 0x43, 0x3e, 0x07, 0x47, 0x94, 0x13, 0xca, - 0xc1, 0x09, 0xe6, 0x12, 0xad, 0x72, 0xe0, 0x23, 0x44, 0xfd, 0x98, 0x99, 0xb6, 0xd9, 0x4d, 0x30, - 0x97, 0x5c, 0x3c, 0x5d, 0xd5, 0xd5, 0xd5, 0x55, 0xbf, 0xfe, 0x55, 0x75, 0x1b, 0x4e, 0x8c, 0xf7, - 0xfa, 0x1b, 0x43, 0xaf, 0x3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 0x9e, 0xbb, 0xa1, 0xff, 0x8f, 0xdd, 0x31, 0xc4, 0xe7, 0xdd, 0xbf, 0x03, 0x00, 0x00, + 0xff, 0xff, 0x0a, 0x35, 0x40, 0x22, 0xde, 0x0e, 0x00, 0x00, } func (x Direction) String() string { @@ -1974,6 +1982,14 @@ func (this *SeriesRequest) Equal(that interface{}) bool { return false } } + if len(this.Shards) != len(that1.Shards) { + return false + } + for i := range this.Shards { + if this.Shards[i] != that1.Shards[i] { + return false + } + } return true } func (this *SeriesResponse) Equal(that interface{}) bool { @@ -2460,11 +2476,12 @@ func (this *SeriesRequest) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 7) + s := make([]string, 0, 8) s = append(s, "&logproto.SeriesRequest{") s = append(s, "Start: "+fmt.Sprintf("%#v", this.Start)+",\n") s = append(s, "End: "+fmt.Sprintf("%#v", this.End)+",\n") s = append(s, "Groups: "+fmt.Sprintf("%#v", this.Groups)+",\n") + s = append(s, "Shards: "+fmt.Sprintf("%#v", this.Shards)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -3710,6 +3727,21 @@ func (m *SeriesRequest) MarshalTo(dAtA []byte) (int, error) { i += copy(dAtA[i:], s) } } + if len(m.Shards) > 0 { + for _, s := range m.Shards { + dAtA[i] = 0x22 + i++ + l = len(s) + for l >= 1<<7 { + dAtA[i] = uint8(uint64(l)&0x7f | 0x80) + l >>= 7 + i++ + } + dAtA[i] = uint8(l) + i++ + i += copy(dAtA[i:], s) + } + } return i, nil } @@ -4339,6 +4371,12 @@ func (m *SeriesRequest) Size() (n int) { n += 1 + l + sovLogproto(uint64(l)) } } + if len(m.Shards) > 0 { + for _, s := range m.Shards { + l = len(s) + n += 1 + l + sovLogproto(uint64(l)) + } + } return n } @@ -4692,6 +4730,7 @@ func (this *SeriesRequest) String() string { `Start:` + strings.Replace(strings.Replace(this.Start.String(), "Timestamp", "types.Timestamp", 1), `&`, ``, 1) + `,`, `End:` + strings.Replace(strings.Replace(this.End.String(), "Timestamp", "types.Timestamp", 1), `&`, ``, 1) + `,`, `Groups:` + fmt.Sprintf("%v", this.Groups) + `,`, + `Shards:` + fmt.Sprintf("%v", this.Shards) + `,`, `}`, }, "") return s @@ -6674,6 +6713,38 @@ func (m *SeriesRequest) Unmarshal(dAtA []byte) error { } m.Groups = append(m.Groups, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Shards", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowLogproto + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthLogproto + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthLogproto + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Shards = append(m.Shards, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipLogproto(dAtA[iNdEx:]) diff --git a/pkg/logproto/logproto.proto b/pkg/logproto/logproto.proto index bb7df467a404..e54a22c289cd 100644 --- a/pkg/logproto/logproto.proto +++ b/pkg/logproto/logproto.proto @@ -111,6 +111,7 @@ message SeriesRequest { google.protobuf.Timestamp start = 1 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; google.protobuf.Timestamp end = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; repeated string groups = 3; + repeated string shards = 4 [(gogoproto.jsontag) = "shards,omitempty"]; } message SeriesResponse { @@ -163,4 +164,4 @@ message GetChunkIDsRequest { message GetChunkIDsResponse { repeated string chunkIDs = 1; -} \ No newline at end of file +} diff --git a/pkg/logql/shardmapper.go b/pkg/logql/shardmapper.go index 893febe8b09d..86de6cd631ef 100644 --- a/pkg/logql/shardmapper.go +++ b/pkg/logql/shardmapper.go @@ -22,15 +22,14 @@ const ( // ShardingMetrics is the metrics wrapper used in shard mapping type ShardingMetrics struct { - shards *prometheus.CounterVec // sharded queries total, partitioned by (streams/metric) + Shards *prometheus.CounterVec // sharded queries total, partitioned by (streams/metric) + ShardFactor prometheus.Histogram // per request shard factor parsed *prometheus.CounterVec // parsed ASTs total, partitioned by (success/failure/noop) - shardFactor prometheus.Histogram // per request shard factor } func NewShardingMetrics(registerer prometheus.Registerer) *ShardingMetrics { - return &ShardingMetrics{ - shards: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{ + Shards: promauto.With(registerer).NewCounterVec(prometheus.CounterOpts{ Namespace: "loki", Name: "query_frontend_shards_total", }, []string{"type"}), @@ -38,7 +37,7 @@ func NewShardingMetrics(registerer prometheus.Registerer) *ShardingMetrics { Namespace: "loki", Name: "query_frontend_sharding_parsed_queries_total", }, []string{"type"}), - shardFactor: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{ + ShardFactor: promauto.With(registerer).NewHistogram(prometheus.HistogramOpts{ Namespace: "loki", Name: "query_frontend_shard_factor", Help: "Number of shards per request", @@ -67,14 +66,14 @@ type shardRecorder struct { // Add increments both the shard count and tracks it for the eventual histogram entry. func (r *shardRecorder) Add(x int, key string) { r.total += x - r.shards.WithLabelValues(key).Add(float64(x)) + r.Shards.WithLabelValues(key).Add(float64(x)) } // Finish idemptotently records a histogram entry with the total shard factor. func (r *shardRecorder) Finish() { if !r.done { r.done = true - r.shardFactor.Observe(float64(r.total)) + r.ShardFactor.Observe(float64(r.total)) } } @@ -203,7 +202,6 @@ func (m ShardMapper) mapSampleExpr(expr SampleExpr, r *shardRecorder) SampleExpr // technically, std{dev,var} are also parallelizable if there is no cross-shard merging // in descendent nodes in the AST. This optimization is currently avoided for simplicity. func (m ShardMapper) mapVectorAggregationExpr(expr *vectorAggregationExpr, r *shardRecorder) (SampleExpr, error) { - // if this AST contains unshardable operations, don't shard this at this level, // but attempt to shard a child node. if !expr.Shardable() { diff --git a/pkg/querier/querier.go b/pkg/querier/querier.go index 51ab81818a9a..2c6945b25ceb 100644 --- a/pkg/querier/querier.go +++ b/pkg/querier/querier.go @@ -396,7 +396,7 @@ func (q *Querier) awaitSeries(ctx context.Context, req *logproto.SeriesRequest) } go func() { - storeValues, err := q.seriesForMatchers(ctx, req.Start, req.End, req.GetGroups()) + storeValues, err := q.seriesForMatchers(ctx, req.Start, req.End, req.GetGroups(), req.Shards) if err != nil { errs <- err return @@ -441,6 +441,7 @@ func (q *Querier) seriesForMatchers( ctx context.Context, from, through time.Time, groups []string, + shards []string, ) ([]logproto.SeriesIdentifier, error) { var results []logproto.SeriesIdentifier @@ -448,13 +449,13 @@ func (q *Querier) seriesForMatchers( // we send a query with an empty matcher which will match every series. if len(groups) == 0 { var err error - results, err = q.seriesForMatcher(ctx, from, through, "") + results, err = q.seriesForMatcher(ctx, from, through, "", shards) if err != nil { return nil, err } } else { for _, group := range groups { - ids, err := q.seriesForMatcher(ctx, from, through, group) + ids, err := q.seriesForMatcher(ctx, from, through, group, shards) if err != nil { return nil, err } @@ -465,7 +466,7 @@ func (q *Querier) seriesForMatchers( } // seriesForMatcher fetches series from the store for a given matcher -func (q *Querier) seriesForMatcher(ctx context.Context, from, through time.Time, matcher string) ([]logproto.SeriesIdentifier, error) { +func (q *Querier) seriesForMatcher(ctx context.Context, from, through time.Time, matcher string, shards []string) ([]logproto.SeriesIdentifier, error) { ids, err := q.store.GetSeries(ctx, logql.SelectLogParams{ QueryRequest: &logproto.QueryRequest{ Selector: matcher, @@ -473,6 +474,7 @@ func (q *Querier) seriesForMatcher(ctx context.Context, from, through time.Time, Start: from, End: through, Direction: logproto.FORWARD, + Shards: shards, }, }) if err != nil { diff --git a/pkg/querier/queryrange/codec.go b/pkg/querier/queryrange/codec.go index 871063dd4bee..ecee3b2b0812 100644 --- a/pkg/querier/queryrange/codec.go +++ b/pkg/querier/queryrange/codec.go @@ -108,6 +108,7 @@ func (r *LokiSeriesRequest) LogToSpan(sp opentracing.Span) { otlog.String("matchers", strings.Join(r.GetMatch(), ",")), otlog.String("start", timestamp.Time(r.GetStart()).String()), otlog.String("end", timestamp.Time(r.GetEnd()).String()), + otlog.String("shards", strings.Join(r.GetShards(), ",")), ) } @@ -196,7 +197,6 @@ func (Codec) DecodeRequest(_ context.Context, r *http.Request) (queryrange.Reque default: return nil, httpgrpc.Errorf(http.StatusBadRequest, fmt.Sprintf("unknown request path: %s", r.URL.Path)) } - } func (Codec) EncodeRequest(ctx context.Context, r queryrange.Request) (*http.Request, error) { @@ -235,7 +235,9 @@ func (Codec) EncodeRequest(ctx context.Context, r queryrange.Request) (*http.Req "end": []string{fmt.Sprintf("%d", request.EndTs.UnixNano())}, "match[]": request.Match, } - + if len(request.Shards) > 0 { + params["shards"] = request.Shards + } u := &url.URL{ Path: "/loki/api/v1/series", RawQuery: params.Encode(), @@ -355,7 +357,6 @@ func (Codec) DecodeResponse(ctx context.Context, r *http.Response, req queryrang return nil, httpgrpc.Errorf(http.StatusBadRequest, "unsupported response type") } } - } func (Codec) EncodeResponse(ctx context.Context, res queryrange.Response) (*http.Response, error) { @@ -482,7 +483,6 @@ func (Codec) MergeResponse(responses ...queryrange.Response) (queryrange.Respons lokiSeriesData = append(lokiSeriesData, series) uniqueSeries[series.String()] = struct{}{} } - } } @@ -504,7 +504,6 @@ func (Codec) MergeResponse(responses ...queryrange.Response) (queryrange.Respons names = append(names, labelName) uniqueNames[labelName] = struct{}{} } - } } @@ -520,7 +519,6 @@ func (Codec) MergeResponse(responses ...queryrange.Response) (queryrange.Respons // mergeOrderedNonOverlappingStreams merges a set of ordered, nonoverlapping responses by concatenating matching streams then running them through a heap to pull out limit values func mergeOrderedNonOverlappingStreams(resps []*LokiResponse, limit uint32, direction logproto.Direction) []logproto.Stream { - var total int // turn resps -> map[labels] []entries @@ -612,7 +610,6 @@ func mergeOrderedNonOverlappingStreams(resps []*LokiResponse, limit uint32, dire } return results - } func toProto(m loghttp.Matrix) []queryrange.SampleStream { @@ -642,7 +639,6 @@ func (res LokiResponse) Count() int64 { result += int64(len(s.Entries)) } return result - } type paramsWrapper struct { @@ -658,12 +654,15 @@ func paramsFromRequest(req queryrange.Request) *paramsWrapper { func (p paramsWrapper) Query() string { return p.LokiRequest.Query } + func (p paramsWrapper) Start() time.Time { return p.StartTs } + func (p paramsWrapper) End() time.Time { return p.EndTs } + func (p paramsWrapper) Step() time.Duration { return time.Duration(p.LokiRequest.Step * 1e6) } diff --git a/pkg/querier/queryrange/queryrange.pb.go b/pkg/querier/queryrange/queryrange.pb.go index 94224f22225a..893f3e51c716 100644 --- a/pkg/querier/queryrange/queryrange.pb.go +++ b/pkg/querier/queryrange/queryrange.pb.go @@ -237,6 +237,7 @@ type LokiSeriesRequest struct { StartTs time.Time `protobuf:"bytes,2,opt,name=startTs,proto3,stdtime" json:"startTs"` EndTs time.Time `protobuf:"bytes,3,opt,name=endTs,proto3,stdtime" json:"endTs"` Path string `protobuf:"bytes,4,opt,name=path,proto3" json:"path,omitempty"` + Shards []string `protobuf:"bytes,5,rep,name=shards,proto3" json:"shards"` } func (m *LokiSeriesRequest) Reset() { *m = LokiSeriesRequest{} } @@ -299,6 +300,13 @@ func (m *LokiSeriesRequest) GetPath() string { return "" } +func (m *LokiSeriesRequest) GetShards() []string { + if m != nil { + return m.Shards + } + return nil +} + type LokiSeriesResponse struct { Status string `protobuf:"bytes,1,opt,name=Status,proto3" json:"status"` Data []logproto.SeriesIdentifier `protobuf:"bytes,2,rep,name=Data,proto3" json:"data,omitempty"` @@ -590,62 +598,62 @@ func init() { } var fileDescriptor_51b9d53b40d11902 = []byte{ - // 870 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x56, 0x4f, 0x8f, 0xdc, 0x34, - 0x14, 0x8f, 0x27, 0xf3, 0x67, 0xe3, 0xa5, 0x0b, 0x78, 0x4b, 0x1b, 0x2d, 0x52, 0x12, 0x8d, 0x10, - 0x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b8, 0xb9, 0x65, 0xf8, 0x35, 0x80, 0xcf, 0xa9, 0x62, - 0xd5, 0xdb, 0x56, 0x14, 0xde, 0x82, 0x1b, 0xbc, 0x59, 0x37, 0x72, 0x0b, 0xfe, 0x19, 0xdc, 0xa4, - 0x7b, 0x52, 0x87, 0x00, 0xaf, 0xb2, 0xd0, 0xcd, 0x0b, 0xb3, 0xb9, 0xf3, 0x57, 0xb3, 0x59, 0xa5, - 0x38, 0xf6, 0x34, 0x4e, 0xde, 0x3c, 0x3d, 0x0b, 0x9c, 0x07, 0x67, 0x81, 0xf3, 0xe8, 0x2c, 0x00, - 0x5f, 0x2d, 0x02, 0xf0, 0xc3, 0x22, 0x00, 0x27, 0x8b, 0x00, 0x9c, 0x2e, 0x02, 0xf0, 0xdb, 0x22, - 0x00, 0xbf, 0x2f, 0x02, 0xe7, 0xd1, 0x22, 0x00, 0xf7, 0xcf, 0x03, 0xe7, 0xf4, 0x3c, 0x70, 0x1e, - 0x9c, 0x07, 0xce, 0x7e, 0x5f, 0xbf, 0xf0, 0xe6, 0x1f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf4, 0xb2, - 0x1b, 0x96, 0x8f, 0x09, 0x00, 0x00, + // 874 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x56, 0x4f, 0x6f, 0xdc, 0x44, + 0x14, 0xdf, 0x59, 0xef, 0x9f, 0x78, 0x42, 0x03, 0x4c, 0x4a, 0x6b, 0x05, 0xc9, 0xb6, 0x56, 0x08, + 0x16, 0x41, 0xbd, 0x22, 0x85, 0x0b, 0x12, 0xa8, 0xb5, 0xca, 0x3f, 0xa9, 0x02, 0x34, 0xcd, 0x81, + 0xeb, 0x64, 0x3d, 0xf1, 0x9a, 0xd8, 0x3b, 0xce, 0xcc, 0x2c, 0x22, 0x37, 0xae, 0xdc, 0x7a, 0x03, + 0x3e, 0x01, 0x88, 0x33, 0x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10, 0xec, 0x08, 0x49, 0x4b, + 0xcf, 0x09, 0xc1, 0xd0, 0xc1, 0x5a, 0x46, 0xef, 0xc3, 0xbe, 0x90, 0x84, 0xcb, 0x3d, 0xe1, 0x75, + 0x42, 0x30, 0xdc, 0xdc, 0xdd, 0x89, 0x4c, 0x0a, 0x51, 0x93, 0x42, 0xb4, 0xd7, 0xa4, 0x10, 0x6f, + 0x9c, 0x54, 0x41, 0xeb, 0xfe, 0xef, 0x01, 0xc0, 0x4d, 0x10, 0x7a, 0x17, 0x76, 0xe9, 0x34, 0xd9, + 0x13, 0x5e, 0x77, 0x8d, 0x68, 0x13, 0x82, 0xde, 0x82, 0x6e, 0x92, 0x71, 0x3a, 0x96, 0x19, 0x9b, + 0x7a, 0xbd, 0x10, 0x0c, 0xb7, 0x76, 0xb7, 0xa3, 0x25, 0xf6, 0x77, 0x9a, 0x23, 0xbc, 0xf2, 0x52, + 0x25, 0x94, 0x44, 0x4e, 0xbc, 0xbe, 0xae, 0x56, 0xcb, 0x68, 0x00, 0x7b, 0x62, 0x42, 0x78, 0x22, + 0xbc, 0x8d, 0xd0, 0x19, 0xba, 0x31, 0x5c, 0x54, 0x41, 0x6d, 0xc1, 0xf5, 0xff, 0xe0, 0xbb, 0x0e, + 0x7c, 0xce, 0xc0, 0x26, 0x4a, 0x36, 0x15, 0x54, 0x05, 0xdd, 0x93, 0x44, 0xce, 0x84, 0x01, 0xae, + 0x0e, 0xd2, 0x16, 0x5c, 0x9f, 0xa0, 0x5b, 0xb0, 0x73, 0x87, 0x48, 0xa2, 0x41, 0xdc, 0xdc, 0xbd, + 0x1a, 0x59, 0xdd, 0x52, 0x77, 0xa9, 0xb3, 0xf8, 0x9a, 0x2a, 0x6a, 0x51, 0x05, 0x5b, 0x09, 0x91, + 0xe4, 0x4d, 0x56, 0x64, 0x92, 0x16, 0xa5, 0x3c, 0xc6, 0x3a, 0x12, 0xbd, 0x03, 0xdd, 0x0f, 0x38, + 0x67, 0x7c, 0xef, 0x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8f, + 0xdb, 0xdf, 0x2a, 0xa4, 0x65, 0x6f, 0xec, 0xf8, 0xed, 0xd3, 0x33, 0xbf, 0xf5, 0xe0, 0xcc, 0x6f, + 0x3d, 0x3a, 0xf3, 0xc1, 0x37, 0x73, 0x1f, 0xfc, 0x34, 0xf7, 0xc1, 0xc9, 0xdc, 0x07, 0xa7, 0x73, + 0x1f, 0xfc, 0x31, 0xf7, 0xc1, 0x9f, 0x73, 0xbf, 0xf5, 0x68, 0xee, 0x83, 0xfb, 0xe7, 0x7e, 0xeb, + 0xf4, 0xdc, 0x6f, 0x3d, 0x38, 0xf7, 0x5b, 0xfb, 0x3d, 0x5d, 0xe1, 0xcd, 0xbf, 0x02, 0x00, 0x00, + 0xff, 0xff, 0xb2, 0xbc, 0xe5, 0x40, 0xb3, 0x09, 0x00, 0x00, } func (this *LokiRequest) Equal(that interface{}) bool { @@ -787,6 +795,14 @@ func (this *LokiSeriesRequest) Equal(that interface{}) bool { if this.Path != that1.Path { return false } + if len(this.Shards) != len(that1.Shards) { + return false + } + for i := range this.Shards { + if this.Shards[i] != that1.Shards[i] { + return false + } + } return true } func (this *LokiSeriesResponse) Equal(that interface{}) bool { @@ -1003,12 +1019,13 @@ func (this *LokiSeriesRequest) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 8) + s := make([]string, 0, 9) s = append(s, "&queryrange.LokiSeriesRequest{") s = append(s, "Match: "+fmt.Sprintf("%#v", this.Match)+",\n") s = append(s, "StartTs: "+fmt.Sprintf("%#v", this.StartTs)+",\n") s = append(s, "EndTs: "+fmt.Sprintf("%#v", this.EndTs)+",\n") s = append(s, "Path: "+fmt.Sprintf("%#v", this.Path)+",\n") + s = append(s, "Shards: "+fmt.Sprintf("%#v", this.Shards)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -1295,6 +1312,21 @@ func (m *LokiSeriesRequest) MarshalTo(dAtA []byte) (int, error) { i = encodeVarintQueryrange(dAtA, i, uint64(len(m.Path))) i += copy(dAtA[i:], m.Path) } + if len(m.Shards) > 0 { + for _, s := range m.Shards { + dAtA[i] = 0x2a + i++ + l = len(s) + for l >= 1<<7 { + dAtA[i] = uint8(uint64(l)&0x7f | 0x80) + l >>= 7 + i++ + } + dAtA[i] = uint8(l) + i++ + i += copy(dAtA[i:], s) + } + } return i, nil } @@ -1624,6 +1656,12 @@ func (m *LokiSeriesRequest) Size() (n int) { if l > 0 { n += 1 + l + sovQueryrange(uint64(l)) } + if len(m.Shards) > 0 { + for _, s := range m.Shards { + l = len(s) + n += 1 + l + sovQueryrange(uint64(l)) + } + } return n } @@ -1791,6 +1829,7 @@ func (this *LokiSeriesRequest) String() string { `StartTs:` + strings.Replace(strings.Replace(this.StartTs.String(), "Timestamp", "types.Timestamp", 1), `&`, ``, 1) + `,`, `EndTs:` + strings.Replace(strings.Replace(this.EndTs.String(), "Timestamp", "types.Timestamp", 1), `&`, ``, 1) + `,`, `Path:` + fmt.Sprintf("%v", this.Path) + `,`, + `Shards:` + fmt.Sprintf("%v", this.Shards) + `,`, `}`, }, "") return s @@ -2600,6 +2639,38 @@ func (m *LokiSeriesRequest) Unmarshal(dAtA []byte) error { } m.Path = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Shards", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQueryrange + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQueryrange + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQueryrange + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Shards = append(m.Shards, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQueryrange(dAtA[iNdEx:]) diff --git a/pkg/querier/queryrange/queryrange.proto b/pkg/querier/queryrange/queryrange.proto index 6ae36fa49785..3513454867de 100644 --- a/pkg/querier/queryrange/queryrange.proto +++ b/pkg/querier/queryrange/queryrange.proto @@ -39,6 +39,8 @@ message LokiSeriesRequest { google.protobuf.Timestamp startTs = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; google.protobuf.Timestamp endTs = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; string path = 4; + repeated string shards = 5 [(gogoproto.jsontag) = "shards"]; + } message LokiSeriesResponse { @@ -71,4 +73,4 @@ message LokiData { message LokiPromResponse { queryrange.PrometheusResponse response = 1 [(gogoproto.nullable) = true]; stats.Result statistics = 2 [(gogoproto.nullable) = false]; -} \ No newline at end of file +} diff --git a/pkg/querier/queryrange/querysharding.go b/pkg/querier/queryrange/querysharding.go index c396054532ee..2775b6893bb7 100644 --- a/pkg/querier/queryrange/querysharding.go +++ b/pkg/querier/queryrange/querysharding.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/cortexproject/cortex/pkg/querier/astmapper" "github.com/cortexproject/cortex/pkg/querier/queryrange" "github.com/cortexproject/cortex/pkg/util" "github.com/cortexproject/cortex/pkg/util/spanlogger" @@ -54,7 +55,6 @@ func NewQueryShardMiddleware( next: queryrange.InstrumentMiddleware("sharding-bypass", middlewareMetrics).Wrap(next), } }) - } func newASTMapperware( @@ -186,3 +186,86 @@ func hasShards(confs queryrange.ShardingConfigs) bool { } return false } + +// NewSeriesQueryShardMiddleware creates a middleware which shards series queries. +func NewSeriesQueryShardMiddleware( + logger log.Logger, + confs queryrange.ShardingConfigs, + middlewareMetrics *queryrange.InstrumentMiddlewareMetrics, + shardingMetrics *logql.ShardingMetrics, + limits queryrange.Limits, + merger queryrange.Merger, +) queryrange.Middleware { + + noshards := !hasShards(confs) + + if noshards { + level.Warn(logger).Log( + "middleware", "QueryShard", + "msg", "no configuration with shard found", + "confs", fmt.Sprintf("%+v", confs), + ) + return queryrange.PassthroughMiddleware + } + return queryrange.MiddlewareFunc(func(next queryrange.Handler) queryrange.Handler { + return queryrange.InstrumentMiddleware("sharding", middlewareMetrics).Wrap( + &seriesShardingHandler{ + confs: confs, + logger: logger, + next: next, + metrics: shardingMetrics, + limits: limits, + merger: merger, + }, + ) + }) +} + +type seriesShardingHandler struct { + confs queryrange.ShardingConfigs + logger log.Logger + next queryrange.Handler + metrics *logql.ShardingMetrics + limits queryrange.Limits + merger queryrange.Merger +} + +func (ss *seriesShardingHandler) Do(ctx context.Context, r queryrange.Request) (queryrange.Response, error) { + conf, err := ss.confs.GetConf(r) + // cannot shard with this timerange + if err != nil { + level.Warn(ss.logger).Log("err", err.Error(), "msg", "skipped sharding for request") + return ss.next.Do(ctx, r) + } + + if conf.RowShards <= 1 { + return ss.next.Do(ctx, r) + } + + req, ok := r.(*LokiSeriesRequest) + if !ok { + return nil, fmt.Errorf("expected *LokiSeriesRequest, got (%T)", r) + } + + ss.metrics.Shards.WithLabelValues("series").Inc() + ss.metrics.ShardFactor.Observe(float64(conf.RowShards)) + + requests := make([]queryrange.Request, 0, conf.RowShards) + for i := 0; i < int(conf.RowShards); i++ { + shardedRequest := *req + shardedRequest.Shards = []string{astmapper.ShardAnnotation{ + Shard: i, + Of: int(conf.RowShards), + }.String()} + requests = append(requests, &shardedRequest) + } + requestResponses, err := queryrange.DoRequests(ctx, ss.next, requests, ss.limits) + if err != nil { + return nil, err + } + responses := make([]queryrange.Response, 0, len(requestResponses)) + for _, res := range requestResponses { + responses = append(responses, res.Response) + } + return ss.merger.MergeResponse(responses...) +} diff --git a/pkg/querier/queryrange/querysharding_test.go b/pkg/querier/queryrange/querysharding_test.go index 333734a24ca4..d5b8e676ff30 100644 --- a/pkg/querier/queryrange/querysharding_test.go +++ b/pkg/querier/queryrange/querysharding_test.go @@ -2,6 +2,7 @@ package queryrange import ( "context" + "errors" "fmt" "math" "sort" @@ -14,6 +15,7 @@ import ( "github.com/cortexproject/cortex/pkg/util" "github.com/go-kit/kit/log" "github.com/stretchr/testify/require" + "github.com/weaveworks/common/user" "github.com/grafana/loki/pkg/loghttp" "github.com/grafana/loki/pkg/logproto" @@ -158,7 +160,6 @@ func Test_astMapper(t *testing.T) { require.Nil(t, err) require.Equal(t, called, 2) require.Equal(t, expected.(*LokiResponse).Data, resp.(*LokiResponse).Data) - } func Test_ShardingByPass(t *testing.T) { @@ -232,3 +233,75 @@ func mockHandler(resp queryrange.Response, err error) queryrange.Handler { return resp, err }) } + +func Test_SeriesShardingHandler(t *testing.T) { + sharding := NewSeriesQueryShardMiddleware(log.NewNopLogger(), queryrange.ShardingConfigs{ + chunk.PeriodConfig{ + RowShards: 3, + }, + }, + queryrange.NewInstrumentMiddlewareMetrics(nil), + nilShardingMetrics, + fakeLimits{ + maxQueryParallelism: 10, + }, + LokiCodec, + ) + ctx := user.InjectOrgID(context.Background(), "1") + + response, err := sharding.Wrap(queryrange.HandlerFunc(func(c context.Context, r queryrange.Request) (queryrange.Response, error) { + req, ok := r.(*LokiSeriesRequest) + if !ok { + return nil, errors.New("not a series call") + } + return &LokiSeriesResponse{ + Status: "success", + Version: 1, + Data: []logproto.SeriesIdentifier{ + { + Labels: map[string]string{ + "foo": "bar", + }, + }, + { + Labels: map[string]string{ + "shard": req.Shards[0], + }, + }, + }, + }, nil + })).Do(ctx, &LokiSeriesRequest{ + Match: []string{"foo", "bar"}, + StartTs: time.Unix(0, 1), + EndTs: time.Unix(0, 10), + Path: "foo", + }) + + require.NoError(t, err) + require.Equal(t, &LokiSeriesResponse{ + Status: "success", + Version: 1, + Data: []logproto.SeriesIdentifier{ + { + Labels: map[string]string{ + "foo": "bar", + }, + }, + { + Labels: map[string]string{ + "shard": "0_of_3", + }, + }, + { + Labels: map[string]string{ + "shard": "1_of_3", + }, + }, + { + Labels: map[string]string{ + "shard": "2_of_3", + }, + }, + }, + }, response) +} diff --git a/pkg/querier/queryrange/roundtrip.go b/pkg/querier/queryrange/roundtrip.go index ffdd7b7cd6d9..bfe6e41a7fa9 100644 --- a/pkg/querier/queryrange/roundtrip.go +++ b/pkg/querier/queryrange/roundtrip.go @@ -66,7 +66,7 @@ func NewTripperware( return nil, nil, err } - seriesTripperware, err := NewSeriesTripperware(cfg, log, limits, LokiCodec, instrumentMetrics, retryMetrics, splitByMetrics) + seriesTripperware, err := NewSeriesTripperware(cfg, log, limits, LokiCodec, instrumentMetrics, retryMetrics, splitByMetrics, shardingMetrics, schema) if err != nil { return nil, nil, err } @@ -263,6 +263,8 @@ func NewSeriesTripperware( instrumentMetrics *queryrange.InstrumentMiddlewareMetrics, retryMiddlewareMetrics *queryrange.RetryMiddlewareMetrics, splitByMetrics *SplitByMetrics, + shardingMetrics *logql.ShardingMetrics, + schema chunk.SchemaConfig, ) (queryrange.Tripperware, error) { queryRangeMiddleware := []queryrange.Middleware{} if cfg.SplitQueriesByInterval != 0 { @@ -278,9 +280,22 @@ func NewSeriesTripperware( queryRangeMiddleware = append(queryRangeMiddleware, queryrange.InstrumentMiddleware("retry", instrumentMetrics), queryrange.NewRetryMiddleware(log, cfg.MaxRetries, retryMiddlewareMetrics)) } + if cfg.ShardedQueries { + queryRangeMiddleware = append(queryRangeMiddleware, + NewSeriesQueryShardMiddleware( + log, + schema.Configs, + instrumentMetrics, + shardingMetrics, + limits, + codec, + ), + ) + } + return func(next http.RoundTripper) http.RoundTripper { if len(queryRangeMiddleware) > 0 { - return queryrange.NewRoundTripper(next, codec, queryRangeMiddleware...) + return NewLimitedRoundTripper(next, codec, limits, queryRangeMiddleware...) } return next }, nil diff --git a/pkg/querier/queryrange/split_by_interval.go b/pkg/querier/queryrange/split_by_interval.go index 30bfe03e8a5e..18947d367307 100644 --- a/pkg/querier/queryrange/split_by_interval.go +++ b/pkg/querier/queryrange/split_by_interval.go @@ -236,6 +236,7 @@ func splitByTime(req queryrange.Request, interval time.Duration) []queryrange.Re Path: r.Path, StartTs: start, EndTs: end, + Shards: r.Shards, }) }) case *LokiLabelNamesRequest: diff --git a/pkg/storage/store.go b/pkg/storage/store.go index 9949bf61d8f3..c4e2b3b58daf 100644 --- a/pkg/storage/store.go +++ b/pkg/storage/store.go @@ -157,11 +157,22 @@ func decodeReq(req logql.QueryParams) ([]*labels.Matcher, model.Time, model.Time return nil, 0, 0, err } matchers = append(matchers, nameLabelMatcher) + if err != nil { + return nil, 0, 0, err + } + matchers, err = injectShardLabel(req.GetShards(), matchers) + if err != nil { + return nil, 0, 0, err + } + from, through := util.RoundToMilliseconds(req.GetStart(), req.GetEnd()) + return matchers, from, through, nil +} - if shards := req.GetShards(); shards != nil { +func injectShardLabel(shards []string, matchers []*labels.Matcher) ([]*labels.Matcher, error) { + if shards != nil { parsed, err := logql.ParseShards(shards) if err != nil { - return nil, 0, 0, err + return nil, err } for _, s := range parsed { shardMatcher, err := labels.NewMatcher( @@ -170,19 +181,13 @@ func decodeReq(req logql.QueryParams) ([]*labels.Matcher, model.Time, model.Time s.String(), ) if err != nil { - return nil, 0, 0, err + return nil, err } matchers = append(matchers, shardMatcher) - - // TODO(owen-d): passing more than one shard will require - // a refactor to cortex to support it. We're leaving this codepath in - // preparation of that but will not pass more than one until it's supported. break // nolint:staticcheck } } - - from, through := util.RoundToMilliseconds(req.GetStart(), req.GetEnd()) - return matchers, from, through, nil + return matchers, nil } func (s *store) SetChunkFilterer(chunkFilterer RequestChunkFilterer) { @@ -238,6 +243,10 @@ func (s *store) GetSeries(ctx context.Context, req logql.SelectLogParams) ([]log return nil, err } matchers = []*labels.Matcher{nameLabelMatcher} + matchers, err = injectShardLabel(req.GetShards(), matchers) + if err != nil { + return nil, err + } } else { var err error matchers, from, through, err = decodeReq(req) From 1e58339a0143616b75955271ca0be1ba57f911df Mon Sep 17 00:00:00 2001 From: Cyril Tovena Date: Wed, 16 Jun 2021 08:02:44 +0200 Subject: [PATCH 2/2] Fixes tests sorting. Signed-off-by: Cyril Tovena --- pkg/querier/queryrange/querysharding_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/querier/queryrange/querysharding_test.go b/pkg/querier/queryrange/querysharding_test.go index d5b8e676ff30..5346dba79598 100644 --- a/pkg/querier/queryrange/querysharding_test.go +++ b/pkg/querier/queryrange/querysharding_test.go @@ -277,8 +277,7 @@ func Test_SeriesShardingHandler(t *testing.T) { Path: "foo", }) - require.NoError(t, err) - require.Equal(t, &LokiSeriesResponse{ + expected := &LokiSeriesResponse{ Status: "success", Version: 1, Data: []logproto.SeriesIdentifier{ @@ -303,5 +302,14 @@ func Test_SeriesShardingHandler(t *testing.T) { }, }, }, - }, response) + } + sort.Slice(expected.Data, func(i, j int) bool { + return expected.Data[i].Labels["shard"] > expected.Data[j].Labels["shard"] + }) + actual := response.(*LokiSeriesResponse) + sort.Slice(actual.Data, func(i, j int) bool { + return actual.Data[i].Labels["shard"] > actual.Data[j].Labels["shard"] + }) + require.NoError(t, err) + require.Equal(t, expected, actual) }