Browse Source

chore(performance): Remove legacy key transactions (#29015)

Clean up all remaining references to the legacy key transactions.
Tony Xiao 3 years ago
parent
commit
537091ec06

+ 0 - 2
src/sentry/api/event_search.py

@@ -11,7 +11,6 @@ from parsimonious.grammar import Grammar, NodeVisitor
 from parsimonious.nodes import Node
 
 from sentry.search.events.constants import (
-    KEY_TRANSACTION_ALIAS,
     OPERATOR_NEGATION_MAP,
     SEARCH_MAP,
     SEMVER_ALIAS,
@@ -1033,7 +1032,6 @@ default_config = SearchConfig(
         "error.handled",
         "error.unhandled",
         "stack.in_app",
-        KEY_TRANSACTION_ALIAS,
         TEAM_KEY_TRANSACTION_ALIAS,
     },
 )

+ 1 - 2
src/sentry/deletions/defaults/organization.py

@@ -14,7 +14,7 @@ class OrganizationDeletionTask(ModelDeletionTask):
         }
 
     def get_child_relations(self, instance):
-        from sentry.discover.models import DiscoverSavedQuery, KeyTransaction, TeamKeyTransaction
+        from sentry.discover.models import DiscoverSavedQuery, TeamKeyTransaction
         from sentry.incidents.models import AlertRule, Incident
         from sentry.models import (
             CommitAuthor,
@@ -46,7 +46,6 @@ class OrganizationDeletionTask(ModelDeletionTask):
             Environment,
             Dashboard,
             DiscoverSavedQuery,
-            KeyTransaction,
             TeamKeyTransaction,
             ExternalIssue,
             PromptsActivity,

+ 1 - 2
src/sentry/deletions/defaults/project.py

@@ -4,7 +4,7 @@ from ..base import BulkModelDeletionTask, ModelDeletionTask, ModelRelation
 class ProjectDeletionTask(ModelDeletionTask):
     def get_child_relations(self, instance):
         from sentry import models
-        from sentry.discover.models import DiscoverSavedQueryProject, KeyTransaction
+        from sentry.discover.models import DiscoverSavedQueryProject
         from sentry.incidents.models import IncidentProject
         from sentry.snuba.models import QuerySubscription
 
@@ -44,7 +44,6 @@ class ProjectDeletionTask(ModelDeletionTask):
             models.UserReport,
             models.ProjectTransactionThreshold,
             DiscoverSavedQueryProject,
-            KeyTransaction,
             IncidentProject,
             QuerySubscription,
         )

+ 0 - 1
src/sentry/eventstore/base.py

@@ -98,7 +98,6 @@ class Filter:
         return {
             "start": self.start,
             "end": self.end,
-            # needed for the key transaction column
             "user_id": self.user_id,
             "organization_id": self.organization_id,
             # needed for the team key transaction column

+ 0 - 1
src/sentry/search/events/constants.py

@@ -7,7 +7,6 @@ TIMEOUT_ERROR_MESSAGE = """
 Query timeout. Please try again. If the problem persists try a smaller date range or fewer projects. Also consider a
 filter on the transaction field if you're filtering performance data.
 """
-KEY_TRANSACTION_ALIAS = "key_transaction"
 PROJECT_THRESHOLD_CONFIG_INDEX_ALIAS = "project_threshold_config_index"
 PROJECT_THRESHOLD_OVERRIDE_CONFIG_INDEX_ALIAS = "project_threshold_override_config_index"
 PROJECT_THRESHOLD_CONFIG_ALIAS = "project_threshold_config"

+ 3 - 58
src/sentry/search/events/fields.py

@@ -11,7 +11,7 @@ from snuba_sdk.column import Column
 from snuba_sdk.function import Function
 from snuba_sdk.orderby import Direction, OrderBy
 
-from sentry.discover.models import KeyTransaction, TeamKeyTransaction
+from sentry.discover.models import TeamKeyTransaction
 from sentry.exceptions import InvalidSearchQuery
 from sentry.models import Project, ProjectTeam, ProjectTransactionThreshold
 from sentry.models.transaction_threshold import (
@@ -30,7 +30,6 @@ from sentry.search.events.constants import (
     FUNCTION_PATTERN,
     ISSUE_ALIAS,
     ISSUE_ID_ALIAS,
-    KEY_TRANSACTION_ALIAS,
     MEASUREMENTS_FRAMES_FROZEN_RATE,
     MEASUREMENTS_FRAMES_SLOW_RATE,
     MEASUREMENTS_STALL_PERCENTAGE,
@@ -104,50 +103,6 @@ class PseudoField:
         ), f"{self.name}: only one of expression, expression_fn is allowed"
 
 
-def key_transaction_expression(user_id, organization_id, project_ids):
-    """
-    This function may be called multiple times, making for repeated data bases queries.
-    Lifting the query higher to earlier in the call stack will require a lot more changes
-    as there are numerous entry points. So we will leave the duplicate query alone for now.
-    """
-    if user_id is None or organization_id is None or project_ids is None:
-        raise InvalidSearchQuery("Missing necessary meta for key transaction field.")
-
-    key_transactions = (
-        KeyTransaction.objects.filter(
-            owner_id=user_id,
-            organization_id=organization_id,
-            project_id__in=project_ids,
-        )
-        .order_by("transaction", "project_id")
-        .values("project_id", "transaction")
-    )
-
-    # if there are no key transactions, the value should always be 0
-    if not len(key_transactions):
-        return ["toInt64", [0]]
-
-    return [
-        "has",
-        [
-            [
-                "array",
-                [
-                    [
-                        "tuple",
-                        [
-                            ["toUInt64", [transaction["project_id"]]],
-                            "'{}'".format(transaction["transaction"]),
-                        ],
-                    ]
-                    for transaction in key_transactions
-                ],
-            ],
-            ["tuple", ["project_id", "transaction"]],
-        ],
-    ]
-
-
 def project_threshold_config_expression(organization_id, project_ids):
     """
     This function returns a column with the threshold and threshold metric
@@ -412,18 +367,6 @@ FIELD_ALIASES = {
             USER_DISPLAY_ALIAS,
             expression=["coalesce", ["user.email", "user.username", "user.ip"]],
         ),
-        # the key transaction field is intentially not added to the discover/fields list yet
-        # because there needs to be some work on the front end to integrate this into discover
-        PseudoField(
-            KEY_TRANSACTION_ALIAS,
-            KEY_TRANSACTION_ALIAS,
-            expression_fn=lambda params: key_transaction_expression(
-                params.get("user_id"),
-                params.get("organization_id"),
-                params.get("project_id"),
-            ),
-            result_type="boolean",
-        ),
         PseudoField(
             PROJECT_THRESHOLD_CONFIG_ALIAS,
             PROJECT_THRESHOLD_CONFIG_ALIAS,
@@ -432,6 +375,8 @@ FIELD_ALIASES = {
                 params.get("project_id"),
             ),
         ),
+        # the team key transaction field is intentially not added to the discover/fields list yet
+        # because there needs to be some work on the front end to integrate this into discover
         PseudoField(
             TEAM_KEY_TRANSACTION_ALIAS,
             TEAM_KEY_TRANSACTION_ALIAS,

+ 1 - 23
src/sentry/search/events/filter.py

@@ -29,7 +29,6 @@ from sentry.search.events.constants import (
     ERROR_UNHANDLED_ALIAS,
     ISSUE_ALIAS,
     ISSUE_ID_ALIAS,
-    KEY_TRANSACTION_ALIAS,
     MAX_SEARCH_RELEASES,
     NO_CONVERSION_FIELDS,
     OPERATOR_NEGATION_MAP,
@@ -301,26 +300,6 @@ def _error_handled_filter_converter(
     raise InvalidSearchQuery("Invalid value for error.handled condition. Accepted values are 1, 0")
 
 
-def _key_transaction_filter_converter(
-    search_filter: SearchFilter,
-    name: str,
-    params: Optional[Mapping[str, Union[int, str, datetime]]],
-):
-    value = search_filter.value.value
-    key_transaction_expr = FIELD_ALIASES[KEY_TRANSACTION_ALIAS].get_expression(params)
-
-    if search_filter.value.raw_value == "":
-        operator = "!=" if search_filter.operator == "!=" else "="
-        return [key_transaction_expr, operator, 0]
-    if value in ("1", 1):
-        return [key_transaction_expr, "=", 1]
-    if value in ("0", 0):
-        return [key_transaction_expr, "=", 0]
-    raise InvalidSearchQuery(
-        "Invalid value for key_transaction condition. Accepted values are 1, 0"
-    )
-
-
 def _team_key_transaction_filter_converter(
     search_filter: SearchFilter,
     name: str,
@@ -337,7 +316,7 @@ def _team_key_transaction_filter_converter(
     if value in ("0", 0):
         return [key_transaction_expr, "=", 0]
     raise InvalidSearchQuery(
-        "Invalid value for key_transaction condition. Accepted values are 1, 0"
+        "Invalid value for team_key_transaction condition. Accepted values are 1, 0"
     )
 
 
@@ -596,7 +575,6 @@ key_conversion_map: Mapping[
     USER_DISPLAY_ALIAS: _user_display_filter_converter,
     ERROR_UNHANDLED_ALIAS: _error_unhandled_filter_converter,
     "error.handled": _error_handled_filter_converter,
-    KEY_TRANSACTION_ALIAS: _key_transaction_filter_converter,
     TEAM_KEY_TRANSACTION_ALIAS: _team_key_transaction_filter_converter,
     RELEASE_STAGE_ALIAS: _release_stage_filter_converter,
     SEMVER_ALIAS: _semver_filter_converter,

+ 0 - 1
static/app/components/searchSyntax/parser.tsx

@@ -800,7 +800,6 @@ const defaultConfig: SearchConfig = {
     'error.handled',
     'error.unhandled',
     'stack.in_app',
-    'key_transaction',
     'team_key_transaction',
   ]),
   allowBoolean: true,

+ 0 - 15
static/app/utils/discover/fieldRenderers.tsx

@@ -39,7 +39,6 @@ import {
 } from 'app/views/performance/transactionSummary/filter';
 
 import ArrayValue from './arrayValue';
-import KeyTransactionField from './keyTransactionField';
 import {
   BarContainer,
   Container,
@@ -207,7 +206,6 @@ type SpecialFields = {
   'error.handled': SpecialField;
   issue: SpecialField;
   release: SpecialField;
-  key_transaction: SpecialField;
   team_key_transaction: SpecialField;
   'trend_percentage()': SpecialField;
   'timestamp.to_hour': SpecialField;
@@ -384,19 +382,6 @@ const SPECIAL_FIELDS: SpecialFields = {
       return <Container>{[1, null].includes(value) ? 'true' : 'false'}</Container>;
     },
   },
-  key_transaction: {
-    sortField: null,
-    renderFunc: (data, {organization}) => (
-      <Container>
-        <KeyTransactionField
-          isKeyTransaction={(data.key_transaction ?? 0) !== 0}
-          organization={organization}
-          projectSlug={data.project}
-          transactionName={data.transaction}
-        />
-      </Container>
-    ),
-  },
   team_key_transaction: {
     sortField: null,
     renderFunc: (data, {organization}) => (

+ 0 - 1
static/app/utils/discover/fields.tsx

@@ -722,7 +722,6 @@ export const TRACING_FIELDS = [
   'user_misery',
   'eps',
   'epm',
-  'key_transaction',
   'team_key_transaction',
   ...Object.keys(MEASUREMENTS),
   ...SPAN_OP_BREAKDOWN_FIELDS,

Some files were not shown because too many files changed in this diff