Skip to content

Commit

Permalink
code flow logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Chen authored and Rachel Chen committed May 23, 2024
1 parent 009c0d5 commit 4436c6f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion snuba/utils/bucket_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.info("Entering __trim_expired_buckets method")
current_minute = floor_minute(now)
window_start = current_minute - self.counter_window_size
new_buckets: Buckets = {}
Expand All @@ -63,6 +64,7 @@ def __add_to_bucket(
start_minute: datetime,
processing_time: timedelta,
) -> None:
logger.info("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
Expand All @@ -75,6 +77,7 @@ def __add_to_bucket(
def record_time_spent(
self, project_id: int, start: datetime, end: datetime
) -> None:
logger.info("Entering record_time_spent method")
start_minute = floor_minute(start)
left = start
right = ceil_minute(start)
Expand All @@ -85,12 +88,18 @@ def record_time_spent(
self.__add_to_bucket(project_id, start_minute, end - left)

def get_projects_exceeding_limit(self) -> List[int]:
logger.info("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))
logger.info("self.buckets_size: %s" % len(self.buckets))
for project_dict in list(self.buckets.values()):
logger.info("project_dict_size: %s" % len(project_dict))
for project_id, processing_time in project_dict.items():
logger.info(
"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))
Expand Down

0 comments on commit 4436c6f

Please sign in to comment.