-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
chore(similarity): Add try catch around insert grouping record #1184
Changes from 2 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from pydantic import BaseModel, ValidationInfo, field_validator | ||
from sentence_transformers import SentenceTransformer | ||
from sqlalchemy.dialects.postgresql import insert | ||
from sqlalchemy.exc import IntegrityError | ||
from torch.cuda import OutOfMemoryError | ||
|
||
from seer.db import DbGroupingRecord, Session | ||
|
@@ -362,8 +363,7 @@ def get_nearest_neighbors(self, issue: GroupingRequest) -> SimilarityResponse: | |
"stacktrace_length": len(issue.stacktrace), | ||
}, | ||
) | ||
self.insert_new_grouping_record(session, issue, embedding) | ||
session.commit() | ||
self.insert_new_grouping_record(issue, embedding) | ||
|
||
similarity_response = SimilarityResponse(responses=[]) | ||
for record, distance in results: | ||
|
@@ -472,43 +472,58 @@ def insert_batch_grouping_records( | |
return groups_with_neighbor | ||
|
||
@sentry_sdk.tracing.trace | ||
def insert_new_grouping_record( | ||
self, session, issue: GroupingRequest, embedding: np.ndarray | ||
) -> None: | ||
def insert_new_grouping_record(self, issue: GroupingRequest, embedding: np.ndarray) -> None: | ||
""" | ||
Inserts a new GroupingRecord into the database if the group_hash does not already exist. | ||
If new grouping record was created, return the id. | ||
|
||
:param session: The database session. | ||
:param issue: The issue to insert as a new GroupingRecord. | ||
:param embedding: The embedding of the stacktrace. | ||
""" | ||
existing_record = ( | ||
session.query(DbGroupingRecord) | ||
.filter_by(hash=issue.hash, project_id=issue.project_id) | ||
.first() | ||
) | ||
|
||
if existing_record is None: | ||
new_record = GroupingRecord( | ||
project_id=issue.project_id, | ||
message=issue.message, | ||
stacktrace_embedding=embedding, | ||
hash=issue.hash, | ||
error_type=issue.exception_type, | ||
).to_db_model() | ||
session.add(new_record) | ||
else: | ||
logger.info( | ||
"group_already_exists_in_seer_db", | ||
extra={ | ||
"existing_hash": existing_record.hash, | ||
"project_id": issue.project_id, | ||
"stacktrace_length": len(issue.stacktrace), | ||
"input_hash": issue.hash, | ||
}, | ||
with Session() as session: | ||
existing_record = ( | ||
session.query(DbGroupingRecord) | ||
.filter_by(hash=issue.hash, project_id=issue.project_id) | ||
.first() | ||
) | ||
|
||
extra = { | ||
"project_id": issue.project_id, | ||
"stacktrace_length": len(issue.stacktrace), | ||
"input_hash": issue.hash, | ||
} | ||
|
||
if existing_record is None: | ||
new_record = GroupingRecord( | ||
project_id=issue.project_id, | ||
message=issue.message, | ||
stacktrace_embedding=embedding, | ||
hash=issue.hash, | ||
error_type=issue.exception_type, | ||
).to_db_model() | ||
session.add(new_record) | ||
|
||
try: | ||
session.commit() | ||
except IntegrityError: | ||
session.rollback() | ||
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. what does rollback do? do we need it here? |
||
existing_record = ( | ||
session.query(DbGroupingRecord) | ||
.filter_by(hash=issue.hash, project_id=issue.project_id) | ||
.first() | ||
) | ||
extra["existing_hash"] = existing_record.hash | ||
logger.info( | ||
"group_already_exists_in_seer_db", | ||
extra=extra, | ||
) | ||
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. i'm wondering if this is necessary or if we can skip not having this log -- in theory we should be able to see the group hashes linked on the sentry side, right? |
||
else: | ||
extra["existing_hash"] = existing_record.hash | ||
logger.info( | ||
"group_already_exists_in_seer_db", | ||
extra=extra, | ||
) | ||
|
||
@sentry_sdk.tracing.trace | ||
def delete_grouping_records_for_project(self, project_id: int) -> bool: | ||
""" | ||
|
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.
can we modify this to return early if existing record is not none so we don't get so much arrowing? https://blog.codinghorror.com/flattening-arrow-code/