From 775d89a7185571eac1d42913b552b6c6ef8ed317 Mon Sep 17 00:00:00 2001 From: Aditya C S Date: Sat, 29 Aug 2020 10:21:08 +0530 Subject: [PATCH] Validate max_query_length in Label API --- pkg/querier/querier.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/querier/querier.go b/pkg/querier/querier.go index d3a07a97f0ba1..6e072e84dbe8e 100644 --- a/pkg/querier/querier.go +++ b/pkg/querier/querier.go @@ -281,6 +281,15 @@ func (q *Querier) queryIngestersForSample(ctx context.Context, params logql.Sele // Label does the heavy lifting for a Label query. func (q *Querier) Label(ctx context.Context, req *logproto.LabelRequest) (*logproto.LabelResponse, error) { + userID, err := user.ExtractOrgID(ctx) + if err != nil { + return nil, err + } + + if err = q.validateQueryTimeRange(userID, *req.Start, *req.End); err != nil { + return nil, err + } + // Enforce the query timeout while querying backends ctx, cancel := context.WithDeadline(ctx, time.Now().Add(q.cfg.QueryTimeout)) defer cancel() @@ -292,11 +301,6 @@ func (q *Querier) Label(ctx context.Context, req *logproto.LabelRequest) (*logpr return nil, err } - userID, err := user.ExtractOrgID(ctx) - if err != nil { - return nil, err - } - from, through := model.TimeFromUnixNano(req.Start.UnixNano()), model.TimeFromUnixNano(req.End.UnixNano()) var storeValues []string if req.Values {