-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(related_issues): Minor code refactoring before feature work #69137
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| """This module exports a function to find related issues. It groups them by type.""" | ||
|
|
||
| from typing import Any | ||
|
|
||
| from sentry.models.group import Group | ||
|
|
||
| from .same_root_cause import same_root_cause_analysis | ||
|
|
@@ -13,8 +11,8 @@ | |
| } | ||
|
|
||
|
|
||
| def find_related_issues(group: Group) -> list[dict[str, Any]]: | ||
| related_issues = [] | ||
| def find_related_issues(group: Group) -> list[dict[str, list[int] | str]]: | ||
|
Member
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. A little tighter than |
||
| related_issues: list[dict[str, list[int] | str]] = [] | ||
| for key, func in RELATED_ISSUES_ALGORITHMS.items(): | ||
| related_issues.append({"type": key, "data": func(group)}) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,29 +3,26 @@ | |
| # The first case this module handles is environmental failures. | ||
| # | ||
| # Refer to README in module for more details. | ||
| from typing import Any | ||
|
|
||
| from sentry.models.group import Group | ||
| from sentry.utils.query import RangeQuerySetWrapper | ||
|
|
||
|
|
||
| def same_root_cause_analysis(group: Group) -> list[Group]: | ||
| def same_root_cause_analysis(group: Group) -> list[int]: | ||
|
Member
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. The endpoint is going to return the group IDs. This also makes typing a bit simpler in the module above. |
||
| """Analyze and create a group set if the group was caused by the same root cause.""" | ||
| # Querying the data field (which is a GzippedDictField) cannot be done via | ||
| # Django's ORM, thus, we do so via compare_groups | ||
| project_groups = RangeQuerySetWrapper(Group.objects.filter(project=group.project_id), limit=100) | ||
| same_error_type_groups = [g for g in project_groups if compare_groups(g, group)] | ||
| same_error_type_groups = [g.id for g in project_groups if compare_groups(g, group)] | ||
| return same_error_type_groups or [] | ||
|
|
||
|
|
||
| def compare_groups(groupA: Group, groupB: Group) -> bool: | ||
| return match_criteria(_extract_values(groupA), _extract_values(groupB)) | ||
| return match_criteria( | ||
| {"title": groupA.title, "type": groupA.get_event_type()}, | ||
| {"title": groupB.title, "type": groupB.get_event_type()}, | ||
| ) | ||
|
|
||
|
|
||
| def match_criteria(a: dict[str, str | None], b: dict[str, str | None]) -> bool: | ||
| # XXX: In future iterations we will be able to use similar titles rather than an exact match | ||
| return a["type"] == b["type"] and a["title"] == b["title"] | ||
|
|
||
|
|
||
| def _extract_values(group: Group) -> dict[str, Any]: | ||
| return {"title": group.title, "type": group.data.get("metadata", {}).get("type")} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We won't be returning this data shape. The UI only uses the new shape (#68985).