-
Notifications
You must be signed in to change notification settings - Fork 14
perf(worker): Optimize flake expiration updates in test analytics #871
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,17 +42,21 @@ def get_testruns(upload: ReportSession) -> QuerySet[Testrun]: | |
| ).order_by("timestamp") | ||
|
|
||
|
|
||
| def handle_pass(curr_flakes: dict[bytes, Flake], test_id: bytes): | ||
| def handle_pass( | ||
| curr_flakes: dict[bytes, Flake], test_id: bytes | ||
| ) -> Flake | None: | ||
| # possible that we expire it and stop caring about it | ||
| if test_id not in curr_flakes: | ||
| return | ||
| return None | ||
|
|
||
| curr_flakes[test_id].recent_passes_count += 1 | ||
| curr_flakes[test_id].count += 1 | ||
| if curr_flakes[test_id].recent_passes_count == 30: | ||
| curr_flakes[test_id].end_date = timezone.now() | ||
| curr_flakes[test_id].save() | ||
| del curr_flakes[test_id] | ||
| expired_flake = curr_flakes.pop(test_id) | ||
| return expired_flake | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| def handle_failure( | ||
|
|
@@ -82,8 +86,9 @@ def handle_failure( | |
| @sentry_sdk.trace | ||
| def process_single_upload( | ||
| upload: ReportSession, curr_flakes: dict[bytes, Flake], repo_id: int | ||
| ): | ||
| ) -> list[Flake]: | ||
| testruns = get_testruns(upload) | ||
| expired_flakes: list[Flake] = [] | ||
|
|
||
| for testrun in testruns: | ||
| test_id = bytes(testrun.test_id) | ||
|
|
@@ -92,13 +97,16 @@ def process_single_upload( | |
| if test_id not in curr_flakes: | ||
| continue | ||
|
|
||
| handle_pass(curr_flakes, test_id) | ||
| expired_flake = handle_pass(curr_flakes, test_id) | ||
| if expired_flake is not None: | ||
| expired_flakes.append(expired_flake) | ||
| case "failure" | "flaky_fail" | "error": | ||
| handle_failure(curr_flakes, test_id, testrun, repo_id) | ||
| case _: | ||
| continue | ||
|
|
||
| Testrun.objects.bulk_update(testruns, ["outcome"]) | ||
| return expired_flakes | ||
|
|
||
|
|
||
| @sentry_sdk.trace | ||
|
|
@@ -120,8 +128,11 @@ def process_flakes_for_commit(repo_id: int, commit_id: str): | |
| extra={"flakes": [flake.test_id.hex() for flake in curr_flakes.values()]}, | ||
| ) | ||
|
|
||
| all_expired_flakes: list[Flake] = [] | ||
|
|
||
| for upload in uploads: | ||
| process_single_upload(upload, curr_flakes, repo_id) | ||
| expired_flakes = process_single_upload(upload, curr_flakes, repo_id) | ||
| all_expired_flakes.extend(expired_flakes) | ||
| log.info( | ||
| "process_flakes_for_commit: processed upload", | ||
| extra={"upload": upload.id}, | ||
|
|
@@ -139,6 +150,12 @@ def process_flakes_for_commit(repo_id: int, commit_id: str): | |
| update_fields=["end_date", "count", "recent_passes_count", "fail_count"], | ||
| ) | ||
|
|
||
| if all_expired_flakes: | ||
| Flake.objects.bulk_update( | ||
| all_expired_flakes, | ||
| ["end_date", "count", "recent_passes_count"], | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newly created flake expiring crashes bulk_updateMedium Severity If a new Additional Locations (1)Reviewed by Cursor Bugbot for commit 13cdd51. Configure here.
Comment on lines
+154
to
+157
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixAdd the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
|
|
||
| @sentry_sdk.trace | ||
| def process_flakes_for_repo(repo_id: int): | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expired flakes bulk_update missing
fail_countfieldHigh Severity
The
bulk_updatefor expired flakes uses fields["end_date", "count", "recent_passes_count"]but omitsfail_count, which thebulk_createfor non-expired flakes correctly includes. Ifhandle_failureincrementsfail_counton a flake that later expires viahandle_pass(e.g., across multiple uploads in the same commit), thatfail_countchange is silently lost. The originalflake.save()persisted all fields.Additional Locations (1)
apps/worker/services/test_analytics/ta_process_flakes.py#L145-L151Reviewed by Cursor Bugbot for commit 13cdd51. Configure here.