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

Method Next

tempodb/encoding/vparquet5/block_traceql.go:1368–1449  ·  view source on GitHub ↗

Next has to handle two different style results. First is an initial set of spans that does not have a callback spanset. These can be passed directly through. Second is a set of spans that have spansets imposed by the callback (i.e. for grouping) these must be regrouped into the callback spansets

()

Source from the content-addressed store, hash-verified

1366// Second is a set of spans that have spansets imposed by the callback (i.e. for grouping)
1367// these must be regrouped into the callback spansets
1368func (i *rebatchIterator) Next() (*parquetquery.IteratorResult, error) {
1369 for {
1370 // see if we have a queue
1371 res := i.resultFromNextSpans()
1372 if res != nil {
1373 return res, nil
1374 }
1375
1376 // check the iterator for anything
1377 res, err := i.iter.Next()
1378 if err != nil {
1379 return nil, err
1380 }
1381 if res == nil {
1382 return nil, nil
1383 }
1384
1385 // get the spanset and see if we should pass it through or buffer for rebatching
1386 iface := res.OtherValueFromKey(otherEntrySpansetKey)
1387 if iface == nil {
1388 return nil, fmt.Errorf("engine assumption broken: spanset not found in other entries in rebatch")
1389 }
1390 ss, ok := iface.(*traceql.Spanset)
1391 if !ok {
1392 return nil, fmt.Errorf("engine assumption broken: spanset is not of type *traceql.Spanset in rebatch")
1393 }
1394
1395 // if this has no call back spanset just pass it on
1396 if len(ss.Spans) > 0 && ss.Spans[0].(*span).cbSpanset == nil {
1397 return res, nil
1398 }
1399
1400 // dump all spans into our buffer
1401 for _, s := range ss.Spans {
1402 sp := s.(*span)
1403 if !sp.cbSpansetFinal {
1404 continue
1405 }
1406
1407 // copy trace level data from the current iteration spanset into the rebatch spanset. only do this if
1408 // we don't have current data
1409 if sp.cbSpanset.DurationNanos == 0 {
1410 sp.cbSpanset.DurationNanos = ss.DurationNanos
1411 }
1412 if len(sp.cbSpanset.TraceID) == 0 {
1413 sp.cbSpanset.TraceID = ss.TraceID
1414 }
1415 if len(sp.cbSpanset.RootSpanName) == 0 {
1416 sp.cbSpanset.RootSpanName = ss.RootSpanName
1417 }
1418 if len(sp.cbSpanset.RootServiceName) == 0 {
1419 sp.cbSpanset.RootServiceName = ss.RootServiceName
1420 }
1421 if sp.cbSpanset.StartTimeUnixNanos == 0 {
1422 sp.cbSpanset.StartTimeUnixNanos = ss.StartTimeUnixNanos
1423 }
1424 if len(sp.cbSpanset.ServiceStats) == 0 {
1425 // If this spanset was created by a GroupOperation, the ServiceStats map is nil and must be allocated first

Callers

nothing calls this directly

Calls 4

resultFromNextSpansMethod · 0.95
OtherValueFromKeyMethod · 0.80
putSpansetFunction · 0.70
NextMethod · 0.65

Tested by

no test coverage detected