Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging bucket timer #5963

Merged
merged 2 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions 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.debug("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.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
Expand All @@ -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)
Expand All @@ -85,26 +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))
xurui-c marked this conversation as resolved.
Show resolved Hide resolved
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(),
Expand Down
Loading