Skip to content

Commit

Permalink
s/group_hash/hash and s/parent_group_hash/parent_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed May 6, 2024
1 parent 26ea0eb commit 813dfb7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/sentry/api/endpoints/group_similar_issues_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def get(self, request: Request, group) -> Response:

similar_issues_params: SimilarIssuesEmbeddingsRequest = {
"group_id": group.id,
"group_hash": latest_event.get_primary_hash(),
"hash": latest_event.get_primary_hash(),
"project_id": group.project.id,
"stacktrace": stacktrace_string,
"message": group.message,
Expand All @@ -184,7 +184,7 @@ def get(self, request: Request, group) -> Response:
organization_id=group.organization.id,
project_id=group.project.id,
group_id=group.id,
group_hash=latest_event.get_primary_hash(),
hash=latest_event.get_primary_hash(),
count_over_threshold=len(
[
result.stacktrace_distance
Expand Down
14 changes: 7 additions & 7 deletions src/sentry/seer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ class SimilarIssuesEmbeddingsRequest(TypedDict):
k: NotRequired[int] # how many neighbors to find
threshold: NotRequired[float]
group_id: NotRequired[int] # TODO: Remove this once we stop sending it to seer
group_hash: NotRequired[str] # TODO: Make this required once id -> hash change is done
hash: NotRequired[str] # TODO: Make this required once id -> hash change is done


class RawSeerSimilarIssueData(TypedDict):
stacktrace_distance: float
message_distance: float
should_group: bool
parent_group_id: NotRequired[int] # TODO: Remove this once seer stops sending it
parent_group_hash: NotRequired[str] # TODO: Make this required once id -> hash change is done
parent_hash: NotRequired[str] # TODO: Make this required once id -> hash change is done


class SimilarIssuesEmbeddingsResponse(TypedDict):
Expand All @@ -125,7 +125,7 @@ class SeerSimilarIssueData:
should_group: bool
parent_group_id: int
# TODO: See if we end up needing the hash here
parent_group_hash: str | None = None
parent_hash: str | None = None

@classmethod
def from_raw(cls, project_id: int, raw_similar_issue_data: RawSeerSimilarIssueData) -> Self:
Expand All @@ -141,12 +141,12 @@ def from_raw(cls, project_id: int, raw_similar_issue_data: RawSeerSimilarIssueDa
"""
similar_issue_data = raw_similar_issue_data
parent_group_hash = raw_similar_issue_data.get("parent_group_hash")
parent_hash = raw_similar_issue_data.get("parent_hash")
parent_group_id = raw_similar_issue_data.get("parent_group_id")

if not parent_group_id and not parent_group_hash:
if not parent_group_id and not parent_hash:
raise IncompleteSeerDataError(
"Seer similar issues response missing both `parent_group_id` and `parent_group_hash`"
"Seer similar issues response missing both `parent_group_id` and `parent_hash`"
)

if parent_group_id:
Expand All @@ -155,7 +155,7 @@ def from_raw(cls, project_id: int, raw_similar_issue_data: RawSeerSimilarIssueDa

else:
parent_grouphash = (
GroupHash.objects.filter(project_id=project_id, hash=parent_group_hash)
GroupHash.objects.filter(project_id=project_id, hash=parent_hash)
.exclude(state=GroupHash.State.LOCKED_IN_MIGRATION)
.first()
)
Expand Down
48 changes: 24 additions & 24 deletions tests/sentry/api/endpoints/test_group_similar_issues_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,14 +662,14 @@ def test_get_formatted_results(self):
similar_issue_data_1 = SeerSimilarIssueData(
message_distance=0.05,
parent_group_id=NonNone(self.similar_event.group_id),
parent_group_hash=NonNone(self.similar_event.get_primary_hash()),
parent_hash=NonNone(self.similar_event.get_primary_hash()),
should_group=True,
stacktrace_distance=0.01,
)
similar_issue_data_2 = SeerSimilarIssueData(
message_distance=0.49,
parent_group_id=NonNone(event_from_second_similar_group.group_id),
parent_group_hash=NonNone(event_from_second_similar_group.get_primary_hash()),
parent_hash=NonNone(event_from_second_similar_group.get_primary_hash()),
should_group=False,
stacktrace_distance=0.23,
)
Expand Down Expand Up @@ -720,7 +720,7 @@ def test_simple_only_group_id_returned(self, mock_logger, mock_seer_request):

expected_seer_request_params = {
"group_id": self.group.id,
"group_hash": NonNone(self.event.get_primary_hash()),
"hash": NonNone(self.event.get_primary_hash()),
"project_id": self.project.id,
"stacktrace": EXPECTED_STACKTRACE_STRING,
"message": self.group.message,
Expand Down Expand Up @@ -748,7 +748,7 @@ def test_simple_only_hash_returned(self, mock_logger, mock_seer_request):
"responses": [
{
"message_distance": 0.05,
"parent_group_hash": NonNone(self.similar_event.get_primary_hash()),
"parent_hash": NonNone(self.similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
}
Expand All @@ -767,7 +767,7 @@ def test_simple_only_hash_returned(self, mock_logger, mock_seer_request):

expected_seer_request_params = {
"group_id": self.group.id,
"group_hash": NonNone(self.event.get_primary_hash()),
"hash": NonNone(self.event.get_primary_hash()),
"project_id": self.project.id,
"stacktrace": EXPECTED_STACKTRACE_STRING,
"message": self.group.message,
Expand Down Expand Up @@ -797,7 +797,7 @@ def test_simple_group_id_and_hash_returned(self, mock_logger, mock_seer_request)
{
"message_distance": 0.05,
"parent_group_id": NonNone(self.similar_event.group_id),
"parent_group_hash": NonNone(self.similar_event.get_primary_hash()),
"parent_hash": NonNone(self.similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
}
Expand All @@ -816,7 +816,7 @@ def test_simple_group_id_and_hash_returned(self, mock_logger, mock_seer_request)

expected_seer_request_params = {
"group_id": self.group.id,
"group_hash": NonNone(self.event.get_primary_hash()),
"hash": NonNone(self.event.get_primary_hash()),
"project_id": self.project.id,
"stacktrace": EXPECTED_STACKTRACE_STRING,
"message": self.group.message,
Expand Down Expand Up @@ -848,21 +848,21 @@ def test_multiple(self, mock_seer_request, mock_record):
{
"message_distance": 0.05,
"parent_group_id": NonNone(self.similar_event.group_id),
"parent_group_hash": NonNone(self.similar_event.get_primary_hash()),
"parent_hash": NonNone(self.similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.002, # Over threshold
},
{
"message_distance": 0.05,
"parent_group_id": NonNone(over_threshold_group_event.group_id),
"parent_group_hash": NonNone(over_threshold_group_event.get_primary_hash()),
"parent_hash": NonNone(over_threshold_group_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.002, # Over threshold
},
{
"message_distance": 0.05,
"parent_group_id": NonNone(under_threshold_group_event.group_id),
"parent_group_hash": NonNone(under_threshold_group_event.get_primary_hash()),
"parent_hash": NonNone(under_threshold_group_event.get_primary_hash()),
"should_group": False,
"stacktrace_distance": 0.05, # Under threshold
},
Expand Down Expand Up @@ -891,7 +891,7 @@ def test_multiple(self, mock_seer_request, mock_record):
organization_id=self.org.id,
project_id=self.project.id,
group_id=self.group.id,
group_hash=NonNone(self.event.get_primary_hash()),
hash=NonNone(self.event.get_primary_hash()),
count_over_threshold=2,
user_id=self.user.id,
)
Expand All @@ -900,14 +900,14 @@ def test_multiple(self, mock_seer_request, mock_record):
@mock.patch("sentry.seer.utils.logger")
@mock.patch("sentry.seer.utils.seer_staging_connection_pool.urlopen")
def test_incomplete_return_data(self, mock_seer_request, mock_logger):
# Two suggested groups, one with valid data, one missing both parent group id and parent group hash.
# Two suggested groups, one with valid data, one missing both parent group id and parent hash.
# We should log the second and return the first.
seer_return_value: SimilarIssuesEmbeddingsResponse = {
"responses": [
{
"message_distance": 0.05,
"parent_group_id": NonNone(self.similar_event.group_id),
"parent_group_hash": NonNone(self.similar_event.get_primary_hash()),
"parent_hash": NonNone(self.similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
},
Expand All @@ -923,11 +923,11 @@ def test_incomplete_return_data(self, mock_seer_request, mock_logger):
response = self.client.get(self.path)

mock_logger.exception.assert_called_with(
"Seer similar issues response missing both `parent_group_id` and `parent_group_hash`",
"Seer similar issues response missing both `parent_group_id` and `parent_hash`",
extra={
"request_params": {
"group_id": NonNone(self.event.group_id),
"group_hash": NonNone(self.event.get_primary_hash()),
"hash": NonNone(self.event.get_primary_hash()),
"project_id": self.project.id,
"stacktrace": EXPECTED_STACKTRACE_STRING,
"message": self.group.message,
Expand Down Expand Up @@ -958,14 +958,14 @@ def test_nonexistent_group(self, mock_seer_request, mock_logger):
{
"message_distance": 0.05,
"parent_group_id": NonNone(self.similar_event.group_id),
"parent_group_hash": NonNone(self.similar_event.get_primary_hash()),
"parent_hash": NonNone(self.similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
},
{
"message_distance": 0.05,
"parent_group_id": 1121201212312012, # too high to be real
"parent_group_hash": "not a real hash",
"parent_hash": "not a real hash",
"should_group": True,
"stacktrace_distance": 0.01,
},
Expand All @@ -979,15 +979,15 @@ def test_nonexistent_group(self, mock_seer_request, mock_logger):
extra={
"request_params": {
"group_id": NonNone(self.event.group_id),
"group_hash": NonNone(self.event.get_primary_hash()),
"hash": NonNone(self.event.get_primary_hash()),
"project_id": self.project.id,
"stacktrace": EXPECTED_STACKTRACE_STRING,
"message": self.group.message,
},
"raw_similar_issue_data": {
"message_distance": 0.05,
"parent_group_id": 1121201212312012,
"parent_group_hash": "not a real hash",
"parent_hash": "not a real hash",
"should_group": True,
"stacktrace_distance": 0.01,
},
Expand All @@ -1010,7 +1010,7 @@ def test_empty_seer_return(self, mock_seer_request, mock_record):
organization_id=self.org.id,
project_id=self.project.id,
group_id=self.group.id,
group_hash=NonNone(self.event.get_primary_hash()),
hash=NonNone(self.event.get_primary_hash()),
count_over_threshold=0,
user_id=self.user.id,
)
Expand Down Expand Up @@ -1079,7 +1079,7 @@ def test_no_optional_params(self, mock_seer_request):
{
"message_distance": 0.05,
"parent_group_id": NonNone(self.similar_event.group_id),
"parent_group_hash": NonNone(self.similar_event.get_primary_hash()),
"parent_hash": NonNone(self.similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
}
Expand All @@ -1100,7 +1100,7 @@ def test_no_optional_params(self, mock_seer_request):
body=json.dumps(
{
"group_id": self.group.id,
"group_hash": NonNone(self.event.get_primary_hash()),
"hash": NonNone(self.event.get_primary_hash()),
"project_id": self.project.id,
"stacktrace": EXPECTED_STACKTRACE_STRING,
"message": self.group.message,
Expand All @@ -1124,7 +1124,7 @@ def test_no_optional_params(self, mock_seer_request):
body=json.dumps(
{
"group_id": self.group.id,
"group_hash": NonNone(self.event.get_primary_hash()),
"hash": NonNone(self.event.get_primary_hash()),
"project_id": self.project.id,
"stacktrace": EXPECTED_STACKTRACE_STRING,
"message": self.group.message,
Expand All @@ -1149,7 +1149,7 @@ def test_no_optional_params(self, mock_seer_request):
body=json.dumps(
{
"group_id": self.group.id,
"group_hash": NonNone(self.event.get_primary_hash()),
"hash": NonNone(self.event.get_primary_hash()),
"project_id": self.project.id,
"stacktrace": EXPECTED_STACKTRACE_STRING,
"message": self.group.message,
Expand Down
20 changes: 10 additions & 10 deletions tests/sentry/seer/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_simple_similar_issues_embeddings_only_group_id_returned(

params: SimilarIssuesEmbeddingsRequest = {
"group_id": NonNone(event.group_id),
"group_hash": NonNone(event.get_primary_hash()),
"hash": NonNone(event.get_primary_hash()),
"project_id": default_project.id,
"stacktrace": "string",
"message": "message",
Expand All @@ -97,7 +97,7 @@ def test_simple_similar_issues_embeddings_only_hash_returned(mock_seer_request,

raw_similar_issue_data: RawSeerSimilarIssueData = {
"message_distance": 0.05,
"parent_group_hash": NonNone(similar_event.get_primary_hash()),
"parent_hash": NonNone(similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
}
Expand All @@ -107,7 +107,7 @@ def test_simple_similar_issues_embeddings_only_hash_returned(mock_seer_request,

params: SimilarIssuesEmbeddingsRequest = {
"group_id": NonNone(event.group_id),
"group_hash": NonNone(event.get_primary_hash()),
"hash": NonNone(event.get_primary_hash()),
"project_id": default_project.id,
"stacktrace": "string",
"message": "message",
Expand All @@ -134,7 +134,7 @@ def test_simple_similar_issues_embeddings_both_returned(mock_seer_request, defau
raw_similar_issue_data: RawSeerSimilarIssueData = {
"message_distance": 0.05,
"parent_group_id": NonNone(similar_event.group_id),
"parent_group_hash": NonNone(similar_event.get_primary_hash()),
"parent_hash": NonNone(similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
}
Expand All @@ -144,7 +144,7 @@ def test_simple_similar_issues_embeddings_both_returned(mock_seer_request, defau

params: SimilarIssuesEmbeddingsRequest = {
"group_id": NonNone(event.group_id),
"group_hash": NonNone(event.get_primary_hash()),
"hash": NonNone(event.get_primary_hash()),
"project_id": default_project.id,
"stacktrace": "string",
"message": "message",
Expand All @@ -163,7 +163,7 @@ def test_empty_similar_issues_embeddings(mock_seer_request, default_project):

params: SimilarIssuesEmbeddingsRequest = {
"group_id": NonNone(event.group_id),
"group_hash": NonNone(event.get_primary_hash()),
"hash": NonNone(event.get_primary_hash()),
"project_id": default_project.id,
"stacktrace": "string",
"message": "message",
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_from_raw_only_parent_hash(default_project):
similar_event = save_new_event({"message": "Dogs are great!"}, default_project)
raw_similar_issue_data: RawSeerSimilarIssueData = {
"message_distance": 0.05,
"parent_group_hash": NonNone(similar_event.get_primary_hash()),
"parent_hash": NonNone(similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
}
Expand All @@ -216,7 +216,7 @@ def test_from_raw_parent_group_id_and_parent_hash(default_project):
raw_similar_issue_data: RawSeerSimilarIssueData = {
"message_distance": 0.05,
"parent_group_id": NonNone(similar_event.group_id),
"parent_group_hash": NonNone(similar_event.get_primary_hash()),
"parent_hash": NonNone(similar_event.get_primary_hash()),
"should_group": True,
"stacktrace_distance": 0.01,
}
Expand All @@ -230,7 +230,7 @@ def test_from_raw_parent_group_id_and_parent_hash(default_project):
def test_from_raw_missing_data(default_project):
with pytest.raises(IncompleteSeerDataError):
raw_similar_issue_data: RawSeerSimilarIssueData = {
# missing both `parent_group_id` and `parent_group_hash`
# missing both `parent_group_id` and `parent_hash`
"message_distance": 0.05,
"should_group": True,
"stacktrace_distance": 0.01,
Expand All @@ -244,7 +244,7 @@ def test_from_raw_nonexistent_group(default_project):
with pytest.raises(SimilarGroupNotFoundError):
raw_similar_issue_data: RawSeerSimilarIssueData = {
"parent_group_id": 1121201212312012, # too high to be real
"parent_group_hash": "not a real hash",
"parent_hash": "not a real hash",
"message_distance": 0.05,
"should_group": True,
"stacktrace_distance": 0.01,
Expand Down

0 comments on commit 813dfb7

Please sign in to comment.