MCPcopy
hub / github.com/grafana/tempo / createAllIterator

Function createAllIterator

tempodb/encoding/vparquet3/block_traceql.go:1435–1477  ·  view source on GitHub ↗
(ctx context.Context, primaryIter parquetquery.Iterator, conds []traceql.Condition, allConditions bool, start, end uint64,
	rgs []parquet.RowGroup, pf *parquet.File, dc backend.DedicatedColumns, selectAll bool,
)

Source from the content-addressed store, hash-verified

1433}
1434
1435func createAllIterator(ctx context.Context, primaryIter parquetquery.Iterator, conds []traceql.Condition, allConditions bool, start, end uint64,
1436 rgs []parquet.RowGroup, pf *parquet.File, dc backend.DedicatedColumns, selectAll bool,
1437) (parquetquery.Iterator, error) {
1438 // categorizeConditions conditions into span-level or resource-level
1439 mingledConditions, spanConditions, resourceConditions, traceConditions, err := categorizeConditions(conds)
1440 if err != nil {
1441 return nil, err
1442 }
1443
1444 makeIter := makeIterFunc(ctx, rgs, pf)
1445 makeNilIter := makeNilIterFunc(ctx, rgs, pf)
1446
1447 // Global state
1448 // Span-filtering behavior changes depending on the resource-filtering in effect,
1449 // and vice-versa. For example consider the query { span.a=1 }. If no spans have a=1
1450 // then it generate the empty spanset.
1451 // However once we add a resource condition: { span.a=1 || resource.b=2 }, now the span
1452 // filtering must return all spans, even if no spans have a=1, because they might be
1453 // matched upstream to a resource.
1454 // TODO - After introducing AllConditions it seems like some of this logic overlaps.
1455 // Determine if it can be generalized or simplified.
1456
1457 // Don't return the final spanset upstream unless it matched at least 1 condition
1458 // anywhere, except in the case of the empty query: {}
1459 batchRequireAtLeastOneMatchOverall := len(conds) > 0 && len(traceConditions) == 0
1460
1461 // Optimization for queries like {resource.x... && span.y ...}
1462 // Requires no mingled scopes like .foo=x, which could be satisfied
1463 // one either resource or span.
1464 allConditions = allConditions && !mingledConditions
1465
1466 spanIter, err := createSpanIterator(makeIter, makeNilIter, primaryIter, spanConditions, allConditions, dc, selectAll)
1467 if err != nil {
1468 return nil, fmt.Errorf("creating span iterator: %w", err)
1469 }
1470
1471 resourceIter, err := createResourceIterator(makeIter, makeNilIter, spanIter, resourceConditions, batchRequireAtLeastOneMatchOverall, allConditions, dc, selectAll)
1472 if err != nil {
1473 return nil, fmt.Errorf("creating resource iterator: %w", err)
1474 }
1475
1476 return createTraceIterator(makeIter, resourceIter, traceConditions, start, end, allConditions, selectAll)
1477}
1478
1479// createSpanIterator iterates through all span-level columns, groups them into rows representing
1480// one span each. Spans are returned that match any of the given conditions.

Callers 1

fetchFunction · 0.70

Calls 6

categorizeConditionsFunction · 0.70
makeIterFuncFunction · 0.70
makeNilIterFuncFunction · 0.70
createSpanIteratorFunction · 0.70
createResourceIteratorFunction · 0.70
createTraceIteratorFunction · 0.70

Tested by

no test coverage detected