cacheLandingPage.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import React from 'react';
  2. import FeatureBadge from 'sentry/components/badge/featureBadge';
  3. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  8. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  9. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  10. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  11. import {t} from 'sentry/locale';
  12. import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  13. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  14. import {useLocation} from 'sentry/utils/useLocation';
  15. import useOrganization from 'sentry/utils/useOrganization';
  16. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  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. CACHE_BASE_URL,
  24. MODULE_TITLE,
  25. RELEASE_LEVEL,
  26. } from 'sentry/views/performance/cache/settings';
  27. import {
  28. isAValidSort,
  29. TransactionsTable,
  30. } from 'sentry/views/performance/cache/tables/transactionsTable';
  31. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  32. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  33. import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
  34. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  35. import {SpanFunction} from 'sentry/views/starfish/types';
  36. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  37. const {CACHE_MISS_RATE} = SpanFunction;
  38. export function CacheLandingPage() {
  39. const organization = useOrganization();
  40. const location = useLocation();
  41. const sortField = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_SORT]);
  42. const sort = decodeSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  43. const cursor = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_CURSOR]);
  44. const {
  45. isLoading: isCacheHitRateLoading,
  46. data: cacheHitRateData,
  47. error: cacheHitRateError,
  48. } = useSpanMetricsSeries({
  49. yAxis: [`${CACHE_MISS_RATE}()`],
  50. search: MutableSearch.fromQueryObject(BASE_FILTERS),
  51. referrer: Referrer.LANDING_CACHE_HIT_MISS_CHART,
  52. });
  53. const {
  54. isLoading: isThroughputDataLoading,
  55. data: throughputData,
  56. error: throughputError,
  57. } = useSpanMetricsSeries({
  58. search: MutableSearch.fromQueryObject(BASE_FILTERS),
  59. yAxis: ['spm()'],
  60. referrer: Referrer.LANDING_CACHE_THROUGHPUT_CHART,
  61. });
  62. const {
  63. isLoading: isTransactionsListLoading,
  64. data: transactionsList,
  65. meta: transactionsListMeta,
  66. error: transactionsListError,
  67. pageLinks: transactionsListPageLinks,
  68. } = useSpanMetrics({
  69. search: MutableSearch.fromQueryObject(BASE_FILTERS),
  70. fields: [
  71. 'project',
  72. 'project.id',
  73. 'transaction',
  74. 'spm()',
  75. `${CACHE_MISS_RATE}()`,
  76. 'sum(span.self_time)',
  77. 'time_spent_percentage()',
  78. ],
  79. sorts: [sort],
  80. cursor,
  81. limit: TRANSACTIONS_TABLE_ROW_COUNT,
  82. referrer: Referrer.LANDING_CACHE_TRANSACTION_LIST,
  83. });
  84. return (
  85. <React.Fragment>
  86. <Layout.Header>
  87. <Layout.HeaderContent>
  88. <Breadcrumbs
  89. crumbs={[
  90. {
  91. label: t('Performance'),
  92. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  93. preservePageFilters: true,
  94. },
  95. {
  96. label: MODULE_TITLE,
  97. },
  98. ]}
  99. />
  100. <Layout.Title>
  101. {MODULE_TITLE}
  102. <FeatureBadge type={RELEASE_LEVEL} />
  103. </Layout.Title>
  104. </Layout.HeaderContent>
  105. <Layout.HeaderActions>
  106. <ButtonBar gap={1}>
  107. <FeedbackWidgetButton />
  108. </ButtonBar>
  109. </Layout.HeaderActions>
  110. </Layout.Header>
  111. <Layout.Body>
  112. <Layout.Main fullWidth>
  113. <ModuleLayout.Layout>
  114. <ModuleLayout.Full>
  115. <PageFilterBar condensed>
  116. <ProjectPageFilter />
  117. <EnvironmentPageFilter />
  118. <DatePageFilter />
  119. </PageFilterBar>
  120. </ModuleLayout.Full>
  121. <ModuleLayout.Half>
  122. <CacheHitMissChart
  123. series={cacheHitRateData[`${CACHE_MISS_RATE}()`]}
  124. isLoading={isCacheHitRateLoading}
  125. error={cacheHitRateError}
  126. />
  127. </ModuleLayout.Half>
  128. <ModuleLayout.Half>
  129. <ThroughputChart
  130. series={throughputData['spm()']}
  131. isLoading={isThroughputDataLoading}
  132. error={throughputError}
  133. />
  134. </ModuleLayout.Half>
  135. <ModuleLayout.Full>
  136. <TransactionsTable
  137. data={transactionsList}
  138. isLoading={isTransactionsListLoading}
  139. sort={sort}
  140. error={transactionsListError}
  141. meta={transactionsListMeta}
  142. pageLinks={transactionsListPageLinks}
  143. />
  144. </ModuleLayout.Full>
  145. </ModuleLayout.Layout>
  146. </Layout.Main>
  147. </Layout.Body>
  148. <CacheSamplePanel />
  149. </React.Fragment>
  150. );
  151. }
  152. export function LandingPageWithProviders() {
  153. return (
  154. <ModulePageProviders
  155. title={[t('Performance'), MODULE_TITLE].join(' — ')}
  156. baseURL={CACHE_BASE_URL}
  157. features="performance-cache-view"
  158. >
  159. <CacheLandingPage />
  160. </ModulePageProviders>
  161. );
  162. }
  163. const DEFAULT_SORT = {
  164. field: 'time_spent_percentage()' as const,
  165. kind: 'desc' as const,
  166. };
  167. const TRANSACTIONS_TABLE_ROW_COUNT = 20;
  168. export default LandingPageWithProviders;