cacheLandingPage.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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.id',
  72. 'transaction',
  73. 'spm()',
  74. `${CACHE_MISS_RATE}()`,
  75. 'sum(span.self_time)',
  76. 'time_spent_percentage()',
  77. ],
  78. sorts: [sort],
  79. cursor,
  80. limit: TRANSACTIONS_TABLE_ROW_COUNT,
  81. referrer: Referrer.LANDING_CACHE_TRANSACTION_LIST,
  82. });
  83. return (
  84. <React.Fragment>
  85. <Layout.Header>
  86. <Layout.HeaderContent>
  87. <Breadcrumbs
  88. crumbs={[
  89. {
  90. label: t('Performance'),
  91. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  92. preservePageFilters: true,
  93. },
  94. {
  95. label: MODULE_TITLE,
  96. },
  97. ]}
  98. />
  99. <Layout.Title>
  100. {MODULE_TITLE}
  101. <FeatureBadge type={RELEASE_LEVEL} />
  102. </Layout.Title>
  103. </Layout.HeaderContent>
  104. <Layout.HeaderActions>
  105. <ButtonBar gap={1}>
  106. <FeedbackWidgetButton />
  107. </ButtonBar>
  108. </Layout.HeaderActions>
  109. </Layout.Header>
  110. <Layout.Body>
  111. <Layout.Main fullWidth>
  112. <ModuleLayout.Layout>
  113. <ModuleLayout.Full>
  114. <PageFilterBar condensed>
  115. <ProjectPageFilter />
  116. <EnvironmentPageFilter />
  117. <DatePageFilter />
  118. </PageFilterBar>
  119. </ModuleLayout.Full>
  120. <ModuleLayout.Half>
  121. <CacheHitMissChart
  122. series={cacheHitRateData[`${CACHE_MISS_RATE}()`]}
  123. isLoading={isCacheHitRateLoading}
  124. error={cacheHitRateError}
  125. />
  126. </ModuleLayout.Half>
  127. <ModuleLayout.Half>
  128. <ThroughputChart
  129. series={throughputData['spm()']}
  130. isLoading={isThroughputDataLoading}
  131. error={throughputError}
  132. />
  133. </ModuleLayout.Half>
  134. <ModuleLayout.Full>
  135. <TransactionsTable
  136. data={transactionsList}
  137. isLoading={isTransactionsListLoading}
  138. sort={sort}
  139. error={transactionsListError}
  140. meta={transactionsListMeta}
  141. pageLinks={transactionsListPageLinks}
  142. />
  143. </ModuleLayout.Full>
  144. </ModuleLayout.Layout>
  145. </Layout.Main>
  146. </Layout.Body>
  147. <CacheSamplePanel />
  148. </React.Fragment>
  149. );
  150. }
  151. export function LandingPageWithProviders() {
  152. return (
  153. <ModulePageProviders
  154. title={[t('Performance'), MODULE_TITLE].join(' — ')}
  155. baseURL={CACHE_BASE_URL}
  156. features="performance-cache-view"
  157. >
  158. <CacheLandingPage />
  159. </ModulePageProviders>
  160. );
  161. }
  162. const DEFAULT_SORT = {
  163. field: 'time_spent_percentage()' as const,
  164. kind: 'desc' as const,
  165. };
  166. const TRANSACTIONS_TABLE_ROW_COUNT = 20;
  167. export default LandingPageWithProviders;