spanOperationTable.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import * as qs from 'query-string';
  2. import {getInterval} from 'sentry/components/charts/utils';
  3. import Duration from 'sentry/components/duration';
  4. import Link from 'sentry/components/links/link';
  5. import {t} from 'sentry/locale';
  6. import type {NewQuery} from 'sentry/types/organization';
  7. import EventView from 'sentry/utils/discover/eventView';
  8. import {NumberContainer} from 'sentry/utils/discover/styles';
  9. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  10. import {decodeScalar} from 'sentry/utils/queryString';
  11. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import usePageFilters from 'sentry/utils/usePageFilters';
  14. import {APP_START_SPANS} from 'sentry/views/performance/mobile/appStarts/screenSummary/spanOpSelector';
  15. import type {SpanOperationTableProps} from 'sentry/views/performance/mobile/components/samplesTables';
  16. import {ScreensTable} from 'sentry/views/performance/mobile/components/screensTable';
  17. import {MobileCursors} from 'sentry/views/performance/mobile/screenload/screens/constants';
  18. import {useTableQuery} from 'sentry/views/performance/mobile/screenload/screens/screensTable';
  19. import {Referrer} from 'sentry/views/performance/mobile/ui/referrers';
  20. import {useModuleURL} from 'sentry/views/performance/utils/useModuleURL';
  21. import {
  22. PRIMARY_RELEASE_ALIAS,
  23. SECONDARY_RELEASE_ALIAS,
  24. } from 'sentry/views/starfish/components/releaseSelector';
  25. import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign';
  26. import {SpanMetricsField} from 'sentry/views/starfish/types';
  27. import {STARFISH_CHART_INTERVAL_FIDELITY} from 'sentry/views/starfish/utils/constants';
  28. import {appendReleaseFilters} from 'sentry/views/starfish/utils/releaseComparison';
  29. const {SPAN_DESCRIPTION, SPAN_GROUP, SPAN_OP, PROJECT_ID} = SpanMetricsField;
  30. const VALID_SPAN_OPS = APP_START_SPANS;
  31. export function SpanOperationTable({
  32. transaction,
  33. primaryRelease,
  34. secondaryRelease,
  35. }: SpanOperationTableProps) {
  36. const moduleURL = useModuleURL('mobile-ui');
  37. const location = useLocation();
  38. const {selection} = usePageFilters();
  39. const cursor = decodeScalar(location.query?.[MobileCursors.SPANS_TABLE]);
  40. const spanOp = decodeScalar(location.query[SpanMetricsField.SPAN_OP]) ?? '';
  41. const deviceClass = decodeScalar(location.query[SpanMetricsField.DEVICE_CLASS]) ?? '';
  42. // TODO: These filters seem to be too aggressive, check that they are ingesting properly
  43. const searchQuery = new MutableSearch([
  44. // 'has:span.description',
  45. // 'transaction.op:ui.load',
  46. `transaction:${transaction}`,
  47. `${SpanMetricsField.SPAN_OP}:${spanOp ? spanOp : `[${VALID_SPAN_OPS.join(',')}]`}`,
  48. ...(spanOp ? [`${SpanMetricsField.SPAN_OP}:${spanOp}`] : []),
  49. ...(deviceClass ? [`${SpanMetricsField.DEVICE_CLASS}:${deviceClass}`] : []),
  50. ]);
  51. const queryStringPrimary = appendReleaseFilters(
  52. searchQuery,
  53. primaryRelease,
  54. secondaryRelease
  55. );
  56. const orderby = decodeScalar(location.query.sort, '');
  57. const newQuery: NewQuery = {
  58. name: '',
  59. fields: [
  60. PROJECT_ID,
  61. SPAN_OP,
  62. SPAN_GROUP,
  63. SPAN_DESCRIPTION,
  64. `avg_if(mobile.slow_frames,release,${primaryRelease})`,
  65. `avg_if(mobile.slow_frames,release,${secondaryRelease})`,
  66. `avg_compare(mobile.slow_frames,release,${primaryRelease},${secondaryRelease})`,
  67. `avg_if(mobile.frozen_frames,release,${primaryRelease})`,
  68. `avg_if(mobile.frozen_frames,release,${secondaryRelease})`,
  69. `avg_compare(mobile.frozen_frames,release,${primaryRelease},${secondaryRelease})`,
  70. `avg_if(mobile.frames_delay,release,${primaryRelease})`,
  71. `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
  72. `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  73. ],
  74. query: queryStringPrimary,
  75. orderby,
  76. dataset: DiscoverDatasets.SPANS_METRICS,
  77. version: 2,
  78. projects: selection.projects,
  79. interval: getInterval(selection.datetime, STARFISH_CHART_INTERVAL_FIDELITY),
  80. };
  81. const eventView = EventView.fromNewQueryWithLocation(newQuery, location);
  82. const {data, isLoading, pageLinks} = useTableQuery({
  83. eventView,
  84. enabled: true,
  85. referrer: Referrer.SPAN_OPERATION_TABLE,
  86. cursor,
  87. });
  88. const columnNameMap = {
  89. [SPAN_OP]: t('Operation'),
  90. [SPAN_DESCRIPTION]: t('Span Description'),
  91. [`avg_if(mobile.slow_frames,release,${primaryRelease})`]: t(
  92. 'Slow (%s)',
  93. PRIMARY_RELEASE_ALIAS
  94. ),
  95. [`avg_if(mobile.slow_frames,release,${secondaryRelease})`]: t(
  96. 'Slow (%s)',
  97. SECONDARY_RELEASE_ALIAS
  98. ),
  99. [`avg_compare(mobile.slow_frames,release,${primaryRelease},${secondaryRelease})`]:
  100. t('Change'),
  101. [`avg_if(mobile.frozen_frames,release,${primaryRelease})`]: t(
  102. 'Frozen (%s)',
  103. PRIMARY_RELEASE_ALIAS
  104. ),
  105. [`avg_if(mobile.frozen_frames,release,${secondaryRelease})`]: t(
  106. 'Frozen (%s)',
  107. SECONDARY_RELEASE_ALIAS
  108. ),
  109. [`avg_compare(mobile.frozen_frames,release,${primaryRelease},${secondaryRelease})`]:
  110. t('Change'),
  111. [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
  112. 'Delay (%s)',
  113. PRIMARY_RELEASE_ALIAS
  114. ),
  115. [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
  116. 'Delay (%s)',
  117. SECONDARY_RELEASE_ALIAS
  118. ),
  119. [`avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`]:
  120. t('Change'),
  121. };
  122. function renderBodyCell(column, row) {
  123. if (column.key === SPAN_DESCRIPTION) {
  124. const label = row[SpanMetricsField.SPAN_DESCRIPTION];
  125. const pathname = `${moduleURL}/spans/`;
  126. const query = {
  127. ...location.query,
  128. transaction,
  129. spanOp: row[SpanMetricsField.SPAN_OP],
  130. spanGroup: row[SpanMetricsField.SPAN_GROUP],
  131. spanDescription: row[SpanMetricsField.SPAN_DESCRIPTION],
  132. };
  133. return (
  134. <Link to={`${pathname}?${qs.stringify(query)}`}>
  135. <OverflowEllipsisTextContainer>{label}</OverflowEllipsisTextContainer>
  136. </Link>
  137. );
  138. }
  139. if (column.key.startsWith('avg_if(mobile.frames_delay')) {
  140. return (
  141. <NumberContainer>
  142. {typeof row[column.key] === 'number' ? (
  143. <Duration seconds={row[column.key]} fixedDigits={2} abbreviation />
  144. ) : (
  145. '-'
  146. )}
  147. </NumberContainer>
  148. );
  149. }
  150. return null;
  151. }
  152. return (
  153. <ScreensTable
  154. columnNameMap={columnNameMap}
  155. data={data}
  156. eventView={eventView}
  157. isLoading={isLoading}
  158. pageLinks={pageLinks}
  159. columnOrder={[
  160. String(SPAN_OP),
  161. String(SPAN_DESCRIPTION),
  162. `avg_if(mobile.slow_frames,release,${primaryRelease})`,
  163. `avg_if(mobile.slow_frames,release,${secondaryRelease})`,
  164. `avg_compare(mobile.slow_frames,release,${primaryRelease},${secondaryRelease})`,
  165. `avg_if(mobile.frozen_frames,release,${primaryRelease})`,
  166. `avg_if(mobile.frozen_frames,release,${secondaryRelease})`,
  167. `avg_compare(mobile.frozen_frames,release,${primaryRelease},${secondaryRelease})`,
  168. `avg_if(mobile.frames_delay,release,${primaryRelease})`,
  169. `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
  170. `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  171. ]}
  172. defaultSort={[
  173. {
  174. key: `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
  175. order: 'desc',
  176. },
  177. ]}
  178. customBodyCellRenderer={renderBodyCell}
  179. />
  180. );
  181. }