cacheLandingPage.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import React from 'react';
  2. import keyBy from 'lodash/keyBy';
  3. import FeatureBadge from 'sentry/components/badge/featureBadge';
  4. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  9. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  10. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  11. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  12. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  13. import type {EventsMetaType} from 'sentry/utils/discover/eventView';
  14. import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  15. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  16. import {useLocation} from 'sentry/utils/useLocation';
  17. import {CacheHitMissChart} from 'sentry/views/performance/cache/charts/hitMissChart';
  18. import {ThroughputChart} from 'sentry/views/performance/cache/charts/throughputChart';
  19. import {Referrer} from 'sentry/views/performance/cache/referrers';
  20. import {CacheSamplePanel} from 'sentry/views/performance/cache/samplePanel/samplePanel';
  21. import {
  22. BASE_FILTERS,
  23. MODULE_DESCRIPTION,
  24. MODULE_DOC_LINK,
  25. MODULE_TITLE,
  26. ONBOARDING_CONTENT,
  27. RELEASE_LEVEL,
  28. } from 'sentry/views/performance/cache/settings';
  29. import {
  30. isAValidSort,
  31. TransactionsTable,
  32. } from 'sentry/views/performance/cache/tables/transactionsTable';
  33. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  34. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  35. import {ModulesOnboarding} from 'sentry/views/performance/onboarding/modulesOnboarding';
  36. import {OnboardingContent} from 'sentry/views/performance/onboarding/onboardingContent';
  37. import {useModuleBreadcrumbs} from 'sentry/views/performance/utils/useModuleBreadcrumbs';
  38. import {useMetrics, useSpanMetrics} from 'sentry/views/starfish/queries/useDiscover';
  39. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useDiscoverSeries';
  40. import {SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  41. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  42. import {DataTitles} from 'sentry/views/starfish/views/spans/types';
  43. const {CACHE_MISS_RATE} = SpanFunction;
  44. const {CACHE_ITEM_SIZE} = SpanMetricsField;
  45. export function CacheLandingPage() {
  46. const location = useLocation();
  47. const sortField = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_SORT]);
  48. const sort = decodeSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  49. const cursor = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_CURSOR]);
  50. const {
  51. isLoading: isCacheHitRateLoading,
  52. data: cacheHitRateData,
  53. error: cacheHitRateError,
  54. } = useSpanMetricsSeries(
  55. {
  56. yAxis: [`${CACHE_MISS_RATE}()`],
  57. search: MutableSearch.fromQueryObject(BASE_FILTERS),
  58. },
  59. Referrer.LANDING_CACHE_HIT_MISS_CHART
  60. );
  61. const {
  62. isLoading: isThroughputDataLoading,
  63. data: throughputData,
  64. error: throughputError,
  65. } = useSpanMetricsSeries(
  66. {
  67. search: MutableSearch.fromQueryObject(BASE_FILTERS),
  68. yAxis: ['spm()'],
  69. },
  70. Referrer.LANDING_CACHE_THROUGHPUT_CHART
  71. );
  72. const {
  73. isFetching: isTransactionsListFetching,
  74. data: transactionsList,
  75. meta: transactionsListMeta,
  76. error: transactionsListError,
  77. pageLinks: transactionsListPageLinks,
  78. } = useSpanMetrics(
  79. {
  80. search: MutableSearch.fromQueryObject(BASE_FILTERS),
  81. fields: [
  82. 'project',
  83. 'project.id',
  84. 'transaction',
  85. 'spm()',
  86. `${CACHE_MISS_RATE}()`,
  87. 'sum(span.self_time)',
  88. 'time_spent_percentage()',
  89. `avg(${CACHE_ITEM_SIZE})`,
  90. ],
  91. sorts: [sort],
  92. cursor,
  93. limit: TRANSACTIONS_TABLE_ROW_COUNT,
  94. },
  95. Referrer.LANDING_CACHE_TRANSACTION_LIST
  96. );
  97. const {
  98. data: transactionDurationData,
  99. error: transactionDurationError,
  100. meta: transactionDurationMeta,
  101. isFetching: isTransactionDurationFetching,
  102. } = useMetrics(
  103. {
  104. search: `transaction:[${transactionsList.map(({transaction}) => `"${transaction}"`).join(',')}]`,
  105. fields: [`avg(transaction.duration)`, 'transaction'],
  106. enabled: !isTransactionsListFetching && transactionsList.length > 0,
  107. },
  108. Referrer.LANDING_CACHE_TRANSACTION_DURATION
  109. );
  110. const transactionDurationsMap = keyBy(transactionDurationData, 'transaction');
  111. const transactionsListWithDuration =
  112. transactionsList?.map(transaction => ({
  113. ...transaction,
  114. 'avg(transaction.duration)':
  115. transactionDurationsMap[transaction.transaction]?.['avg(transaction.duration)'],
  116. })) || [];
  117. const meta = combineMeta(transactionsListMeta, transactionDurationMeta);
  118. addCustomMeta(meta);
  119. const crumbs = useModuleBreadcrumbs('cache');
  120. return (
  121. <React.Fragment>
  122. <Layout.Header>
  123. <Layout.HeaderContent>
  124. <Breadcrumbs crumbs={crumbs} />
  125. <Layout.Title>
  126. {MODULE_TITLE}
  127. <PageHeadingQuestionTooltip
  128. docsUrl={MODULE_DOC_LINK}
  129. title={MODULE_DESCRIPTION}
  130. />
  131. <FeatureBadge type={RELEASE_LEVEL} />
  132. </Layout.Title>
  133. </Layout.HeaderContent>
  134. <Layout.HeaderActions>
  135. <ButtonBar gap={1}>
  136. <FeedbackWidgetButton />
  137. </ButtonBar>
  138. </Layout.HeaderActions>
  139. </Layout.Header>
  140. <Layout.Body>
  141. <Layout.Main fullWidth>
  142. <ModuleLayout.Layout>
  143. <ModuleLayout.Full>
  144. <PageFilterBar condensed>
  145. <ProjectPageFilter />
  146. <EnvironmentPageFilter />
  147. <DatePageFilter />
  148. </PageFilterBar>
  149. </ModuleLayout.Full>
  150. <ModulesOnboarding
  151. moduleQueryFilter={MutableSearch.fromQueryObject(BASE_FILTERS)}
  152. onboardingContent={<OnboardingContent {...ONBOARDING_CONTENT} />}
  153. referrer={Referrer.LANDING_CACHE_ONBOARDING}
  154. >
  155. <ModuleLayout.Half>
  156. <CacheHitMissChart
  157. series={{
  158. seriesName: DataTitles[`${CACHE_MISS_RATE}()`],
  159. data: cacheHitRateData[`${CACHE_MISS_RATE}()`]?.data,
  160. }}
  161. isLoading={isCacheHitRateLoading}
  162. error={cacheHitRateError}
  163. />
  164. </ModuleLayout.Half>
  165. <ModuleLayout.Half>
  166. <ThroughputChart
  167. series={throughputData['spm()']}
  168. isLoading={isThroughputDataLoading}
  169. error={throughputError}
  170. />
  171. </ModuleLayout.Half>
  172. <ModuleLayout.Full>
  173. <TransactionsTable
  174. data={transactionsListWithDuration}
  175. isLoading={isTransactionsListFetching || isTransactionDurationFetching}
  176. sort={sort}
  177. error={transactionsListError || transactionDurationError}
  178. meta={meta}
  179. pageLinks={transactionsListPageLinks}
  180. />
  181. </ModuleLayout.Full>
  182. </ModulesOnboarding>
  183. </ModuleLayout.Layout>
  184. </Layout.Main>
  185. </Layout.Body>
  186. <CacheSamplePanel />
  187. </React.Fragment>
  188. );
  189. }
  190. function PageWithProviders() {
  191. return (
  192. <ModulePageProviders moduleName="cache" features="performance-cache-view">
  193. <CacheLandingPage />
  194. </ModulePageProviders>
  195. );
  196. }
  197. export default PageWithProviders;
  198. const combineMeta = (
  199. meta1?: EventsMetaType,
  200. meta2?: EventsMetaType
  201. ): EventsMetaType | undefined => {
  202. if (!meta1 && !meta2) {
  203. return undefined;
  204. }
  205. if (!meta1) {
  206. return meta2;
  207. }
  208. if (!meta2) {
  209. return meta1;
  210. }
  211. return {
  212. fields: {...meta1.fields, ...meta2.fields},
  213. units: {...meta1.units, ...meta2.units},
  214. };
  215. };
  216. // TODO - this should come from the backend
  217. const addCustomMeta = (meta?: EventsMetaType) => {
  218. if (meta) {
  219. meta.fields[`avg(${CACHE_ITEM_SIZE})`] = 'size';
  220. meta.units[`avg(${CACHE_ITEM_SIZE})`] = 'byte';
  221. }
  222. };
  223. const DEFAULT_SORT = {
  224. field: 'time_spent_percentage()' as const,
  225. kind: 'desc' as const,
  226. };
  227. const TRANSACTIONS_TABLE_ROW_COUNT = 20;