Skip to content

Commit fecf3f1

Browse files
lobsterkatiesnigdhas
authored andcommitted
chore(issue assignment): Add logging forGroupOwner auto assignment (#45142)
There's currently a bug in our issue assignment logic such that suspect commits are sometimes passed over in favor of issue ownership rules or codeowners when auto-assigning an issue. For folks with Commit Context enabled, the calculating of suspect commits involves an API call to an outside service (GitHub or GitLab), meaning it's possible that this problem is caused by a race condition: when assignment happens, the data for suspect commit calculation may or may not have come back from the API yet. To test this hypothesis, it would be helpful to know when each stage of the process happened for an event with the wrong assignee. We already log the completion of suspect commit processing, but we don't log the completion of either ownership rule/code owners processing or the completion of auto-assignment. This PR adds that logging. Once it's merged, we'll need to look at logs for `process_commit_context.success` , `handle_owner_assignment.success`, and `handle_auto_assignment.success` .
1 parent 7c9f4b5 commit fecf3f1

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/sentry/api/endpoints/project_stacktrace_link.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any, Dict, List, Mapping, Optional
33

44
import requests
5+
from rest_framework import status
56
from rest_framework.request import Request
67
from rest_framework.response import Response
78
from sentry_sdk import Scope, configure_scope
@@ -399,13 +400,19 @@ def get(self, request: Request, project: Project) -> Response:
399400
}
400401
if error.response.status_code != 404:
401402
logger.exception(
402-
"Failed to get expected data from Codecov, pending investigation. Continuing execution."
403+
"Failed to get expected data from Codecov. Continuing execution."
403404
)
404405
except requests.Timeout:
405406
scope.set_tag("codecov.timeout", True)
407+
result["codecov"] = {
408+
"status": status.HTTP_408_REQUEST_TIMEOUT,
409+
}
406410
logger.exception("Codecov request timed out. Continuing execution.")
407411
except Exception:
408-
logger.exception("Something unexpected happen. Continuing execution.")
412+
result["codecov"] = {
413+
"status": status.HTTP_500_INTERNAL_SERVER_ERROR,
414+
}
415+
logger.exception("Something unexpected happened. Continuing execution.")
409416
# We don't expect coverage data if the integration does not exist (404)
410417

411418
try:

src/sentry/models/projectownership.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence, Tuple, Union
23

34
from django.db import models
@@ -18,6 +19,8 @@
1819
from sentry.models import ProjectCodeOwners, Team
1920
from sentry.services.hybrid_cloud.user import RpcUser
2021

22+
logger = logging.getLogger(__name__)
23+
2124
READ_CACHE_DURATION = 3600
2225

2326

@@ -303,6 +306,19 @@ def handle_auto_assignment(cls, project_id, event):
303306
project_id=project_id,
304307
group_id=event.group.id,
305308
)
309+
logger.info(
310+
"handle_auto_assignment.success",
311+
extra={
312+
"event": event.event_id,
313+
"group": event.group_id,
314+
"project": event.project_id,
315+
"organization": event.project.organization_id,
316+
# owner_id returns a string including the owner type (user or team) and id
317+
"assignee": issue_owner.owner_id(),
318+
"reason": "created" if assignment["new_assignment"] else "updated",
319+
**details,
320+
},
321+
)
306322

307323
@classmethod
308324
def _matching_ownership_rules(

src/sentry/tasks/post_process.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ def handle_owner_assignment(job):
248248
if issue_owners:
249249
try:
250250
handle_group_owners(project, group, issue_owners)
251+
logger.info(
252+
"handle_owner_assignment.success",
253+
extra={
254+
**basic_logging_details,
255+
"reason": "stored_issue_owners",
256+
},
257+
)
251258
except Exception:
252259
logger.exception("Failed to store group owners")
253260
except Exception:

0 commit comments

Comments
 (0)