Просмотр исходного кода

ref(search): time postgres-only vs non-postgres-only searches (#53211)

Add some metrics to track query times for search when we hit snuba vs
when we avoid snuba.
Gilbert Szeto 1 год назад
Родитель
Сommit
37df2c13b2
2 измененных файлов с 11 добавлено и 6 удалено
  1. 10 5
      src/sentry/search/snuba/executors.py
  2. 1 1
      src/sentry/utils/cursors.py

+ 10 - 5
src/sentry/search/snuba/executors.py

@@ -822,12 +822,12 @@ class PostgresSnubaQueryExecutor(AbstractQueryExecutor):
             paginator = DateTimePaginator(group_queryset, "-last_seen", **paginator_options)
             metrics.incr("snuba.search.postgres_only")
             # When it's a simple django-only search, we count_hits like normal
-
-            # TODO: Add types to paginators and remove this
-            return cast(
-                CursorResult[Group],
-                paginator.get_result(limit, cursor, count_hits=count_hits, max_hits=max_hits),
+            metrics.timing(
+                "snuba.search.query",
+                (timezone.now() - now).total_seconds(),
+                tags={"postgres_only": True},
             )
+            return paginator.get_result(limit, cursor, count_hits=count_hits, max_hits=max_hits)
 
         # Here we check if all the django filters reduce the set of groups down
         # to something that we can send down to Snuba in a `group_id IN (...)`
@@ -1000,6 +1000,11 @@ class PostgresSnubaQueryExecutor(AbstractQueryExecutor):
         groups = Group.objects.in_bulk(paginator_results.results)
         paginator_results.results = [groups[k] for k in paginator_results.results if k in groups]
 
+        metrics.timing(
+            "snuba.search.query",
+            (timezone.now() - now).total_seconds(),
+            tags={"postgres_only": False},
+        )
         return paginator_results
 
     def calculate_hits(

+ 1 - 1
src/sentry/utils/cursors.py

@@ -252,7 +252,7 @@ def build_cursor(
     cursor: Cursor | None = None,
     hits: int | None = None,
     max_hits: int | None = None,
-    on_results: None | OnResultCallable[T] = None,
+    on_results: OnResultCallable[T] | None = None,
 ) -> CursorResult[T | JSONData]:
     if cursor is None:
         cursor = Cursor(0, 0, 0)