@@ -247,21 +247,21 @@ def get_profile_candidates_from_transactions_v2(self) -> ProfileCandidates:
247
247
profiler_metas : list [ProfilerMeta ] = []
248
248
249
249
assert self .snuba_params .start is not None and self .snuba_params .end is not None
250
- original_start , original_end = self .snuba_params .start , self . snuba_params . end
250
+ snuba_params = self .snuba_params .copy ()
251
251
252
252
for chunk_start , chunk_end in split_datetime_range_exponential (
253
- original_start ,
254
- original_end ,
253
+ self . snuba_params . start ,
254
+ self . snuba_params . end ,
255
255
initial_chunk_delta ,
256
256
max_chunk_delta ,
257
257
multiplier ,
258
258
reverse = True ,
259
259
):
260
- self . snuba_params .start = chunk_start
261
- self . snuba_params .end = chunk_end
260
+ snuba_params .start = chunk_start
261
+ snuba_params .end = chunk_end
262
262
263
263
builder = self .get_transactions_based_candidate_query (
264
- query = self .query , limit = max_profiles
264
+ query = self .query , limit = max_profiles , snuba_params = snuba_params
265
265
)
266
266
267
267
results = builder .run_query (
@@ -298,9 +298,9 @@ def get_profile_candidates_from_transactions_v2(self) -> ProfileCandidates:
298
298
continuous_profile_candidates : list [ContinuousProfileCandidate ] = []
299
299
300
300
if max_continuous_profile_candidates > 0 :
301
+ snuba_params .end = self .snuba_params .end
301
302
continuous_profile_candidates , _ = self .get_chunks_for_profilers (
302
- profiler_metas ,
303
- max_continuous_profile_candidates ,
303
+ profiler_metas , max_continuous_profile_candidates , snuba_params
304
304
)
305
305
306
306
return {
@@ -309,12 +309,15 @@ def get_profile_candidates_from_transactions_v2(self) -> ProfileCandidates:
309
309
}
310
310
311
311
def get_transactions_based_candidate_query (
312
- self , query : str | None , limit : int
312
+ self ,
313
+ query : str | None ,
314
+ limit : int ,
315
+ snuba_params : SnubaParams | None = None ,
313
316
) -> DiscoverQueryBuilder :
314
317
builder = DiscoverQueryBuilder (
315
318
dataset = Dataset .Discover ,
316
319
params = {},
317
- snuba_params = self .snuba_params ,
320
+ snuba_params = snuba_params or self .snuba_params ,
318
321
selected_columns = [
319
322
"id" ,
320
323
"project.id" ,
@@ -356,7 +359,10 @@ def get_transactions_based_candidate_query(
356
359
return builder
357
360
358
361
def get_chunks_for_profilers (
359
- self , profiler_metas : list [ProfilerMeta ], limit : int
362
+ self ,
363
+ profiler_metas : list [ProfilerMeta ],
364
+ limit : int ,
365
+ snuba_params : SnubaParams | None = None ,
360
366
) -> tuple [list [ContinuousProfileCandidate ], float ]:
361
367
total_duration = 0.0
362
368
@@ -365,7 +371,8 @@ def get_chunks_for_profilers(
365
371
366
372
chunk_size = options .get ("profiling.continuous-profiling.chunks-query.size" )
367
373
queries = [
368
- self ._create_chunks_query (chunk ) for chunk in chunked (profiler_metas , chunk_size )
374
+ self ._create_chunks_query (chunk , snuba_params )
375
+ for chunk in chunked (profiler_metas , chunk_size )
369
376
]
370
377
371
378
results = self ._query_chunks_for_profilers (queries )
@@ -416,8 +423,11 @@ def get_chunks_for_profilers(
416
423
417
424
return continuous_profile_candidates , total_duration
418
425
419
- def _create_chunks_query (self , profiler_metas : list [ProfilerMeta ]) -> Query :
426
+ def _create_chunks_query (
427
+ self , profiler_metas : list [ProfilerMeta ], snuba_params : SnubaParams | None = None
428
+ ) -> Query :
420
429
assert profiler_metas , "profiler_metas cannot be empty"
430
+ snuba_params = snuba_params or self .snuba_params
421
431
422
432
profiler_conditions = [profiler_meta .as_condition () for profiler_meta in profiler_metas ]
423
433
@@ -434,10 +444,10 @@ def _create_chunks_query(self, profiler_metas: list[ProfilerMeta]) -> Query:
434
444
start_condition = Condition (
435
445
Column ("start_timestamp" ),
436
446
Op .LT ,
437
- resolve_datetime64 (self . snuba_params .end ),
447
+ resolve_datetime64 (snuba_params .end ),
438
448
)
439
449
end_condition = Condition (
440
- Column ("end_timestamp" ), Op .GTE , resolve_datetime64 (self . snuba_params .start )
450
+ Column ("end_timestamp" ), Op .GTE , resolve_datetime64 (snuba_params .start )
441
451
)
442
452
443
453
return Query (
@@ -652,21 +662,21 @@ def get_profile_candidates_from_profiles_v2(self) -> ProfileCandidates:
652
662
profiler_metas : list [ProfilerMeta ] = []
653
663
654
664
assert self .snuba_params .start is not None and self .snuba_params .end is not None
655
- original_start , original_end = self .snuba_params .start , self . snuba_params . end
665
+ snuba_params = self .snuba_params .copy ()
656
666
657
667
for chunk_start , chunk_end in split_datetime_range_exponential (
658
- original_start ,
659
- original_end ,
668
+ self . snuba_params . start ,
669
+ self . snuba_params . end ,
660
670
initial_chunk_delta ,
661
671
max_chunk_delta ,
662
672
multiplier ,
663
673
reverse = True ,
664
674
):
665
- self . snuba_params .start = chunk_start
666
- self . snuba_params .end = chunk_end
675
+ snuba_params .start = chunk_start
676
+ snuba_params .end = chunk_end
667
677
668
678
builder = self .get_transactions_based_candidate_query (
669
- query = self .query , limit = max_profiles
679
+ query = self .query , limit = max_profiles , snuba_params = snuba_params
670
680
)
671
681
results = builder .run_query (referrer )
672
682
results = builder .process_results (results )
@@ -704,8 +714,9 @@ def get_profile_candidates_from_profiles_v2(self) -> ProfileCandidates:
704
714
# If there are continuous profiles attached to transactions, we prefer those as
705
715
# the active thread id gives us more user friendly flamegraphs than without.
706
716
if profiler_metas and max_continuous_profile_candidates > 0 :
717
+ snuba_params .end = self .snuba_params .end
707
718
continuous_profile_candidates , continuous_duration = self .get_chunks_for_profilers (
708
- profiler_metas , max_continuous_profile_candidates
719
+ profiler_metas , max_continuous_profile_candidates , snuba_params
709
720
)
710
721
711
722
seen_chunks = {
@@ -720,10 +731,14 @@ def get_profile_candidates_from_profiles_v2(self) -> ProfileCandidates:
720
731
conditions = []
721
732
conditions .append (Condition (Column ("project_id" ), Op .IN , self .snuba_params .project_ids ))
722
733
conditions .append (
723
- Condition (Column ("start_timestamp" ), Op .LT , resolve_datetime64 (original_end ))
734
+ Condition (
735
+ Column ("start_timestamp" ), Op .LT , resolve_datetime64 (self .snuba_params .end )
736
+ )
724
737
)
725
738
conditions .append (
726
- Condition (Column ("end_timestamp" ), Op .GTE , resolve_datetime64 (original_start ))
739
+ Condition (
740
+ Column ("end_timestamp" ), Op .GTE , resolve_datetime64 (self .snuba_params .start )
741
+ )
727
742
)
728
743
environments = self .snuba_params .environment_names
729
744
if environments :
0 commit comments