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

Method Find

tempodb/tempodb.go:332–418  ·  view source on GitHub ↗
(ctx context.Context, tenantID string, id common.ID, blockStart string, blockEnd string, timeStart int64, timeEnd int64, opts common.SearchOptions)

Source from the content-addressed store, hash-verified

330}
331
332func (rw *readerWriter) Find(ctx context.Context, tenantID string, id common.ID, blockStart string, blockEnd string, timeStart int64, timeEnd int64, opts common.SearchOptions) ([]*tempopb.TraceByIDResponse, []error, error) {
333 // tracing instrumentation
334 logger := log.WithContext(ctx, log.Logger)
335 ctx, span := tracer.Start(ctx, "store.Find")
336 defer span.End()
337
338 blockStartUUID, err := uuid.Parse(blockStart)
339 if err != nil {
340 return nil, nil, err
341 }
342 blockStartBytes, err := blockStartUUID.MarshalBinary()
343 if err != nil {
344 return nil, nil, err
345 }
346 blockEndUUID, err := uuid.Parse(blockEnd)
347 if err != nil {
348 return nil, nil, err
349 }
350 blockEndBytes, err := blockEndUUID.MarshalBinary()
351 if err != nil {
352 return nil, nil, err
353 }
354
355 // gather appropriate blocks
356 blocklist := rw.blocklist.Metas(tenantID)
357 compactedBlocklist := rw.blocklist.CompactedMetas(tenantID)
358 copiedBlocklist := make([]interface{}, 0, len(blocklist))
359 blocksSearched := 0
360 compactedBlocksSearched := 0
361
362 for _, b := range blocklist {
363 if includeBlock(b, id, blockStartBytes, blockEndBytes, timeStart, timeEnd) {
364 copiedBlocklist = append(copiedBlocklist, b)
365 blocksSearched++
366 }
367 }
368 for _, c := range compactedBlocklist {
369 if includeCompactedBlock(c, id, blockStartBytes, blockEndBytes, rw.cfg.BlocklistPoll, timeStart, timeEnd) {
370 copiedBlocklist = append(copiedBlocklist, &c.BlockMeta)
371 compactedBlocksSearched++
372 }
373 }
374 if len(copiedBlocklist) == 0 {
375 return nil, nil, nil
376 }
377
378 if rw.cfg != nil && rw.cfg.Search != nil {
379 rw.cfg.Search.ApplyToOptions(&opts)
380 }
381
382 partialTraces, funcErrs, err := rw.pool.RunJobs(ctx, copiedBlocklist, func(ctx context.Context, payload interface{}) (interface{}, error) {
383 meta := payload.(*backend.BlockMeta)
384 block, err := encoding.OpenBlock(meta, rw.r)
385 if err != nil {
386 return nil, fmt.Errorf("error opening block for reading, blockID: %s: %w", meta.BlockID.String(), err)
387 }
388
389 foundObject, err := block.FindTraceByID(ctx, id, opts)

Callers

nothing calls this directly

Calls 15

WithContextFunction · 0.92
OpenBlockFunction · 0.92
includeCompactedBlockFunction · 0.85
ApplyToOptionsMethod · 0.80
RunJobsMethod · 0.80
EncodeToStringMethod · 0.80
IntMethod · 0.80
includeBlockFunction · 0.70
StartMethod · 0.65
ParseMethod · 0.65
FindTraceByIDMethod · 0.65
LogMethod · 0.65

Tested by

no test coverage detected