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

feat(related_issues): Decouple endpoint #70504

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
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
23 changes: 17 additions & 6 deletions src/sentry/api/endpoints/issues/related_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.group import GroupEndpoint
from sentry.issues.related import find_related_issues
from sentry.issues.related import find_related_issues # To be deprecated
from sentry.issues.related import RELATED_ISSUES_ALGORITHMS
from sentry.models.group import Group
from sentry.types.ratelimit import RateLimit, RateLimitCategory

Expand All @@ -24,13 +25,23 @@ class RelatedIssuesEndpoint(GroupEndpoint):
}

# We get a Group object since the endpoint is /issues/{issue_id}/related-issues
def get(self, _: Request, group: Group) -> Response:
def get(self, request: Request, group: Group) -> Response:
"""
Retrieve related issues for an Issue
Retrieve related issues for a Group
````````````````````````````````````
Related issues can be based on the same root cause or trace connected.

:pparam string group_id: the ID of the issue
:pparam Request request: the request object
:pparam Group group: the group object
"""
related_issues = find_related_issues(group)
return Response({"data": [related_set for related_set in related_issues]})
# The type of related issues to retrieve. Can be either `same_root_cause` or `trace_connected`.
related_type = request.query_params.get("type")
related_issues: list[dict[str, str | list[int] | dict[str, str]]] = []

if related_type in RELATED_ISSUES_ALGORITHMS:
data, meta = RELATED_ISSUES_ALGORITHMS[related_type](group)
return Response({"type": related_type, "data": data, "meta": meta})
else:
# XXX: We will be deprecating this approach soon
related_issues = find_related_issues(group)
return Response({"data": [related_set for related_set in related_issues]})
2 changes: 1 addition & 1 deletion src/sentry/issues/related/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .same_root_cause import same_root_cause_analysis
from .trace_connected import trace_connected_analysis

__all__ = ["find_related_issues"]
__all__ = ["find_related_issues", "same_root_cause_analysis", "trace_connected_analysis"]

RELATED_ISSUES_ALGORITHMS = {
"same_root_cause": same_root_cause_analysis,
Expand Down
27 changes: 7 additions & 20 deletions tests/sentry/api/endpoints/issues/test_related_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,11 @@ def test_same_root_related_issues(self) -> None:
for datum in groups_data:
self.create_group(data=datum)

response = self.get_success_response()
response = self.get_success_response(qs_params={"type": "same_root_cause"})
# The UI will then make normal calls to get issues-stats
# For instance, this URL
# https://us.sentry.io/api/0/organizations/sentry/issues-stats/?groups=4741828952&groups=4489703641&statsPeriod=24h
assert response.json() == {
"data": [
{"type": "same_root_cause", "data": [5], "meta": {}},
{"type": "trace_connected", "data": [], "meta": {}},
],
}
assert response.json() == {"type": "same_root_cause", "data": [5], "meta": {}}

def test_trace_connected_errors(self) -> None:
armenzg marked this conversation as resolved.
Show resolved Hide resolved
error_event, _, another_proj_event = self.load_errors(self.project, uuid4().hex[:16])
Expand All @@ -62,18 +57,10 @@ def test_trace_connected_errors(self) -> None:
assert error_event.project.id != another_proj_event.project.id
assert error_event.trace_id == another_proj_event.trace_id

response = self.get_success_response()
response = self.get_success_response(qs_params={"type": "trace_connected"})
assert response.json() == {
"data": [
{"type": "same_root_cause", "data": [], "meta": {}},
{
"type": "trace_connected",
# This is the other issue in the trace that it is not itself
"data": [another_proj_event.group_id],
"meta": {
"event_id": recommended_event.event_id,
"trace_id": error_event.trace_id,
},
},
]
"type": "trace_connected",
# This is the other issue in the trace that it is not itself
"data": [another_proj_event.group_id],
"meta": {"event_id": recommended_event.event_id, "trace_id": error_event.trace_id},
}
Loading