Browse Source

feat(functions): Handle processed profiles in examples query (#63258)

Processed profiles will have a profile id of
"00000000000000000000000000000000". Make sure to filter them out before
returning the results.
Tony Xiao 1 year ago
parent
commit
fa4a9b8626
1 changed files with 39 additions and 11 deletions
  1. 39 11
      src/sentry/search/events/datasets/profile_functions.py

+ 39 - 11
src/sentry/search/events/datasets/profile_functions.py

@@ -1,5 +1,6 @@
 from __future__ import annotations
 
+import uuid
 from dataclasses import dataclass
 from enum import Enum
 from typing import Callable, Mapping, Optional, Union
@@ -291,20 +292,47 @@ class ProfileFunctionsDatasetConfig(DatasetConfig):
                 SnQLFunction(
                     "examples",
                     snql_aggregate=lambda _, alias: Function(
-                        "arrayMap",
+                        # The worst may collide with one of the examples, so make sure to filter it out.
+                        "arrayDistinct",
                         [
-                            # TODO: should this transform be moved to snuba?
-                            Lambda(
-                                ["x"],
-                                Function(
-                                    "replaceAll", [Function("toString", [Identifier("x")]), "-", ""]
-                                ),
-                            ),
                             Function(
-                                "arrayPushFront",
+                                "arrayFilter",
                                 [
-                                    Function("groupUniqArrayMerge(5)", [SnQLColumn("examples")]),
-                                    Function("argMaxMerge", [SnQLColumn("worst")]),
+                                    # Filter out the profile ids for processed profiles
+                                    Lambda(
+                                        ["x"],
+                                        Function(
+                                            "notEquals",
+                                            [Identifier("x"), uuid.UUID(int=0).hex],
+                                        ),
+                                    ),
+                                    Function(
+                                        "arrayMap",
+                                        [
+                                            # TODO: should this transform be moved to snuba?
+                                            Lambda(
+                                                ["x"],
+                                                Function(
+                                                    "replaceAll",
+                                                    [
+                                                        Function("toString", [Identifier("x")]),
+                                                        "-",
+                                                        "",
+                                                    ],
+                                                ),
+                                            ),
+                                            Function(
+                                                "arrayPushFront",
+                                                [
+                                                    Function(
+                                                        "groupUniqArrayMerge(5)",
+                                                        [SnQLColumn("examples")],
+                                                    ),
+                                                    Function("argMaxMerge", [SnQLColumn("worst")]),
+                                                ],
+                                            ),
+                                        ],
+                                    ),
                                 ],
                             ),
                         ],