|
1 | 1 | package metrics |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "errors" |
6 | 5 | "math" |
7 | 6 | "sort" |
8 | 7 | "strconv" |
9 | 8 |
|
10 | | - "github.com/getsentry/sentry-go" |
11 | | - "github.com/getsentry/vroom/internal/chunk" |
12 | 9 | "github.com/getsentry/vroom/internal/examples" |
13 | 10 | "github.com/getsentry/vroom/internal/nodetree" |
14 | | - "github.com/getsentry/vroom/internal/profile" |
15 | | - "github.com/getsentry/vroom/internal/storageutil" |
16 | | - "gocloud.dev/blob" |
17 | 11 | ) |
18 | 12 |
|
19 | 13 | type ( |
@@ -203,107 +197,3 @@ func CapAndFilterFunctions(functions []nodetree.CallTreeFunction, maxUniqueFunct |
203 | 197 | } |
204 | 198 | return appFunctions |
205 | 199 | } |
206 | | - |
207 | | -func (ma *Aggregator) GetMetricsFromCandidates( |
208 | | - ctx context.Context, |
209 | | - storage *blob.Bucket, |
210 | | - organizationID uint64, |
211 | | - transactionProfileCandidates []examples.TransactionProfileCandidate, |
212 | | - continuousProfileCandidates []examples.ContinuousProfileCandidate, |
213 | | - jobs chan storageutil.ReadJob, |
214 | | -) ([]examples.FunctionMetrics, error) { |
215 | | - hub := sentry.GetHubFromContext(ctx) |
216 | | - |
217 | | - results := make(chan storageutil.ReadJobResult) |
218 | | - defer close(results) |
219 | | - |
220 | | - go func() { |
221 | | - for _, candidate := range transactionProfileCandidates { |
222 | | - jobs <- profile.ReadJob{ |
223 | | - Ctx: ctx, |
224 | | - OrganizationID: organizationID, |
225 | | - ProjectID: candidate.ProjectID, |
226 | | - ProfileID: candidate.ProfileID, |
227 | | - Storage: storage, |
228 | | - Result: results, |
229 | | - } |
230 | | - } |
231 | | - |
232 | | - for _, candidate := range continuousProfileCandidates { |
233 | | - jobs <- chunk.ReadJob{ |
234 | | - Ctx: ctx, |
235 | | - OrganizationID: organizationID, |
236 | | - ProjectID: candidate.ProjectID, |
237 | | - ProfilerID: candidate.ProfilerID, |
238 | | - ChunkID: candidate.ChunkID, |
239 | | - TransactionID: candidate.TransactionID, |
240 | | - ThreadID: candidate.ThreadID, |
241 | | - Start: candidate.Start, |
242 | | - End: candidate.End, |
243 | | - Storage: storage, |
244 | | - Result: results, |
245 | | - } |
246 | | - } |
247 | | - }() |
248 | | - |
249 | | - numCandidates := len(transactionProfileCandidates) + len(continuousProfileCandidates) |
250 | | - |
251 | | - for i := 0; i < numCandidates; i++ { |
252 | | - res := <-results |
253 | | - |
254 | | - err := res.Error() |
255 | | - if err != nil { |
256 | | - if errors.Is(err, storageutil.ErrObjectNotFound) { |
257 | | - continue |
258 | | - } |
259 | | - if errors.Is(err, context.DeadlineExceeded) { |
260 | | - return nil, err |
261 | | - } |
262 | | - if hub != nil { |
263 | | - hub.CaptureException(err) |
264 | | - } |
265 | | - continue |
266 | | - } |
267 | | - |
268 | | - var resultMetadata examples.ExampleMetadata |
269 | | - if result, ok := res.(profile.ReadJobResult); ok { |
270 | | - profileCallTrees, err := result.Profile.CallTrees() |
271 | | - if err != nil { |
272 | | - hub.CaptureException(err) |
273 | | - continue |
274 | | - } |
275 | | - start, end := result.Profile.StartAndEndEpoch() |
276 | | - resultMetadata = examples.NewExampleFromProfileID( |
277 | | - result.Profile.ProjectID(), |
278 | | - result.Profile.ID(), |
279 | | - start, |
280 | | - end, |
281 | | - ) |
282 | | - functions := CapAndFilterFunctions(ExtractFunctionsFromCallTrees(profileCallTrees, ma.MinDepth), int(ma.MaxUniqueFunctions), true) |
283 | | - ma.AddFunctions(functions, resultMetadata) |
284 | | - } else if result, ok := res.(chunk.ReadJobResult); ok { |
285 | | - chunkCallTrees, err := result.Chunk.CallTrees(result.ThreadID) |
286 | | - if err != nil { |
287 | | - hub.CaptureException(err) |
288 | | - continue |
289 | | - } |
290 | | - |
291 | | - resultMetadata = examples.NewExampleFromProfilerChunk( |
292 | | - result.Chunk.GetProjectID(), |
293 | | - result.Chunk.GetProfilerID(), |
294 | | - result.Chunk.GetID(), |
295 | | - result.TransactionID, |
296 | | - result.ThreadID, |
297 | | - result.Start, |
298 | | - result.End, |
299 | | - ) |
300 | | - functions := CapAndFilterFunctions(ExtractFunctionsFromCallTrees(chunkCallTrees, ma.MinDepth), int(ma.MaxUniqueFunctions), true) |
301 | | - ma.AddFunctions(functions, resultMetadata) |
302 | | - } else { |
303 | | - // this should never happen |
304 | | - return nil, errors.New("unexpected result from storage") |
305 | | - } |
306 | | - } |
307 | | - |
308 | | - return ma.ToMetrics(), nil |
309 | | -} |
0 commit comments