MCPcopy Create free account
hub / github.com/cortexproject/cortex / LabelNamesCommon

Method LabelNamesCommon

pkg/distributor/distributor.go:1423–1463  ·  view source on GitHub ↗
(ctx context.Context, from, to model.Time, hints *storage.LabelHints, f func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest, limiter *limiter.QueryLimiter) ([]any, error), matchers ...*labels.Matcher)

Source from the content-addressed store, hash-verified

1421}
1422
1423func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time, hints *storage.LabelHints, f func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest, limiter *limiter.QueryLimiter) ([]any, error), matchers ...*labels.Matcher) ([]string, error) {
1424 span, ctx := opentracing.StartSpanFromContext(ctx, "Distributor.LabelNames", opentracing.Tags{
1425 "start": from.Unix(),
1426 "end": to.Unix(),
1427 })
1428 defer span.Finish()
1429 replicationSet, err := d.GetIngestersForMetadata(ctx)
1430 if err != nil {
1431 return nil, err
1432 }
1433
1434 limit := getLimitFromLabelHints(hints)
1435 req, err := ingester_client.ToLabelNamesRequest(from, to, limit, matchers)
1436 if err != nil {
1437 return nil, err
1438 }
1439
1440 queryLimiter := limiter.QueryLimiterFromContextWithFallback(ctx)
1441 resps, err := f(ctx, replicationSet, req, queryLimiter)
1442 if err != nil {
1443 return nil, err
1444 }
1445
1446 span, _ = opentracing.StartSpanFromContext(ctx, "response_merge")
1447 defer span.Finish()
1448 values := make([][]string, len(resps))
1449 for i, resp := range resps {
1450 values[i] = resp.([]string)
1451 }
1452 r, err := util.MergeSlicesParallel(ctx, mergeSlicesParallelism, values...)
1453 if err != nil {
1454 return nil, err
1455 }
1456 if limit > 0 && len(r) > limit {
1457 r = r[:limit]
1458 }
1459
1460 span.SetTag("result_length", len(r))
1461
1462 return r, nil
1463}
1464
1465func (d *Distributor) LabelNamesStream(ctx context.Context, from, to model.Time, hints *storage.LabelHints, partialDataEnabled bool, matchers ...*labels.Matcher) ([]string, error) {
1466 return d.LabelNamesCommon(ctx, from, to, hints, func(ctx context.Context, rs ring.ReplicationSet, req *ingester_client.LabelNamesRequest, queryLimiter *limiter.QueryLimiter) ([]any, error) {

Callers 2

LabelNamesStreamMethod · 0.95
LabelNamesMethod · 0.95

Calls 6

MergeSlicesParallelFunction · 0.92
getLimitFromLabelHintsFunction · 0.85
FinishMethod · 0.80
SetTagMethod · 0.80

Tested by

no test coverage detected