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

Function blockMetasForSearch

modules/frontend/frontend.go:372–393  ·  view source on GitHub ↗

blockMetasForSearch returns a list of blocks that are relevant to the search query. start and end are unix timestamps in seconds. rf is the replication factor of the blocks to return.

(allBlocks []*backend.BlockMeta, start, end time.Time, filterFn func(m *backend.BlockMeta) bool)

Source from the content-addressed store, hash-verified

370// blockMetasForSearch returns a list of blocks that are relevant to the search query.
371// start and end are unix timestamps in seconds. rf is the replication factor of the blocks to return.
372func blockMetasForSearch(allBlocks []*backend.BlockMeta, start, end time.Time, filterFn func(m *backend.BlockMeta) bool) []*backend.BlockMeta {
373 blocks := make([]*backend.BlockMeta, 0, len(allBlocks)/50) // divide by 50 for luck
374 for _, m := range allBlocks {
375 // Block overlaps with search range if:
376 // block start is before or equal to search end AND block end is after or equal to search start
377 if !m.StartTime.After(end) && // block start <= search end
378 !m.EndTime.Before(start) && // block end >= search start
379 filterFn(m) {
380 blocks = append(blocks, m)
381 }
382 }
383
384 // search backwards in time with deterministic ordering
385 sort.Slice(blocks, func(i, j int) bool {
386 if !blocks[i].EndTime.Equal(blocks[j].EndTime) {
387 return blocks[i].EndTime.After(blocks[j].EndTime)
388 }
389 return blocks[i].BlockID.String() < blocks[j].BlockID.String()
390 })
391
392 return blocks
393}

Callers 4

backendRequestsMethod · 0.85
backendRequestsMethod · 0.85
TestBlockMetasForSearchFunction · 0.85
backendRequestsMethod · 0.85

Calls 2

EqualMethod · 0.45
StringMethod · 0.45

Tested by 1

TestBlockMetasForSearchFunction · 0.68