@@ -530,122 +530,38 @@ def test_queries_profile_candidates_from_transactions_with_data(
530530 },
531531 )
532532
533- def test_queries_profile_candidates_from_profiles_with_continuous_profiles_without_transactions (
533+ def test_queries_profile_candidates_from_profiles_with_continuous_profiles (
534534 self ,
535535 ):
536- # this transaction has transaction profile
537536 profile_id = uuid4 ().hex
538- self .store_transaction (
539- transaction = "foo" ,
540- profile_id = profile_id ,
541- project = self .project ,
537+ span_with_transaction_profile = self .create_span (
538+ project = self .project , start_ts = self .ten_mins_ago , duration = 1000
542539 )
540+ span_with_transaction_profile .update ({"profile_id" : profile_id , "is_segment" : True })
541+ self .store_span (span_with_transaction_profile )
543542
544- # this transaction has continuous profile with a matching chunk (to be mocked below)
545543 profiler_id = uuid4 ().hex
546544 thread_id = "12345"
547- profiler_transaction_id = uuid4 ().hex
548- profiler_transaction = self .store_transaction (
549- transaction = "foo" ,
550- profiler_id = profiler_id ,
551- thread_id = thread_id ,
552- transaction_id = profiler_transaction_id ,
545+ span_with_continuous_profile = self .create_span (
546+ {"sentry_tags" : {"profiler_id" : profiler_id , "thread.id" : thread_id }},
553547 project = self .project ,
548+ start_ts = self .ten_mins_ago ,
549+ duration = 1000 ,
554550 )
555- start_timestamp = datetime .fromtimestamp (profiler_transaction ["start_timestamp" ])
556- finish_timestamp = datetime .fromtimestamp (profiler_transaction ["timestamp" ])
557- buffer = timedelta (seconds = 3 )
558- # not able to write profile chunks to the table yet so mock it's response here
559- # so that the profiler transaction looks like it has a profile chunk within
560- # the specified time range
561- chunk = {
562- "project_id" : self .project .id ,
563- "profiler_id" : profiler_id ,
564- "chunk_id" : uuid4 ().hex ,
565- "start_timestamp" : (start_timestamp - buffer ).isoformat (),
566- "end_timestamp" : (finish_timestamp + buffer ).isoformat (),
567- }
551+ del span_with_continuous_profile ["profile_id" ]
552+ span_with_continuous_profile ["is_segment" ] = True
553+ self .store_span (span_with_continuous_profile )
568554
569- with (
570- patch (
571- "sentry.profiles.flamegraph.FlamegraphExecutor._query_chunks_for_profilers"
572- ) as mock_query_chunks_for_profilers ,
573- patch (
574- "sentry.api.endpoints.organization_profiling_profiles.proxy_profiling_service"
575- ) as mock_proxy_profiling_service ,
576- ):
577- # Mock the chunks query for the profiler_meta
578- mock_query_chunks_for_profilers .return_value = [{"data" : [chunk ]}]
579- mock_proxy_profiling_service .return_value = HttpResponse (status = 200 )
580-
581- response = self .do_request (
582- {
583- "project" : [self .project .id ],
584- "dataSource" : "profiles" ,
585- },
586- )
587-
588- assert response .status_code == 200 , response .content
589-
590- # Verify that chunks were queried for the profiler
591- mock_query_chunks_for_profilers .assert_called_once ()
592-
593- mock_proxy_profiling_service .assert_called_once_with (
594- method = "POST" ,
595- path = f"/organizations/{ self .project .organization .id } /flamegraph" ,
596- json_data = {
597- "transaction" : [
598- {
599- "project_id" : self .project .id ,
600- "profile_id" : profile_id ,
601- },
602- ],
603- "continuous" : [
604- {
605- "project_id" : self .project .id ,
606- "profiler_id" : profiler_id ,
607- "chunk_id" : chunk ["chunk_id" ],
608- "thread_id" : thread_id ,
609- "start" : str (int (profiler_transaction ["start_timestamp" ] * 1e9 )),
610- "end" : str (int (profiler_transaction ["timestamp" ] * 1e9 )),
611- "transaction_id" : profiler_transaction_id ,
612- },
613- ],
614- },
615- )
616-
617- def test_queries_profile_candidates_from_profiles_with_continuous_profiles_with_transactions (
618- self ,
619- ):
620- # this transaction has transaction profile
621- profile_id = uuid4 ().hex
622- profile_transaction_id = uuid4 ().hex
623- self .store_transaction (
624- transaction = "foo" ,
625- profile_id = profile_id ,
626- transaction_id = profile_transaction_id ,
627- project = self .project ,
555+ start_timestamp = datetime .fromtimestamp (
556+ span_with_continuous_profile ["start_timestamp_precise" ]
628557 )
629-
630- # this transaction has continuous profile with a matching chunk (to be mocked below)
631- profiler_id = uuid4 ().hex
632- thread_id = "12345"
633- profiler_transaction_id = uuid4 ().hex
634- profiler_transaction = self .store_transaction (
635- transaction = "foo" ,
636- profiler_id = profiler_id ,
637- thread_id = thread_id ,
638- transaction_id = profiler_transaction_id ,
639- project = self .project ,
558+ finish_timestamp = datetime .fromtimestamp (
559+ span_with_continuous_profile ["end_timestamp_precise" ]
640560 )
641-
642- start_timestamp = datetime .fromtimestamp (profiler_transaction ["start_timestamp" ])
643- finish_timestamp = datetime .fromtimestamp (profiler_transaction ["timestamp" ])
644561 buffer = timedelta (seconds = 3 )
645- # not able to write profile chunks to the table yet so mock it's response here
646- # so that the profiler transaction looks like it has a profile chunk within
647- # the specified time range
648- chunk_1 = {
562+ # not able to write profile chunks to the table yet so mock its response here
563+ # so that the span looks like it has a profile chunk within the specified time range
564+ chunk = {
649565 "project_id" : self .project .id ,
650566 "profiler_id" : profiler_id ,
651567 "chunk_id" : uuid4 ().hex ,
@@ -662,13 +578,14 @@ def test_queries_profile_candidates_from_profiles_with_continuous_profiles_with_
662578 ) as mock_proxy_profiling_service ,
663579 ):
664580 # Mock the chunks query for the profiler_meta
665- mock_query_chunks_for_profilers .return_value = [{"data" : [chunk_1 ]}]
581+ mock_query_chunks_for_profilers .return_value = [{"data" : [chunk ]}]
666582 mock_proxy_profiling_service .return_value = HttpResponse (status = 200 )
667583
668584 response = self .do_request (
669585 {
670586 "project" : [self .project .id ],
671587 "dataSource" : "profiles" ,
588+ "statsPeriod" : "1h" ,
672589 },
673590 )
674591
@@ -691,11 +608,15 @@ def test_queries_profile_candidates_from_profiles_with_continuous_profiles_with_
691608 {
692609 "project_id" : self .project .id ,
693610 "profiler_id" : profiler_id ,
694- "chunk_id" : chunk_1 ["chunk_id" ],
611+ "chunk_id" : chunk ["chunk_id" ],
695612 "thread_id" : thread_id ,
696- "start" : str (int (profiler_transaction ["start_timestamp" ] * 1e9 )),
697- "end" : str (int (profiler_transaction ["timestamp" ] * 1e9 )),
698- "transaction_id" : profiler_transaction_id ,
613+ "start" : str (
614+ int (span_with_continuous_profile ["start_timestamp_precise" ] * 1e9 )
615+ ),
616+ "end" : str (
617+ int (span_with_continuous_profile ["end_timestamp_precise" ] * 1e9 )
618+ ),
619+ "transaction_id" : span_with_continuous_profile ["event_id" ],
699620 },
700621 ],
701622 },
0 commit comments