Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(profiling): Remove unused chunks flamegraph endpoint #541

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
75 changes: 0 additions & 75 deletions cmd/vroom/flamegraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 0 additions & 5 deletions cmd/vroom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
90 changes: 0 additions & 90 deletions internal/flamegraph/flamegraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"strconv"

"github.com/getsentry/sentry-go"
"github.com/getsentry/vroom/internal/chunk"
Expand All @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down
Loading