Browse Source

ref: Refactor transaction post processing (#25826)

This is the first step towards removing transactions from
post processing entirely. It simply groups the post
processing transaction code so it can be more easily refactored
later.

The only functional change included here is that the metric
events.processed is no longer inclusive of transactions.
Lyn Nagara 3 years ago
parent
commit
2a085a407b
1 changed files with 39 additions and 23 deletions
  1. 39 23
      src/sentry/tasks/post_process.py

+ 39 - 23
src/sentry/tasks/post_process.py

@@ -54,7 +54,7 @@ def _should_send_error_created_hooks(project):
 
 def _capture_stats(event, is_new):
     # TODO(dcramer): limit platforms to... something?
-    platform = event.group.platform if event.group else event.platform
+    platform = event.group.platform
     if not platform:
         return
     platform = platform.split("-", 1)[0].split("_", 1)[0]
@@ -204,17 +204,9 @@ def post_process_group(
 
         set_current_event_project(event.project_id)
 
-        is_reprocessed = is_reprocessed_event(event.data)
+        is_transaction_event = not bool(event.group_id)
 
-        # NOTE: we must pass through the full Event object, and not an
-        # event_id since the Event object may not actually have been stored
-        # in the database due to sampling.
-        from sentry.models import Commit, EventDict, GroupInboxReason, Organization, Project
-        from sentry.models.group import get_group_with_redirect
-        from sentry.models.groupinbox import add_group_to_inbox
-        from sentry.rules.processor import RuleProcessor
-        from sentry.tasks.groupowner import process_suspect_commits
-        from sentry.tasks.servicehooks import process_service_hook
+        from sentry.models import EventDict, Organization, Project
 
         # Re-bind node data to avoid renormalization. We only want to
         # renormalize when loading old data from the database.
@@ -227,23 +219,48 @@ def post_process_group(
             id=event.project.organization_id
         )
 
-        if event.group_id:
-            # Re-bind Group since we're reading the Event object
-            # from cache, which may contain a stale group and project
-            event.group, _ = get_group_with_redirect(event.group_id)
-            event.group_id = event.group.id
+        # Simplified post processing for transaction events.
+        # This should eventually be completely removed and transactions
+        # will not go through any post processing.
+        if is_transaction_event:
+            event_processed.send_robust(
+                sender=post_process_group,
+                project=event.project,
+                event=event,
+            )
 
-            event.group.project = event.project
-            event.group.project._organization_cache = event.project._organization_cache
+            event_processing_store.delete_by_key(cache_key)
+
+            return
+
+        is_reprocessed = is_reprocessed_event(event.data)
+
+        # NOTE: we must pass through the full Event object, and not an
+        # event_id since the Event object may not actually have been stored
+        # in the database due to sampling.
+        from sentry.models import Commit, GroupInboxReason
+        from sentry.models.group import get_group_with_redirect
+        from sentry.models.groupinbox import add_group_to_inbox
+        from sentry.rules.processor import RuleProcessor
+        from sentry.tasks.groupowner import process_suspect_commits
+        from sentry.tasks.servicehooks import process_service_hook
+
+        # Re-bind Group since we're reading the Event object
+        # from cache, which may contain a stale group and project
+        event.group, _ = get_group_with_redirect(event.group_id)
+        event.group_id = event.group.id
+
+        event.group.project = event.project
+        event.group.project._organization_cache = event.project._organization_cache
 
         bind_organization_context(event.project.organization)
 
         _capture_stats(event, is_new)
 
-        if event.group_id and is_reprocessed and is_new:
+        if is_reprocessed and is_new:
             add_group_to_inbox(event.group, GroupInboxReason.REPROCESSED)
 
-        if event.group_id and not is_reprocessed:
+        if not is_reprocessed:
             # we process snoozes before rules as it might create a regression
             # but not if it's new because you can't immediately snooze a new group
             has_reappeared = False if is_new else process_snoozes(event.group)
@@ -337,9 +354,8 @@ def post_process_group(
 
             safe_execute(similarity.record, event.project, [event], _with_transaction=False)
 
-        if event.group_id:
-            # Patch attachments that were ingested on the standalone path.
-            update_existing_attachments(event)
+        # Patch attachments that were ingested on the standalone path.
+        update_existing_attachments(event)
 
         if not is_reprocessed:
             event_processed.send_robust(