From 009c0d503c810ce5d95e9e51e106ddd0b9d76af2 Mon Sep 17 00:00:00 2001 From: Rachel Chen Date: Thu, 23 May 2024 10:57:37 -0700 Subject: [PATCH 1/2] self.buckets --- snuba/utils/bucket_timer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/snuba/utils/bucket_timer.py b/snuba/utils/bucket_timer.py index 7ffe80e7e1..8d3f023ce6 100644 --- a/snuba/utils/bucket_timer.py +++ b/snuba/utils/bucket_timer.py @@ -88,6 +88,7 @@ def get_projects_exceeding_limit(self) -> List[int]: now = datetime.now() self.__trim_expired_buckets(now) project_groups: dict[int, timedelta] = defaultdict(lambda: timedelta(seconds=0)) + logger.debug("self.buckets_size: %s" % len(self.buckets)) for project_dict in list(self.buckets.values()): for project_id, processing_time in project_dict.items(): project_groups[project_id] += processing_time From bd13be314d2b17e172199b149dd4f7f571bb947d Mon Sep 17 00:00:00 2001 From: Rachel Chen Date: Thu, 23 May 2024 11:46:35 -0700 Subject: [PATCH 2/2] code flow logging --- snuba/utils/bucket_timer.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/snuba/utils/bucket_timer.py b/snuba/utils/bucket_timer.py index 8d3f023ce6..cb2654eecf 100644 --- a/snuba/utils/bucket_timer.py +++ b/snuba/utils/bucket_timer.py @@ -49,6 +49,7 @@ def __init__(self, consumer_group: str) -> None: self.limit = self.counter_window_size * percentage def __trim_expired_buckets(self, now: datetime) -> None: + logger.debug("Entering __trim_expired_buckets method") current_minute = floor_minute(now) window_start = current_minute - self.counter_window_size new_buckets: Buckets = {} @@ -63,6 +64,7 @@ def __add_to_bucket( start_minute: datetime, processing_time: timedelta, ) -> None: + logger.debug("Entering __add_to_bucket method") if start_minute in self.buckets: if project_id in self.buckets[start_minute]: self.buckets[start_minute][project_id] += processing_time @@ -75,6 +77,7 @@ def __add_to_bucket( def record_time_spent( self, project_id: int, start: datetime, end: datetime ) -> None: + logger.debug("Entering record_time_spent method") start_minute = floor_minute(start) left = start right = ceil_minute(start) @@ -85,27 +88,33 @@ def record_time_spent( self.__add_to_bucket(project_id, start_minute, end - left) def get_projects_exceeding_limit(self) -> List[int]: + logger.debug("Entering get_projects_exceeding_limit method") now = datetime.now() self.__trim_expired_buckets(now) project_groups: dict[int, timedelta] = defaultdict(lambda: timedelta(seconds=0)) logger.debug("self.buckets_size: %s" % len(self.buckets)) for project_dict in list(self.buckets.values()): + logger.debug("project_dict_size: %s" % len(project_dict)) for project_id, processing_time in project_dict.items(): + logger.debug( + "project_id: %s, processing_time: %s" + % (project_id, processing_time) + ) project_groups[project_id] += processing_time - logger.info("project_groups_size: %s" % len(project_groups)) + logger.debug("project_groups_size: %s" % len(project_groups)) # Compare the replacement total grouped by project_id with system time limit projects_exceeding_time_limit = [] for project_id, total_processing_time in project_groups.items(): - logger.info( + logger.debug( "project_id: %s, total_processing_time: %s, limit: %s" % (project_id, total_processing_time, self.limit) ) if total_processing_time > self.limit and len(project_groups) > 1: projects_exceeding_time_limit.append(project_id) - logger.info("projects_exceeding_time_limit: %s", projects_exceeding_time_limit) + logger.debug("projects_exceeding_time_limit: %s", projects_exceeding_time_limit) metrics.timing( "get_projects_exceeding_limit_duration", datetime.now().timestamp() - now.timestamp(),