|
@@ -26,11 +26,11 @@ logger = logging.getLogger(__name__)
|
|
|
MAX_FRAME_COUNT = 50
|
|
|
|
|
|
|
|
|
-def get_value_if_exists(exception_value):
|
|
|
+def _get_value_if_exists(exception_value: dict[str, Any]) -> str:
|
|
|
return exception_value["values"][0] if exception_value.get("values") else ""
|
|
|
|
|
|
|
|
|
-def get_stacktrace_string(data):
|
|
|
+def get_stacktrace_string(data: dict[str, Any]) -> str:
|
|
|
"""Format a stacktrace string from the grouping information."""
|
|
|
if not (
|
|
|
get_path(data, "app", "hash") and get_path(data, "app", "component", "values")
|
|
@@ -59,9 +59,9 @@ def get_stacktrace_string(data):
|
|
|
exc_type, exc_value, frame_str = "", "", ""
|
|
|
for exception_value in exception.get("values", []):
|
|
|
if exception_value.get("id") == "type":
|
|
|
- exc_type = get_value_if_exists(exception_value)
|
|
|
+ exc_type = _get_value_if_exists(exception_value)
|
|
|
elif exception_value.get("id") == "value":
|
|
|
- exc_value = get_value_if_exists(exception_value)
|
|
|
+ exc_value = _get_value_if_exists(exception_value)
|
|
|
elif exception_value.get("id") == "stacktrace" and frame_count < MAX_FRAME_COUNT:
|
|
|
contributing_frames = [
|
|
|
frame
|
|
@@ -79,7 +79,7 @@ def get_stacktrace_string(data):
|
|
|
frame_dict = {"filename": "", "function": "", "context-line": ""}
|
|
|
for frame_values in frame.get("values", []):
|
|
|
if frame_values.get("id") in frame_dict:
|
|
|
- frame_dict[frame_values["id"]] = get_value_if_exists(frame_values)
|
|
|
+ frame_dict[frame_values["id"]] = _get_value_if_exists(frame_values)
|
|
|
|
|
|
frame_str += f' File "{frame_dict["filename"]}", function {frame_dict["function"]}\n {frame_dict["context-line"]}\n'
|
|
|
|
|
@@ -107,20 +107,22 @@ class GroupSimilarIssuesEmbeddingsEndpoint(GroupEndpoint):
|
|
|
}
|
|
|
|
|
|
def get_formatted_results(
|
|
|
- self, responses: Sequence[SimilarIssuesEmbeddingsData], user: User | AnonymousUser
|
|
|
+ self,
|
|
|
+ similar_issues_data: Sequence[SimilarIssuesEmbeddingsData],
|
|
|
+ user: User | AnonymousUser,
|
|
|
) -> Sequence[tuple[Mapping[str, Any], Mapping[str, Any]] | None]:
|
|
|
"""
|
|
|
Format the responses using to be used by the frontend by changing the field names and
|
|
|
changing the cosine distances into cosine similarities.
|
|
|
"""
|
|
|
group_data = {}
|
|
|
- for response in responses:
|
|
|
+ for similar_issue_data in similar_issues_data:
|
|
|
formatted_response: FormattedSimilarIssuesEmbeddingsData = {
|
|
|
- "message": 1 - response["message_distance"],
|
|
|
- "exception": 1 - response["stacktrace_distance"],
|
|
|
- "shouldBeGrouped": "Yes" if response["should_group"] else "No",
|
|
|
+ "message": 1 - similar_issue_data["message_distance"],
|
|
|
+ "exception": 1 - similar_issue_data["stacktrace_distance"],
|
|
|
+ "shouldBeGrouped": "Yes" if similar_issue_data["should_group"] else "No",
|
|
|
}
|
|
|
- group_data.update({response["parent_group_id"]: formatted_response})
|
|
|
+ group_data[similar_issue_data["parent_group_id"]] = formatted_response
|
|
|
|
|
|
serialized_groups = {
|
|
|
int(g["id"]): g
|
|
@@ -134,7 +136,14 @@ class GroupSimilarIssuesEmbeddingsEndpoint(GroupEndpoint):
|
|
|
try:
|
|
|
result.append((serialized_groups[group_id], group_data[group_id]))
|
|
|
except KeyError:
|
|
|
- # KeyErrors may occur if seer API returns a deleted/merged group
|
|
|
+ # KeyErrors may occur if seer API returns a deleted/merged group, which means it
|
|
|
+ # will be missing from `serialized_groups`
|
|
|
+ #
|
|
|
+ # TODO: This shouldn't be an issue for merged groups once we only use hashes (since
|
|
|
+ # merging leaves the hashes intact), but it will still be an error for deleted
|
|
|
+ # groups/hashes.
|
|
|
+ #
|
|
|
+ # TODO: Report back to seer that the hash has been deleted.
|
|
|
continue
|
|
|
return result
|
|
|
|
|
@@ -159,9 +168,9 @@ class GroupSimilarIssuesEmbeddingsEndpoint(GroupEndpoint):
|
|
|
}
|
|
|
# Add optional parameters
|
|
|
if request.GET.get("k"):
|
|
|
- similar_issues_params.update({"k": int(request.GET["k"])})
|
|
|
+ similar_issues_params["k"] = int(request.GET["k"])
|
|
|
if request.GET.get("threshold"):
|
|
|
- similar_issues_params.update({"threshold": float(request.GET["threshold"])})
|
|
|
+ similar_issues_params["threshold"] = float(request.GET["threshold"])
|
|
|
|
|
|
extra: dict[str, Any] = dict(similar_issues_params.copy())
|
|
|
extra["group_message"] = extra.pop("message")
|
|
@@ -178,7 +187,7 @@ class GroupSimilarIssuesEmbeddingsEndpoint(GroupEndpoint):
|
|
|
[
|
|
|
result["stacktrace_distance"]
|
|
|
for result in (results.get("responses") or [])
|
|
|
- if result and result["stacktrace_distance"] <= 0.01
|
|
|
+ if result["stacktrace_distance"] <= 0.01
|
|
|
]
|
|
|
),
|
|
|
user_id=request.user.id,
|