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

Function queryBucketForSummary

cmd/tempo-cli/cmd-query-trace-summary.go:89–214  ·  view source on GitHub ↗
(ctx context.Context, percentage float32, r backend.Reader, c backend.Compactor, tenantID string, traceID common.ID)

Source from the content-addressed store, hash-verified

87}
88
89func queryBucketForSummary(ctx context.Context, percentage float32, r backend.Reader, c backend.Compactor, tenantID string, traceID common.ID) (*TraceSummary, error) {
90 blockIDs, _, err := r.Blocks(context.Background(), tenantID)
91 if err != nil {
92 return nil, err
93 }
94
95 if percentage > 0 {
96 // shuffle
97 rand.Shuffle(len(blockIDs), func(i, j int) { blockIDs[i], blockIDs[j] = blockIDs[j], blockIDs[i] })
98
99 // get the first n%
100 total := len(blockIDs)
101 total = int(float32(total) * percentage)
102 blockIDs = blockIDs[:total]
103 }
104
105 fmt.Println("total blocks to search: ", len(blockIDs))
106
107 // Load in parallel
108 wg := boundedwaitgroup.New(50)
109 resultsCh := make(chan *queryResults)
110
111 go func() {
112 for blockNum, id := range blockIDs {
113 wg.Add(1)
114
115 go func(blockNum2 int, id2 uuid.UUID) {
116 defer wg.Done()
117
118 // search here
119 q, err := queryBlock(ctx, r, c, blockNum2, id2, tenantID, traceID)
120 if err != nil {
121 fmt.Println("Error querying block:", err)
122 return
123 }
124
125 if q != nil {
126 resultsCh <- q
127 }
128 }(blockNum, id)
129 }
130 }()
131
132 // cheap way to let the wait group get at least one .Add()
133 time.Sleep(time.Second)
134
135 go func() {
136 wg.Wait()
137 close(resultsCh)
138 }()
139
140 var rootSpan *v1.Span
141 var rootSpanResource *v1resource.Resource
142
143 numBlock := 0
144 size := 0
145 spanCount := 0
146

Callers 1

RunMethod · 0.85

Calls 10

NewFunction · 0.92
queryBlockFunction · 0.85
sortServiceNamesFunction · 0.85
GetStringValueMethod · 0.80
BlocksMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.65
SleepMethod · 0.65
WaitMethod · 0.65
SizeMethod · 0.65

Tested by

no test coverage detected