httpLandingPage.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import React, {Fragment} 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 SearchBar from 'sentry/components/searchBar';
  12. import {t} from 'sentry/locale';
  13. import {browserHistory} from 'sentry/utils/browserHistory';
  14. import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  15. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  16. import useLocationQuery from 'sentry/utils/url/useLocationQuery';
  17. import {useLocation} from 'sentry/utils/useLocation';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  20. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  21. import {DurationChart} from 'sentry/views/performance/http/charts/durationChart';
  22. import {ResponseRateChart} from 'sentry/views/performance/http/charts/responseRateChart';
  23. import {ThroughputChart} from 'sentry/views/performance/http/charts/throughputChart';
  24. import {Referrer} from 'sentry/views/performance/http/referrers';
  25. import {MODULE_TITLE, RELEASE_LEVEL} from 'sentry/views/performance/http/settings';
  26. import {
  27. DomainsTable,
  28. isAValidSort,
  29. } from 'sentry/views/performance/http/tables/domainsTable';
  30. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  31. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  32. import Onboarding from 'sentry/views/performance/onboarding';
  33. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  34. import {useSpanMetrics} from 'sentry/views/starfish/queries/useDiscover';
  35. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useDiscoverSeries';
  36. import {ModuleName} from 'sentry/views/starfish/types';
  37. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  38. export function HTTPLandingPage() {
  39. const organization = useOrganization();
  40. const location = useLocation();
  41. const onboardingProject = useOnboardingProject();
  42. const sortField = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_SORT]);
  43. // TODO: Pull this using `useLocationQuery` below
  44. const sort = decodeSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  45. const query = useLocationQuery({
  46. fields: {
  47. 'span.domain': decodeScalar,
  48. },
  49. });
  50. const chartFilters = {
  51. 'span.module': ModuleName.HTTP,
  52. };
  53. const tableFilters = {
  54. 'span.module': ModuleName.HTTP,
  55. 'span.domain': query['span.domain'] ? `*${query['span.domain']}*` : undefined,
  56. };
  57. const cursor = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_CURSOR]);
  58. const handleSearch = (newDomain: string) => {
  59. browserHistory.push({
  60. ...location,
  61. query: {
  62. ...location.query,
  63. 'span.domain': newDomain === '' ? undefined : newDomain,
  64. [QueryParameterNames.SPANS_CURSOR]: undefined,
  65. },
  66. });
  67. };
  68. const {
  69. isLoading: isThroughputDataLoading,
  70. data: throughputData,
  71. error: throughputError,
  72. } = useSpanMetricsSeries(
  73. {
  74. search: MutableSearch.fromQueryObject(chartFilters),
  75. yAxis: ['spm()'],
  76. },
  77. Referrer.LANDING_THROUGHPUT_CHART
  78. );
  79. const {
  80. isLoading: isDurationDataLoading,
  81. data: durationData,
  82. error: durationError,
  83. } = useSpanMetricsSeries(
  84. {
  85. search: MutableSearch.fromQueryObject(chartFilters),
  86. yAxis: [`avg(span.self_time)`],
  87. },
  88. Referrer.LANDING_DURATION_CHART
  89. );
  90. const {
  91. isLoading: isResponseCodeDataLoading,
  92. data: responseCodeData,
  93. error: responseCodeError,
  94. } = useSpanMetricsSeries(
  95. {
  96. search: MutableSearch.fromQueryObject(chartFilters),
  97. yAxis: ['http_response_rate(3)', 'http_response_rate(4)', 'http_response_rate(5)'],
  98. },
  99. Referrer.LANDING_RESPONSE_CODE_CHART
  100. );
  101. const domainsListResponse = useSpanMetrics(
  102. {
  103. search: MutableSearch.fromQueryObject(tableFilters),
  104. fields: [
  105. 'project',
  106. 'project.id',
  107. 'span.domain',
  108. 'spm()',
  109. 'http_response_rate(3)',
  110. 'http_response_rate(4)',
  111. 'http_response_rate(5)',
  112. 'avg(span.self_time)',
  113. 'sum(span.self_time)',
  114. 'time_spent_percentage()',
  115. ],
  116. sorts: [sort],
  117. limit: DOMAIN_TABLE_ROW_COUNT,
  118. cursor,
  119. },
  120. Referrer.LANDING_DOMAINS_LIST
  121. );
  122. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  123. return (
  124. <React.Fragment>
  125. <Layout.Header>
  126. <Layout.HeaderContent>
  127. <Breadcrumbs
  128. crumbs={[
  129. {
  130. label: t('Performance'),
  131. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  132. preservePageFilters: true,
  133. },
  134. {
  135. label: MODULE_TITLE,
  136. },
  137. ]}
  138. />
  139. <Layout.Title>
  140. {MODULE_TITLE}
  141. <FeatureBadge type={RELEASE_LEVEL} />
  142. </Layout.Title>
  143. </Layout.HeaderContent>
  144. <Layout.HeaderActions>
  145. <ButtonBar gap={1}>
  146. <FeedbackWidgetButton />
  147. </ButtonBar>
  148. </Layout.HeaderActions>
  149. </Layout.Header>
  150. <Layout.Body>
  151. <Layout.Main fullWidth>
  152. <ModuleLayout.Layout>
  153. <ModuleLayout.Full>
  154. <PageFilterBar condensed>
  155. <ProjectPageFilter />
  156. <EnvironmentPageFilter />
  157. <DatePageFilter />
  158. </PageFilterBar>
  159. </ModuleLayout.Full>
  160. {onboardingProject && (
  161. <ModuleLayout.Full>
  162. <Onboarding organization={organization} project={onboardingProject} />
  163. </ModuleLayout.Full>
  164. )}
  165. {!onboardingProject && (
  166. <Fragment>
  167. <ModuleLayout.Third>
  168. <ThroughputChart
  169. series={throughputData['spm()']}
  170. isLoading={isThroughputDataLoading}
  171. error={throughputError}
  172. />
  173. </ModuleLayout.Third>
  174. <ModuleLayout.Third>
  175. <DurationChart
  176. series={[durationData[`avg(span.self_time)`]]}
  177. isLoading={isDurationDataLoading}
  178. error={durationError}
  179. />
  180. </ModuleLayout.Third>
  181. <ModuleLayout.Third>
  182. <ResponseRateChart
  183. series={[
  184. {
  185. ...responseCodeData[`http_response_rate(3)`],
  186. seriesName: t('3XX'),
  187. },
  188. {
  189. ...responseCodeData[`http_response_rate(4)`],
  190. seriesName: t('4XX'),
  191. },
  192. {
  193. ...responseCodeData[`http_response_rate(5)`],
  194. seriesName: t('5XX'),
  195. },
  196. ]}
  197. isLoading={isResponseCodeDataLoading}
  198. error={responseCodeError}
  199. />
  200. </ModuleLayout.Third>
  201. <ModuleLayout.Full>
  202. <SearchBar
  203. query={query['span.domain']}
  204. placeholder={t('Search for more domains')}
  205. onSearch={handleSearch}
  206. />
  207. </ModuleLayout.Full>
  208. <ModuleLayout.Full>
  209. <DomainsTable response={domainsListResponse} sort={sort} />
  210. </ModuleLayout.Full>
  211. </Fragment>
  212. )}
  213. </ModuleLayout.Layout>
  214. </Layout.Main>
  215. </Layout.Body>
  216. </React.Fragment>
  217. );
  218. }
  219. const DEFAULT_SORT = {
  220. field: 'time_spent_percentage()' as const,
  221. kind: 'desc' as const,
  222. };
  223. const DOMAIN_TABLE_ROW_COUNT = 10;
  224. function LandingPageWithProviders() {
  225. return (
  226. <ModulePageProviders
  227. title={[t('Performance'), MODULE_TITLE].join(' — ')}
  228. baseURL="/performance/http"
  229. features="spans-first-ui"
  230. >
  231. <HTTPLandingPage />
  232. </ModulePageProviders>
  233. );
  234. }
  235. export default LandingPageWithProviders;