Browse Source

feat(starfish): Use time_spent(local) on endpoint overview (#52383)

Use time_spent(local) for now so that the breakdown
percentages make a little more sense. Still not accurate
when the module filters are applied (it changes the
denominator to include the module filter), so we'll need 
to make changes to explicitly specify which filters
to apply to the denominator
Shruthi 1 year ago
parent
commit
1f52e7e4d5

+ 22 - 14
static/app/views/starfish/queries/useSpanList.tsx

@@ -32,6 +32,7 @@ export type SpanMetrics = {
   'sps_percent_change()': number;
   'sum(span.self_time)': number;
   'time_spent_percentage()': number;
+  'time_spent_percentage(local)': number;
 };
 
 export const useSpanList = (
@@ -84,24 +85,31 @@ function getEventView(
     .filter(Boolean)
     .join(' ');
 
+  const fields = [
+    'span.op',
+    'span.group',
+    'span.description',
+    'span.domain',
+    'sps()',
+    'sps_percent_change()',
+    `sum(${SPAN_SELF_TIME})`,
+    `p95(${SPAN_SELF_TIME})`,
+    `percentile_percent_change(${SPAN_SELF_TIME}, 0.95)`,
+    'http_error_count()',
+    'http_error_count_percent_change()',
+  ];
+
+  if (defined(transaction)) {
+    fields.push('time_spent_percentage(local)');
+  } else {
+    fields.push('time_spent_percentage()');
+  }
+
   const eventView = EventView.fromNewQueryWithLocation(
     {
       name: '',
       query,
-      fields: [
-        'span.op',
-        'span.group',
-        'span.description',
-        'span.domain',
-        'sps()',
-        'sps_percent_change()',
-        `sum(${SPAN_SELF_TIME})`,
-        `p95(${SPAN_SELF_TIME})`,
-        'time_spent_percentage()',
-        `percentile_percent_change(${SPAN_SELF_TIME}, 0.95)`,
-        'http_error_count()',
-        'http_error_count_percent_change()',
-      ],
+      fields,
       dataset: DiscoverDatasets.SPANS_METRICS,
       version: 2,
     },

+ 17 - 5
static/app/views/starfish/views/spans/spansTable.tsx

@@ -10,6 +10,7 @@ import GridEditable, {
 import Link from 'sentry/components/links/link';
 import Pagination, {CursorHandler} from 'sentry/components/pagination';
 import {Organization} from 'sentry/types';
+import {defined} from 'sentry/utils';
 import {EventsMetaType} from 'sentry/utils/discover/eventView';
 import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
 import type {Sort} from 'sentry/utils/discover/fields';
@@ -37,6 +38,7 @@ type Row = {
   'sps()': number;
   'sps_percent_change()': number;
   'time_spent_percentage()': number;
+  'time_spent_percentage(local)': number;
 };
 
 type Column = GridColumnHeader<keyof Row>;
@@ -63,6 +65,7 @@ export const SORTABLE_FIELDS = new Set([
   'sps()',
   'sps_percent_change()',
   'time_spent_percentage()',
+  'time_spent_percentage(local)',
   'http_error_count()',
   'http_error_count_percent_change()',
 ]);
@@ -112,7 +115,7 @@ export default function SpansTable({
         <GridEditable
           isLoading={isLoading}
           data={data as Row[]}
-          columnOrder={columnOrder ?? getColumns(moduleName)}
+          columnOrder={columnOrder ?? getColumns(moduleName, endpoint)}
           columnSortBy={[
             {
               key: sort.field,
@@ -198,7 +201,7 @@ function getDescriptionHeader(moduleName: ModuleName) {
   return 'Description';
 }
 
-function getColumns(moduleName: ModuleName): Column[] {
+export function getColumns(moduleName: ModuleName, transaction?: string): Column[] {
   const description = getDescriptionHeader(moduleName);
 
   const domain = getDomainHeader(moduleName);
@@ -257,12 +260,21 @@ function getColumns(moduleName: ModuleName): Column[] {
           } as Column,
         ]
       : []),
-    {
+  ];
+
+  if (defined(transaction)) {
+    order.push({
+      key: 'time_spent_percentage(local)',
+      name: DataTitles.timeSpent,
+      width: COL_WIDTH_UNDEFINED,
+    });
+  } else {
+    order.push({
       key: 'time_spent_percentage()',
       name: DataTitles.timeSpent,
       width: COL_WIDTH_UNDEFINED,
-    },
-  ];
+    });
+  }
 
   return order;
 }

+ 1 - 1
static/app/views/starfish/views/webServiceView/endpointOverview/index.tsx

@@ -381,7 +381,7 @@ function SpanMetricsTable({
     <SpansTable
       moduleName={filter ?? ModuleName.ALL}
       sort={{
-        field: 'time_spent_percentage()',
+        field: 'time_spent_percentage(local)',
         kind: 'desc',
       }}
       endpoint={transaction}