Skip to content

Commit 9ff6218

Browse files
authored
Parallize label queries to both stores (grafana#5997)
* Parallize label queries to both stores This executes label queries against ingesters and store in parallel, rather than sequentially * Return err without any checks as suggested
1 parent b315ed0 commit 9ff6218

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
* [5790](https://github.com/grafana/loki/pull/5790) **chaudum**: Add UDP support for Promtail's syslog target.
1717
* [5984](https://github.com/grafana/loki/pull/5984) **dannykopping** and **salvacorts**: Improve query performance by preventing unnecessary querying of ingesters when the query data is old enough to be in object storage.
1818
* [5943](https://github.com/grafana/loki/pull/5943) **tpaschalis**: Add configuration support for excluding configuration files when instantiating Promtail.
19+
* [5997](https://github.com/grafana/loki/pull/5997) **simonswine**: Querier: parallize label queries to both stores.
20+
* [5984](https://github.com/grafana/loki/pull/5984) **dannykopping** and **salvacorts**: Querier: prevent unnecessary calls to ingesters.
21+
* [5943](https://github.com/grafana/loki/pull/5943) **tpaschalis**: Add support for exclusion patterns in Promtail's static_config
1922
* [5879](https://github.com/grafana/loki/pull/5879) **MichelHollands**: Remove lines matching delete request expression when using "filter-and-delete" deletion mode.
2023
* [5899](https://github.com/grafana/loki/pull/5899) **simonswine**: Update go image to 1.17.9.
2124
* [5888](https://github.com/grafana/loki/pull/5888) **Papawy** Fix common configuration block net interface name when overwritten by ring common configuration.

pkg/querier/querier.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import (
66
"net/http"
77
"time"
88

9-
"github.com/prometheus/client_golang/prometheus"
10-
119
"github.com/go-kit/log/level"
10+
"github.com/grafana/dskit/tenant"
1211
"github.com/pkg/errors"
12+
"github.com/prometheus/client_golang/prometheus"
1313
"github.com/prometheus/common/model"
1414
"github.com/weaveworks/common/httpgrpc"
15+
"golang.org/x/sync/errgroup"
1516
"google.golang.org/grpc/health/grpc_health_v1"
1617

17-
"github.com/grafana/dskit/tenant"
18-
1918
"github.com/grafana/loki/pkg/iter"
2019
"github.com/grafana/loki/pkg/loghttp"
2120
"github.com/grafana/loki/pkg/logproto"
@@ -359,36 +358,43 @@ func (q *SingleTenantQuerier) Label(ctx context.Context, req *logproto.LabelRequ
359358
ctx, cancel := context.WithDeadline(ctx, time.Now().Add(q.cfg.QueryTimeout))
360359
defer cancel()
361360

361+
g, ctx := errgroup.WithContext(ctx)
362+
362363
ingesterQueryInterval, storeQueryInterval := q.buildQueryIntervals(*req.Start, *req.End)
363364

364365
var ingesterValues [][]string
365366
if !q.cfg.QueryStoreOnly && ingesterQueryInterval != nil {
366-
timeFramedReq := *req
367-
timeFramedReq.Start = &ingesterQueryInterval.start
368-
timeFramedReq.End = &ingesterQueryInterval.end
367+
g.Go(func() error {
368+
var err error
369+
timeFramedReq := *req
370+
timeFramedReq.Start = &ingesterQueryInterval.start
371+
timeFramedReq.End = &ingesterQueryInterval.end
369372

370-
ingesterValues, err = q.ingesterQuerier.Label(ctx, &timeFramedReq)
371-
if err != nil {
372-
return nil, err
373-
}
373+
ingesterValues, err = q.ingesterQuerier.Label(ctx, &timeFramedReq)
374+
return err
375+
})
374376
}
375377

376378
var storeValues []string
377379
if !q.cfg.QueryIngesterOnly && storeQueryInterval != nil {
378-
from := model.TimeFromUnixNano(storeQueryInterval.start.UnixNano())
379-
through := model.TimeFromUnixNano(storeQueryInterval.end.UnixNano())
380-
381-
if req.Values {
382-
storeValues, err = q.store.LabelValuesForMetricName(ctx, userID, from, through, "logs", req.Name)
383-
if err != nil {
384-
return nil, err
385-
}
386-
} else {
387-
storeValues, err = q.store.LabelNamesForMetricName(ctx, userID, from, through, "logs")
388-
if err != nil {
389-
return nil, err
380+
g.Go(func() error {
381+
var (
382+
err error
383+
from = model.TimeFromUnixNano(storeQueryInterval.start.UnixNano())
384+
through = model.TimeFromUnixNano(storeQueryInterval.end.UnixNano())
385+
)
386+
387+
if req.Values {
388+
storeValues, err = q.store.LabelValuesForMetricName(ctx, userID, from, through, "logs", req.Name)
389+
} else {
390+
storeValues, err = q.store.LabelNamesForMetricName(ctx, userID, from, through, "logs")
390391
}
391-
}
392+
return err
393+
})
394+
}
395+
396+
if err := g.Wait(); err != nil {
397+
return nil, err
392398
}
393399

394400
results := append(ingesterValues, storeValues)

0 commit comments

Comments
 (0)