11from abc import ABC , abstractmethod
22from typing import Any , Dict
33
4- from django .http import StreamingHttpResponse
4+ from django .http import HttpResponse
55from rest_framework .exceptions import ParseError
66from rest_framework .request import Request
77from rest_framework .response import Response
1010from sentry .api .base import region_silo_endpoint
1111from sentry .api .bases .project import ProjectEndpoint
1212from sentry .api .paginator import GenericOffsetPaginator
13+ from sentry .api .serializers import serialize
1314from sentry .exceptions import InvalidSearchQuery
14- from sentry .models import Project
15+ from sentry .models .project import Project
16+ from sentry .models .release import Release
1517from sentry .profiles .utils import (
1618 get_from_profiling_service ,
1719 parse_profile_filters ,
@@ -64,7 +66,7 @@ def get(self, request: Request, project: Project) -> Response:
6466
6567@region_silo_endpoint
6668class ProjectProfilingTransactionIDProfileIDEndpoint (ProjectProfilingBaseEndpoint ):
67- def get (self , request : Request , project : Project , transaction_id : str ) -> StreamingHttpResponse :
69+ def get (self , request : Request , project : Project , transaction_id : str ) -> HttpResponse :
6870 if not features .has ("organizations:profiling" , project .organization , actor = request .user ):
6971 return Response (status = 404 )
7072 kwargs : Dict [str , Any ] = {
@@ -76,19 +78,50 @@ def get(self, request: Request, project: Project, transaction_id: str) -> Stream
7678
7779@region_silo_endpoint
7880class ProjectProfilingProfileEndpoint (ProjectProfilingBaseEndpoint ):
79- def get (self , request : Request , project : Project , profile_id : str ) -> StreamingHttpResponse :
81+ def get (self , request : Request , project : Project , profile_id : str ) -> HttpResponse :
8082 if not features .has ("organizations:profiling" , project .organization , actor = request .user ):
8183 return Response (status = 404 )
82- kwargs : Dict [str , Any ] = {
83- "method" : "GET" ,
84- "path" : f"/organizations/{ project .organization .id } /projects/{ project .id } /profiles/{ profile_id } " ,
85- }
86- return proxy_profiling_service (** kwargs )
84+
85+ response = get_from_profiling_service (
86+ "GET" ,
87+ f"/organizations/{ project .organization .id } /projects/{ project .id } /profiles/{ profile_id } " ,
88+ )
89+
90+ if response .status == 200 :
91+ profile = json .loads (response .data )
92+
93+ # make sure to remove the version from the metadata
94+ # we're going to replace it with the release here
95+ version = profile .get ("metadata" , {}).pop ("version" )
96+ profile ["metadata" ]["release" ] = get_release (project , version )
97+
98+ return Response (profile )
99+
100+ return HttpResponse (
101+ content = response .data ,
102+ status = response .status ,
103+ content_type = response .headers .get ("Content-Type" , "application/json" ),
104+ )
105+
106+
107+ def get_release (project : Project , version : str ) -> Any :
108+ if not version :
109+ return None
110+
111+ try :
112+ release = Release .objects .get (
113+ projects = project ,
114+ organization_id = project .organization_id ,
115+ version = version ,
116+ )
117+ return serialize (release )
118+ except Release .DoesNotExist :
119+ return {"version" : version }
87120
88121
89122@region_silo_endpoint
90123class ProjectProfilingRawProfileEndpoint (ProjectProfilingBaseEndpoint ):
91- def get (self , request : Request , project : Project , profile_id : str ) -> StreamingHttpResponse :
124+ def get (self , request : Request , project : Project , profile_id : str ) -> HttpResponse :
92125 if not features .has ("organizations:profiling" , project .organization , actor = request .user ):
93126 return Response (status = 404 )
94127 kwargs : Dict [str , Any ] = {
0 commit comments