From 75b1692915809f0155ccca7625e02e25dd25cf10 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Tue, 3 Dec 2024 11:19:53 -0500 Subject: [PATCH 1/2] chore(profiling): Remove unused chunks flamegraph endpoint Follow up to getsentry/sentry#81583 --- cmd/vroom/flamegraph.go | 75 -------------------------- cmd/vroom/main.go | 5 -- internal/flamegraph/flamegraph.go | 90 ------------------------------- 3 files changed, 170 deletions(-) diff --git a/cmd/vroom/flamegraph.go b/cmd/vroom/flamegraph.go index 73d4a14..590ad22 100644 --- a/cmd/vroom/flamegraph.go +++ b/cmd/vroom/flamegraph.go @@ -13,81 +13,6 @@ import ( "github.com/getsentry/vroom/internal/utils" ) -type postFlamegraphFromChunksMetadataBody struct { - ChunksMetadata []flamegraph.ChunkMetadata `json:"chunks_metadata"` -} - -func (env *environment) postFlamegraphFromChunksMetadata(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - hub := sentry.GetHubFromContext(ctx) - ps := httprouter.ParamsFromContext(ctx) - rawOrganizationID := ps.ByName("organization_id") - organizationID, err := strconv.ParseUint(rawOrganizationID, 10, 64) - if err != nil { - if hub != nil { - hub.CaptureException(err) - } - w.WriteHeader(http.StatusBadRequest) - return - } - - hub.Scope().SetTag("organization_id", rawOrganizationID) - - rawProjectID := ps.ByName("project_id") - projectID, err := strconv.ParseUint(rawProjectID, 10, 64) - if err != nil { - sentry.CaptureException(err) - w.WriteHeader(http.StatusBadRequest) - return - } - if hub != nil { - hub.Scope().SetTag("project_id", rawProjectID) - } - - var body postFlamegraphFromChunksMetadataBody - s := sentry.StartSpan(ctx, "processing") - s.Description = "Decoding data" - err = json.NewDecoder(r.Body).Decode(&body) - s.Finish() - if err != nil { - if hub != nil { - hub.CaptureException(err) - } - w.WriteHeader(http.StatusBadRequest) - return - } - - s = sentry.StartSpan(ctx, "processing") - speedscope, err := flamegraph.GetFlamegraphFromChunks(ctx, organizationID, projectID, env.storage, body.ChunksMetadata, readJobs) - s.Finish() - if err != nil { - if hub != nil { - hub.CaptureException(err) - } - w.WriteHeader(http.StatusInternalServerError) - return - } - - if hub != nil { - hub.Scope().SetTag("requested_chunks", strconv.Itoa(len(body.ChunksMetadata))) - } - - s = sentry.StartSpan(ctx, "json.marshal") - defer s.Finish() - b, err := json.Marshal(speedscope) - if err != nil { - if hub != nil { - hub.CaptureException(err) - } - w.WriteHeader(http.StatusInternalServerError) - return - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = w.Write(b) -} - type ( postFlamegraphBody struct { Transaction []utils.TransactionProfileCandidate `json:"transaction"` diff --git a/cmd/vroom/main.go b/cmd/vroom/main.go index 5127054..81748a3 100644 --- a/cmd/vroom/main.go +++ b/cmd/vroom/main.go @@ -120,11 +120,6 @@ func (e *environment) newRouter() (*httprouter.Router, error) { "/organizations/:organization_id/projects/:project_id/raw_profiles/:profile_id", e.getRawProfile, }, - { - http.MethodPost, - "/organizations/:organization_id/projects/:project_id/chunks-flamegraph", - e.postFlamegraphFromChunksMetadata, - }, { http.MethodPost, "/organizations/:organization_id/projects/:project_id/chunks", diff --git a/internal/flamegraph/flamegraph.go b/internal/flamegraph/flamegraph.go index 18628b7..f0cef92 100644 --- a/internal/flamegraph/flamegraph.go +++ b/internal/flamegraph/flamegraph.go @@ -7,7 +7,6 @@ import ( "encoding/hex" "errors" "fmt" - "strconv" "github.com/getsentry/sentry-go" "github.com/getsentry/vroom/internal/chunk" @@ -27,12 +26,6 @@ type ( } CallTrees map[uint64][]*nodetree.Node - - ChunkMetadata struct { - ProfilerID string `json:"profiler_id"` - ChunkID string `json:"chunk_id"` - SpanIntervals []utils.Interval `json:"span_intervals,omitempty"` - } ) var ( @@ -380,89 +373,6 @@ func (f *flamegraph) getProfilesIndices(profiles map[utils.ExampleMetadata]struc return indices } -func GetFlamegraphFromChunks( - ctx context.Context, - organizationID uint64, - projectID uint64, - storage *blob.Bucket, - chunksMetadata []ChunkMetadata, - jobs chan storageutil.ReadJob) (speedscope.Output, error) { - hub := sentry.GetHubFromContext(ctx) - results := make(chan storageutil.ReadJobResult, len(chunksMetadata)) - defer close(results) - - chunkIDToMetadata := make(map[string]ChunkMetadata) - for _, chunkMetadata := range chunksMetadata { - chunkIDToMetadata[chunkMetadata.ChunkID] = chunkMetadata - jobs <- chunk.ReadJob{ - Ctx: ctx, - ProfilerID: chunkMetadata.ProfilerID, - ChunkID: chunkMetadata.ChunkID, - OrganizationID: organizationID, - ProjectID: projectID, - Storage: storage, - Result: results, - } - } - - var flamegraphTree []*nodetree.Node - countChunksAggregated := 0 - // read the output of each tasks - for i := 0; i < len(chunksMetadata); i++ { - res := <-results - result, ok := res.(chunk.ReadJobResult) - if !ok { - continue - } - if result.Err != nil { - if errors.Is(result.Err, storageutil.ErrObjectNotFound) { - continue - } - if errors.Is(result.Err, context.DeadlineExceeded) { - return speedscope.Output{}, result.Err - } - if hub != nil { - hub.CaptureException(result.Err) - } - continue - } - cm := chunkIDToMetadata[result.Chunk.ID] - for _, interval := range cm.SpanIntervals { - callTrees, err := result.Chunk.CallTrees(&interval.ActiveThreadID) - if err != nil { - if hub != nil { - hub.CaptureException(err) - } - continue - } - intervals := []utils.Interval{interval} - - annotate := annotateWithProfileExample( - utils.NewExampleFromProfilerChunk( - result.Chunk.ProjectID, - result.Chunk.ProfilerID, - result.Chunk.ID, - result.TransactionID, - result.ThreadID, - result.Start, - result.End, - ), - ) - for _, callTree := range callTrees { - slicedTree := sliceCallTree(&callTree, &intervals) - addCallTreeToFlamegraph(&flamegraphTree, slicedTree, annotate) - } - } - countChunksAggregated++ - } - - sp := toSpeedscope(ctx, flamegraphTree, 1000, projectID) - if hub != nil { - hub.Scope().SetTag("processed_chunks", strconv.Itoa(countChunksAggregated)) - } - return sp, nil -} - func GetFlamegraphFromCandidates( ctx context.Context, storage *blob.Bucket, From 95efa715fbc2d035c14b123a57ef4b88e26c44ab Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Tue, 3 Dec 2024 11:32:19 -0500 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c9ecfd..82c5230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,7 @@ - Update sentry-go dependency to v0.29.1 ([#535](https://github.com/getsentry/vroom/pull/535)) - Lower number of concurrent reads ([#537](https://github.com/getsentry/vroom/pull/537)) - Remove unused metrics summary kafka writer ([#538](https://github.com/getsentry/vroom/pull/538)) +- Remove unused chunks flamegraph endpoint ([#541](https://github.com/getsentry/vroom/pull/541)) ## 23.12.0